File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 3333 Optional ,
3434 cast ,
3535)
36- from urllib .parse import quote
36+ from urllib .parse import quote , unquote
3737
3838from bson .binary import Binary
3939from pymongo .auth_aws import _authenticate_aws
@@ -173,6 +173,8 @@ def _build_credentials_tuple(
173173 human_callback = properties .get ("OIDC_HUMAN_CALLBACK" )
174174 environ = properties .get ("ENVIRONMENT" )
175175 token_resource = properties .get ("TOKEN_RESOURCE" , "" )
176+ if unquote (token_resource ) == token_resource :
177+ token_resource = quote (token_resource )
176178 default_allowed = [
177179 "*.mongodb.net" ,
178180 "*.mongodb-dev.net" ,
Original file line number Diff line number Diff line change 539539 }
540540 }
541541 },
542+ {
543+ "description" : " should accept a url-encoded TOKEN_RESOURCE (MONGODB-OIDC)" ,
544+ "uri" : " mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:mongodb%253A//test-cluster" ,
545+ "valid" : true ,
546+ "credential" : {
547+ "username" : " user" ,
548+ "password" : null ,
549+ "source" : " $external" ,
550+ "mechanism" : " MONGODB-OIDC" ,
551+ "mechanism_properties" : {
552+ "ENVIRONMENT" : " azure" ,
553+ "TOKEN_RESOURCE" : " mongodb%253A//test-cluster"
554+ }
555+ }
556+ },
557+ {
558+ "description" : " should url-encode a TOKEN_RESOURCE (MONGODB-OIDC)" ,
559+ "uri" : " mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:a$b" ,
560+ "valid" : true ,
561+ "credential" : {
562+ "username" : " user" ,
563+ "password" : null ,
564+ "source" : " $external" ,
565+ "mechanism" : " MONGODB-OIDC" ,
566+ "mechanism_properties" : {
567+ "ENVIRONMENT" : " azure" ,
568+ "TOKEN_RESOURCE" : " a%24b"
569+ }
570+ }
571+ },
542572 {
543573 "description" : " should accept a username and throw an error for a password with azure provider (MONGODB-OIDC)" ,
544574 "uri" : " mongodb://user:pass@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:foo" ,
You can’t perform that action at this time.
0 commit comments