@@ -343,18 +343,34 @@ def test_pickle_tzoffset(self):
343
343
self .assertEqual (t1 ._name , t2 ._name )
344
344
345
345
def test_remove_password_from_command_line (self ):
346
+ username = "fakeuser"
346
347
password = "fakepassword1234"
347
- url_with_pass = "https://fakeuser:{}@fakerepo.example.com/testrepo" .format (password )
348
- url_without_pass = "https://fakerepo.example.com/testrepo"
348
+ url_with_user_and_pass = "https://{}:{}@fakerepo.example.com/testrepo" .format (username , password )
349
+ url_with_user = "https://{}@fakerepo.example.com/testrepo" .format (username )
350
+ url_with_pass = "https://:{}@fakerepo.example.com/testrepo" .format (password )
351
+ url_without_user_or_pass = "https://fakerepo.example.com/testrepo"
349
352
350
- cmd_1 = ["git" , "clone" , "-v" , url_with_pass ]
351
- cmd_2 = ["git" , "clone" , "-v" , url_without_pass ]
352
- cmd_3 = ["no" , "url" , "in" , "this" , "one" ]
353
+ cmd_1 = ["git" , "clone" , "-v" , url_with_user_and_pass ]
354
+ cmd_2 = ["git" , "clone" , "-v" , url_with_user ]
355
+ cmd_3 = ["git" , "clone" , "-v" , url_with_pass ]
356
+ cmd_4 = ["git" , "clone" , "-v" , url_without_user_or_pass ]
357
+ cmd_5 = ["no" , "url" , "in" , "this" , "one" ]
353
358
354
359
redacted_cmd_1 = remove_password_if_present (cmd_1 )
360
+ assert username not in " " .join (redacted_cmd_1 )
355
361
assert password not in " " .join (redacted_cmd_1 )
356
362
# Check that we use a copy
357
363
assert cmd_1 is not redacted_cmd_1
364
+ assert username in " " .join (cmd_1 )
358
365
assert password in " " .join (cmd_1 )
359
- assert cmd_2 == remove_password_if_present (cmd_2 )
360
- assert cmd_3 == remove_password_if_present (cmd_3 )
366
+
367
+ redacted_cmd_2 = remove_password_if_present (cmd_2 )
368
+ assert username not in " " .join (redacted_cmd_2 )
369
+ assert password not in " " .join (redacted_cmd_2 )
370
+
371
+ redacted_cmd_3 = remove_password_if_present (cmd_3 )
372
+ assert username not in " " .join (redacted_cmd_3 )
373
+ assert password not in " " .join (redacted_cmd_3 )
374
+
375
+ assert cmd_4 == remove_password_if_present (cmd_4 )
376
+ assert cmd_5 == remove_password_if_present (cmd_5 )
0 commit comments