File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,18 @@ impl AuthMechanism {
122
122
} ;
123
123
Ok ( ( ) )
124
124
}
125
+ #[ cfg( feature = "tokio-runtime" ) ]
126
+ AuthMechanism :: MongoDbAws => {
127
+ if credential. username . is_some ( ) && credential. password . is_none ( ) {
128
+ return Err ( ErrorKind :: ArgumentError {
129
+ message : "Username cannot be provided without password for MONGODB-AWS \
130
+ authentication"
131
+ . to_string ( ) ,
132
+ }
133
+ . into ( ) ) ;
134
+ }
135
+ Ok ( ( ) )
136
+ }
125
137
_ => Ok ( ( ) ) ,
126
138
}
127
139
}
Original file line number Diff line number Diff line change @@ -834,6 +834,19 @@ fn validate_userinfo(s: &str, userinfo_type: &str) -> Result<()> {
834
834
}
835
835
. into ( ) ) ;
836
836
}
837
+
838
+ // All instances of '%' in the username must be part of an percent-encoded substring. This means
839
+ // that there must be two hexidecimal digits following any '%' in the username.
840
+ if s. split ( '%' )
841
+ . skip ( 1 )
842
+ . any ( |part| part. len ( ) < 2 || part[ 0 ..2 ] . chars ( ) . any ( |c| !c. is_ascii_hexdigit ( ) ) )
843
+ {
844
+ return Err ( ErrorKind :: ArgumentError {
845
+ message : "username/password cannot contain unescaped %" . to_string ( ) ,
846
+ }
847
+ . into ( ) ) ;
848
+ }
849
+
837
850
Ok ( ( ) )
838
851
}
839
852
@@ -1018,12 +1031,6 @@ impl ClientOptionsParser {
1018
1031
let mut credential = options. credential . get_or_insert_with ( Default :: default) ;
1019
1032
validate_userinfo ( u, "username" ) ?;
1020
1033
let decoded_u = percent_decode ( u, "username must be URL encoded" ) ?;
1021
- if decoded_u. chars ( ) . any ( |c| c == '%' ) {
1022
- return Err ( ErrorKind :: ArgumentError {
1023
- message : "username/passowrd cannot contain unescaped %" . to_string ( ) ,
1024
- }
1025
- . into ( ) ) ;
1026
- }
1027
1034
1028
1035
credential. username = Some ( decoded_u) ;
1029
1036
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ async fn run_auth_test(test_file: TestFile) {
55
55
"MONGODB-X509" ,
56
56
"PLAIN" ,
57
57
"MONGODB-CR" ,
58
+ #[ cfg( not( feature = "tokio-runtime" ) ) ]
58
59
"MONGODB-AWS" ,
59
60
] ;
60
61
@@ -84,7 +85,11 @@ async fn run_auth_test(test_file: TestFile) {
84
85
None => assert ! ( options. credential. is_none( ) , "{}" , test_case. description) ,
85
86
}
86
87
}
87
- Err ( _) => assert ! ( !test_case. valid, "{}" , test_case. description) ,
88
+ Err ( e) => assert ! (
89
+ !test_case. valid,
90
+ "got error {:?}: {}" ,
91
+ e, test_case. description
92
+ ) ,
88
93
} ;
89
94
}
90
95
}
You can’t perform that action at this time.
0 commit comments