Skip to content

Commit dc5ce77

Browse files
committed
Code coverage Fix
1 parent d685a52 commit dc5ce77

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

src/extension/tests/Test_TelemetryWriter.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def test_events_deleted_outside_of_extension_while_extension_is_running(self):
158158
self.telemetry_writer.write_event("testing telemetry write to file", Constants.TelemetryEventLevel.Error, "Test Task")
159159
os.listdir = backup_os_listdir
160160

161-
# ==================== Common Helper Method for Loading Event Files ====================
161+
# ==================== Integration test for credential sanitization in telemetry ====================
162162
def _load_sanitized_event(self, message):
163163
"""
164-
Common helper method to write event to telemetry and load the sanitized message.
164+
Helper method to write event to telemetry and load the sanitized message.
165165
The regex sanitization happens automatically in TelemetryWriter.
166166
167167
Args:
@@ -184,9 +184,8 @@ def _load_sanitized_event(self, message):
184184
f.close()
185185
return sanitized_message
186186

187-
# ==================== Test cases for credential sanitization in telemetry messages ====================
188-
def test_sanitize_credentials_multiple_repos(self):
189-
"""Test 2: Failed repo sync with multiple repo URLs containing different credentials"""
187+
def test_sanitize_credentials_in_telemetry_event(self):
188+
"""Integration test: Verify credentials are sanitized in telemetry events"""
190189
if self.runtime.is_github_runner:
191190
return
192191

@@ -196,26 +195,17 @@ def test_sanitize_credentials_multiple_repos(self):
196195
expected_message = "Failed repo sync: https://user1@repo1.example.com https://user2@repo2.example.com/path"
197196
self.assertEqual(sanitized_message, expected_message)
198197

199-
def test_sanitize_credentials_username_only_no_password(self):
200-
"""Test 3: Using mirror with username only (no password)"""
201-
if self.runtime.is_github_runner:
202-
return
198+
def test_load_sanitized_event_skips_on_github_runner(self):
199+
"""Test: Helper method returns None when running on GitHub runner"""
200+
# Mock is_github_runner to be True to test the skip path
201+
original_is_github_runner = self.runtime.is_github_runner
202+
self.runtime.is_github_runner = True
203203

204-
message = "Using mirror https://testuser@repo.example.com/path"
204+
result = self._load_sanitized_event("test message")
205+
self.assertIsNone(result)
205206

206-
sanitized_message = self._load_sanitized_event(message)
207-
self.assertIn("testuser@repo.example.com", sanitized_message)
208-
209-
def test_sanitize_credentials_special_characters_in_password(self):
210-
"""Test 4: Downloading from repo with special characters in password"""
211-
if self.runtime.is_github_runner:
212-
return
213-
214-
message = "Downloading from https://svc-user:AbC_123-.$%!@repo.contoso.com/rpm"
215-
216-
sanitized_message = self._load_sanitized_event(message)
217-
self.assertNotIn("AbC_123-.$%!", sanitized_message)
218-
self.assertIn("svc-user@repo.contoso.com", sanitized_message)
207+
# Restore
208+
self.runtime.is_github_runner = original_is_github_runner
219209

220210
if __name__ == '__main__':
221211
SUITE = unittest.TestLoader().loadTestsFromTestCase(TestTelemetryWriter)

0 commit comments

Comments
 (0)