-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4256 OIDC Spec Cleanup #1556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…eturns error 18 resync specs fix connection string test Update prose tests
There was a problem hiding this 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!
pymongo/auth_oidc.py
Outdated
except Exception: # noqa: S110 | ||
pass | ||
except OperationFailure as e: | ||
if e.code == 18: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/auth_oidc/test_auth_oidc.py
Outdated
@@ -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__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended comment-out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
test/auth_oidc/test_auth_oidc.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended comment-out?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this 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!
Requires mongodb-labs/drivers-evergreen-tools#428