Skip to content

Commit

Permalink
PYTHON-4256 OIDC Test Cleanup (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed May 9, 2024
1 parent 46da55b commit 7b12dd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
3 changes: 2 additions & 1 deletion test/auth/unified/mongodb-oidc-no-retry.json
Expand Up @@ -5,7 +5,8 @@
{
"minServerVersion": "7.0",
"auth": true,
"authMechanism": "MONGODB-OIDC"
"authMechanism": "MONGODB-OIDC",
"serverless": "forbid"
}
],
"createEntities": [
Expand Down
25 changes: 8 additions & 17 deletions test/auth_oidc/test_auth_oidc.py
Expand Up @@ -824,30 +824,21 @@ def fetch(self, a):
# Close the client.
client.close()

def test_2_4_oidc_callback_returns_invalid_data(self):
# Create a MongoClient configured with an OIDC callback that returns data not conforming to the OIDCCredential with extra fields.
class CustomCallback(OIDCCallback):
count = 0

def fetch(self, a):
self.count += 1
return OIDCCallbackResult(access_token="bad value")

client = self.create_client(request_cb=CustomCallback())
# Perform a ``find`` operation that fails.
with self.assertRaises(OperationFailure):
client.test.test.find_one()
# Close the client.
client.close()

def test_2_5_invalid_client_configuration_with_callback(self):
def test_2_4_invalid_client_configuration_with_callback(self):
# Create a MongoClient configured with an OIDC callback and auth mechanism property ENVIRONMENT:test.
request_cb = self.create_request_cb()
props: Dict = {"OIDC_CALLBACK": request_cb, "ENVIRONMENT": "test"}
# Assert it returns a client configuration error.
with self.assertRaises(ConfigurationError):
self.create_client(authmechanismproperties=props)

def test_2_5_invalid_use_of_ALLOWED_HOSTS(self):
# Create an OIDC configured client with auth mechanism properties `{"ENVIRONMENT": "azure", "ALLOWED_HOSTS": []}`.
props: Dict = {"ENVIRONMENT": "azure", "ALLOWED_HOSTS": []}
# Assert it returns a client configuration error.
with self.assertRaises(ConfigurationError):
self.create_client(authmechanismproperties=props)

def test_3_1_authentication_failure_with_cached_tokens_fetch_a_new_token_and_retry(self):
# Create a MongoClient and an OIDC callback that implements the provider logic.
client = self.create_client()
Expand Down

0 comments on commit 7b12dd4

Please sign in to comment.