From 7b12dd482c4b32885e706830090555e2901fbc11 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 8 May 2024 19:31:19 -0500 Subject: [PATCH] PYTHON-4256 OIDC Test Cleanup (#1632) --- test/auth/unified/mongodb-oidc-no-retry.json | 3 ++- test/auth_oidc/test_auth_oidc.py | 25 +++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/test/auth/unified/mongodb-oidc-no-retry.json b/test/auth/unified/mongodb-oidc-no-retry.json index 9dbe198270..0a8658455e 100644 --- a/test/auth/unified/mongodb-oidc-no-retry.json +++ b/test/auth/unified/mongodb-oidc-no-retry.json @@ -5,7 +5,8 @@ { "minServerVersion": "7.0", "auth": true, - "authMechanism": "MONGODB-OIDC" + "authMechanism": "MONGODB-OIDC", + "serverless": "forbid" } ], "createEntities": [ diff --git a/test/auth_oidc/test_auth_oidc.py b/test/auth_oidc/test_auth_oidc.py index 7ea565935d..c7614fa0c3 100644 --- a/test/auth_oidc/test_auth_oidc.py +++ b/test/auth_oidc/test_auth_oidc.py @@ -824,23 +824,7 @@ 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"} @@ -848,6 +832,13 @@ def test_2_5_invalid_client_configuration_with_callback(self): 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()