Skip to content

Conversation

blink1073
Copy link
Member

@blink1073 blink1073 commented Mar 19, 2024

@blink1073 blink1073 changed the title PYTHON-4256 Only invalidate cached OIDC access tokens if the server returns error 18 PYTHON-4256 OIDC Spec Cleanup Apr 3, 2024
…eturns error 18

resync specs

fix connection string test

Update prose tests
@blink1073 blink1073 marked this pull request as ready for review April 9, 2024 17:22
@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot requested a review from Jibola April 9, 2024 17:32
@blink1073 blink1073 requested review from NoahStapp and removed request for Jibola April 9, 2024 20:29
Copy link
Contributor

@NoahStapp NoahStapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few clarifying questions, otherwise looks good!

except Exception: # noqa: S110
pass
except OperationFailure as e:
if e.code == 18:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these three mostly-duplicate code blocks be abstracted into a helper method that takes an appropriate callback to handle the error code 18 case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callback seemed too awkward, but I made it into a validator.

@@ -90,6 +90,9 @@
# Server code raised when re-authentication is required
_REAUTHENTICATION_REQUIRED_CODE: int = 391

# Server code raised when authentication fails.
_AUTHENTICATION_FAILURE_CODE: int = 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this constant instead of the magic number 18 in auth_oidc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -53,7 +53,7 @@
TOKEN_FILE = os.environ.get("OIDC_TOKEN_FILE", "")

# Generate unified tests.
globals().update(generate_test_classes(str(TEST_PATH), module=__name__))
# globals().update(generate_test_classes(str(TEST_PATH), module=__name__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended comment-out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

def create_request_cb(self, username="test_user1", sleep=0):
def request_token(context):
# Validate the info.
self.assertIsInstance(context.idp_info.issuer, str)
self.assertIsInstance(context.idp_info.clientId, str)
# self.assertIsInstance(context.idp_info.clientId, str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended comment-out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

uri = "mongodb+srv://example.com?authMechanism=MONGODB-OIDC&authMechanismProperties=ALLOWED_HOSTS:%5B%22example.com%22%5D"
with self.assertRaises(ConfigurationError), warnings.catch_warnings():
warnings.simplefilter("ignore")
_ = MongoClient(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointless assignment just for the linter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@blink1073 blink1073 requested a review from NoahStapp April 10, 2024 13:06
Copy link
Contributor

@NoahStapp NoahStapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the validator approach a lot!

@blink1073 blink1073 merged commit efe8cc3 into mongodb:master Apr 10, 2024
@blink1073 blink1073 deleted the PYTHON-4256 branch April 10, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants