@@ -503,8 +503,12 @@ def check_auth(username, password):
503503 self .assertRaises (ConfigurationError , auth_db .add_user ,
504504 "user" , "password" , digestPassword = True )
505505
506+ extra = {}
507+ if client_context .version .at_least (3 , 7 , 2 ):
508+ extra ['mechanisms' ] = ['SCRAM-SHA-1' ]
509+
506510 # Add / authenticate / remove
507- auth_db .add_user ("mike" , "password" , roles = ["read" ])
511+ auth_db .add_user ("mike" , "password" , roles = ["read" ], ** extra )
508512 self .addCleanup (remove_all_users , auth_db )
509513 self .assertRaises (TypeError , check_auth , 5 , "password" )
510514 self .assertRaises (TypeError , check_auth , "mike" , 5 )
@@ -522,21 +526,26 @@ def check_auth(username, password):
522526
523527 # Add / authenticate / change password
524528 self .assertRaises (OperationFailure , check_auth , "Gustave" , u"Dor\xe9 " )
525- auth_db .add_user ("Gustave" , u"Dor\xe9 " , roles = ["read" ])
529+ auth_db .add_user ("Gustave" , u"Dor\xe9 " , roles = ["read" ], ** extra )
526530 check_auth ("Gustave" , u"Dor\xe9 " )
527531
528532 # Change password.
529- auth_db .add_user ("Gustave" , "password" , roles = ["read" ])
533+ auth_db .add_user ("Gustave" , "password" , roles = ["read" ], ** extra )
530534 self .assertRaises (OperationFailure , check_auth , "Gustave" , u"Dor\xe9 " )
531535 check_auth ("Gustave" , u"password" )
532536
533537 @client_context .require_auth
538+ @ignore_deprecations
534539 def test_make_user_readonly (self ):
540+ extra = {}
541+ if client_context .version .at_least (3 , 7 , 2 ):
542+ extra ['mechanisms' ] = ['SCRAM-SHA-1' ]
543+
535544 # "self.client" is logged in as root.
536545 auth_db = self .client .pymongo_test
537546
538547 # Make a read-write user.
539- auth_db .add_user ('jesse' , 'pw' )
548+ auth_db .add_user ('jesse' , 'pw' , ** extra )
540549 self .addCleanup (remove_all_users , auth_db )
541550
542551 # Check that we're read-write by default.
@@ -547,7 +556,7 @@ def test_make_user_readonly(self):
547556 c .pymongo_test .collection .insert_one ({})
548557
549558 # Make the user read-only.
550- auth_db .add_user ('jesse' , 'pw' , read_only = True )
559+ auth_db .add_user ('jesse' , 'pw' , read_only = True , ** extra )
551560
552561 c = rs_or_single_client_noauth (username = 'jesse' ,
553562 password = 'pw' ,
@@ -558,48 +567,58 @@ def test_make_user_readonly(self):
558567 {})
559568
560569 @client_context .require_auth
570+ @ignore_deprecations
561571 def test_default_roles (self ):
572+ extra = {}
573+ if client_context .version .at_least (3 , 7 , 2 ):
574+ extra ['mechanisms' ] = ['SCRAM-SHA-1' ]
575+
562576 # "self.client" is logged in as root.
563577 auth_admin = self .client .admin
564- auth_admin .add_user ('test_default_roles' , 'pass' )
565- self .addCleanup (auth_admin . remove_user , 'test_default_roles' )
578+ auth_admin .add_user ('test_default_roles' , 'pass' , ** extra )
579+ self .addCleanup (client_context . drop_user , 'admin' , 'test_default_roles' )
566580 info = auth_admin .command (
567581 'usersInfo' , 'test_default_roles' )['users' ][0 ]
568582
569583 self .assertEqual ("root" , info ['roles' ][0 ]['role' ])
570584
571585 # Read only "admin" user
572- auth_admin .add_user ('ro-admin' , 'pass' , read_only = True )
573- self .addCleanup (auth_admin . remove_user , 'ro-admin' )
586+ auth_admin .add_user ('ro-admin' , 'pass' , read_only = True , ** extra )
587+ self .addCleanup (client_context . drop_user , 'admin' , 'ro-admin' )
574588 info = auth_admin .command ('usersInfo' , 'ro-admin' )['users' ][0 ]
575589 self .assertEqual ("readAnyDatabase" , info ['roles' ][0 ]['role' ])
576590
577591 # "Non-admin" user
578592 auth_db = self .client .pymongo_test
579- auth_db .add_user ('user' , 'pass' )
593+ auth_db .add_user ('user' , 'pass' , ** extra )
580594 self .addCleanup (remove_all_users , auth_db )
581595 info = auth_db .command ('usersInfo' , 'user' )['users' ][0 ]
582596 self .assertEqual ("dbOwner" , info ['roles' ][0 ]['role' ])
583597
584598 # Read only "Non-admin" user
585- auth_db .add_user ('ro-user' , 'pass' , read_only = True )
599+ auth_db .add_user ('ro-user' , 'pass' , read_only = True , ** extra )
586600 info = auth_db .command ('usersInfo' , 'ro-user' )['users' ][0 ]
587601 self .assertEqual ("read" , info ['roles' ][0 ]['role' ])
588602
589603 @client_context .require_auth
604+ @ignore_deprecations
590605 def test_new_user_cmds (self ):
606+ extra = {}
607+ if client_context .version .at_least (3 , 7 , 2 ):
608+ extra ['mechanisms' ] = ['SCRAM-SHA-1' ]
609+
591610 # "self.client" is logged in as root.
592611 auth_db = self .client .pymongo_test
593- auth_db .add_user ("amalia" , "password" , roles = ["userAdmin" ])
594- self .addCleanup (auth_db . remove_user , "amalia" )
612+ auth_db .add_user ("amalia" , "password" , roles = ["userAdmin" ], ** extra )
613+ self .addCleanup (client_context . drop_user , "pymongo_test" , "amalia" )
595614
596615 db = rs_or_single_client_noauth (username = "amalia" ,
597616 password = "password" ,
598617 authSource = "pymongo_test" ).pymongo_test
599618
600619 # This tests the ability to update user attributes.
601620 db .add_user ("amalia" , "new_password" ,
602- customData = {"secret" : "koalas" })
621+ customData = {"secret" : "koalas" }, ** extra )
603622
604623 user_info = db .command ("usersInfo" , "amalia" )
605624 self .assertTrue (user_info ["users" ])
@@ -610,6 +629,10 @@ def test_new_user_cmds(self):
610629 @client_context .require_auth
611630 @ignore_deprecations
612631 def test_authenticate_multiple (self ):
632+ extra = {}
633+ if client_context .version .at_least (3 , 7 , 2 ):
634+ extra ['mechanisms' ] = ['SCRAM-SHA-1' ]
635+
613636 # "self.client" is logged in as root.
614637 self .client .drop_database ("pymongo_test" )
615638 self .client .drop_database ("pymongo_test1" )
@@ -624,12 +647,15 @@ def test_authenticate_multiple(self):
624647
625648 self .assertRaises (OperationFailure , users_db .test .find_one )
626649
627- admin_db_auth .add_user ('ro-admin' , 'pass' ,
628- roles = ["userAdmin" , "readAnyDatabase" ])
650+ admin_db_auth .add_user (
651+ 'ro-admin' ,
652+ 'pass' ,
653+ roles = ["userAdmin" , "readAnyDatabase" ],
654+ ** extra )
629655
630- self .addCleanup (admin_db_auth . remove_user , 'ro-admin' )
631- users_db_auth .add_user ('user' , 'pass' ,
632- roles = ["userAdmin" , "readWrite" ])
656+ self .addCleanup (client_context . drop_user , 'admin' , 'ro-admin' )
657+ users_db_auth .add_user (
658+ 'user' , 'pass' , roles = ["userAdmin" , "readWrite" ], ** extra )
633659 self .addCleanup (remove_all_users , users_db_auth )
634660
635661 # Regular user should be able to query its own db, but
0 commit comments