MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_scram

Method test_scram

test/test_auth.py:474–563  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

472
473 @client_context.require_no_fips
474 def test_scram(self):
475 # Step 1: create users
476 client_context.create_user(
477 "testscram", "sha1", "pwd", roles=["dbOwner"], mechanisms=["SCRAM-SHA-1"]
478 )
479 client_context.create_user(
480 "testscram", "sha256", "pwd", roles=["dbOwner"], mechanisms=["SCRAM-SHA-256"]
481 )
482 client_context.create_user(
483 "testscram",
484 "both",
485 "pwd",
486 roles=["dbOwner"],
487 mechanisms=["SCRAM-SHA-1", "SCRAM-SHA-256"],
488 )
489
490 # Step 2: verify auth success cases
491 client = self.rs_or_single_client_noauth(
492 username="sha1", password="pwd", authSource="testscram"
493 )
494 client.testscram.command("dbstats")
495
496 client = self.rs_or_single_client_noauth(
497 username="sha1", password="pwd", authSource="testscram", authMechanism="SCRAM-SHA-1"
498 )
499 client.testscram.command("dbstats")
500
501 client = self.rs_or_single_client_noauth(
502 username="sha256", password="pwd", authSource="testscram"
503 )
504 client.testscram.command("dbstats")
505
506 client = self.rs_or_single_client_noauth(
507 username="sha256", password="pwd", authSource="testscram", authMechanism="SCRAM-SHA-256"
508 )
509 client.testscram.command("dbstats")
510
511 # Step 2: SCRAM-SHA-1 and SCRAM-SHA-256
512 client = self.rs_or_single_client_noauth(
513 username="both", password="pwd", authSource="testscram", authMechanism="SCRAM-SHA-1"
514 )
515 client.testscram.command("dbstats")
516 client = self.rs_or_single_client_noauth(
517 username="both", password="pwd", authSource="testscram", authMechanism="SCRAM-SHA-256"
518 )
519 client.testscram.command("dbstats")
520
521 self.listener.reset()
522 client = self.rs_or_single_client_noauth(
523 username="both", password="pwd", authSource="testscram", event_listeners=[self.listener]
524 )
525 client.testscram.command("dbstats")
526 if client_context.version.at_least(4, 4, -1):
527 # Speculative authentication in 4.4+ sends saslStart with the
528 # handshake.
529 self.assertEqual(self.listener.started_events, [])
530 else:
531 started = self.listener.started_events[0]

Callers

nothing calls this directly

Calls 8

at_leastMethod · 0.80
single_client_noauthMethod · 0.80
create_userMethod · 0.45
commandMethod · 0.45
resetMethod · 0.45
getMethod · 0.45
get_databaseMethod · 0.45

Tested by

no test coverage detected