@@ -160,10 +160,6 @@ def test_parse_uri(self):
160
160
self .
assertRaises (
InvalidURI ,
parse_uri ,
"http://[email protected] " )
161
161
self .assertRaises (ValueError , parse_uri , "mongodb://::1" , 27017 )
162
162
163
- # Extra whitespace should be visible in error message.
164
- with self .assertRaisesRegex (ValueError , "'27017 '" ):
165
- parse_uri ("mongodb://localhost:27017 " )
166
-
167
163
orig : dict = {
168
164
"nodelist" : [("localhost" , 27017 )],
169
165
"username" : None ,
@@ -536,6 +532,28 @@ def test_special_chars(self):
536
532
self .assertEqual (user , res ["username" ])
537
533
self .assertEqual (pwd , res ["password" ])
538
534
535
+ def test_do_not_include_password_in_port_message (self ):
536
+ with self .assertRaisesRegex (ValueError , "Port must be an integer between 0 and 65535" ):
537
+ parse_uri ("mongodb://localhost:65536" )
538
+ with self .assertRaisesRegex (
539
+ ValueError , "Port contains non-digit characters. Hint: username "
540
+ ) as ctx :
541
+ parse_uri ("mongodb://user:PASS /@localhost:27017" )
542
+ self .assertNotIn ("PASS" , str (ctx .exception ))
543
+
544
+ # This "invalid" case is technically a valid URI:
545
+ res = parse_uri ("mongodb://user:1234/@localhost:27017" )
546
+ self .assertEqual ([("user" , 1234 )], res ["nodelist" ])
547
+ self .assertEqual ("@localhost:27017" , res ["database" ])
548
+
549
+ def test_port_with_whitespace (self ):
550
+ with self .assertRaisesRegex (ValueError , "Port contains whitespace character: ' '" ):
551
+ parse_uri ("mongodb://localhost:27017 " )
552
+ with self .assertRaisesRegex (ValueError , "Port contains whitespace character: ' '" ):
553
+ parse_uri ("mongodb://localhost: 27017" )
554
+ with self .assertRaisesRegex (ValueError , r"Port contains whitespace character: '\\n'" ):
555
+ parse_uri ("mongodb://localhost:27\n 017" )
556
+
539
557
540
558
if __name__ == "__main__" :
541
559
unittest .main ()
0 commit comments