-
Notifications
You must be signed in to change notification settings - Fork 22
fix: cleanup of toggle and few custom attributes #405
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
robrap
left a comment
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 didn't review tests yet, but I provided some comments. Please update the version and changelog as well. It would be great to land this soon. Thank you.
Note that the changelog can be a very brief summary.
| # .. custom_attribute_name: session_cleanup.logged_out_username | ||
| # .. custom_attribute_description: Records the username that was logged out | ||
| # during session cleanup for tracking and debugging purposes. | ||
| set_custom_attribute('session_cleanup.logged_out_username', existing_username) |
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.
Let's also remove session_cleanup.logout_performed. I think session_cleanup.logout_required is close enough and has a simpler implementation.
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.
Addressed. Removed session_cleanup.logout_performed and updated test file.
auth_backends/pipeline.py
Outdated
| # .. custom_attribute_description: Tracks whether there's a mismatch between | ||
| # the username in the social details and the user's actual username. | ||
| # True if usernames don't match, False if they match. | ||
| set_custom_attribute('update_email.username_mismatch', username_mismatch) |
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.
This is highly unexpected, so let's drop this. I think we can leave the warning, but update its text. I'll add another comment.
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.
Addressed. Dropped the update_email.username_mismatch custom attribute and modified test file.
auth_backends/pipeline.py
Outdated
| # Log warning and set additional custom attributes for mismatches | ||
| # Log warning about the mismatch | ||
| logger.warning( | ||
| "Username mismatch during email update. User username: %s, Details username: %s", |
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.
Let's combine the two warning logs into something like the following:
| "Username mismatch during email update. User username: %s, Details username: %s", | |
| "Unexpected username mismatch during email update. Skipping email update for user %s. User username: %s, Details username: %s", |
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.
Addressed. Combined two loggers into one as per suggestion.
auth_backends/pipeline.py
Outdated
| # Skip email update due to username mismatch | ||
| logger.warning( | ||
| "Skipping email update for user %s due to username mismatch", | ||
| user_username | ||
| ) |
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.
This can be removed in favor of the first log message.
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.
Addressed.
robrap
left a comment
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.
Minor clean-up request. Thank you.
| call('session_cleanup.toggle_enabled', False), | ||
| call('session_cleanup.logout_performed', False) | ||
| ], any_order=True) | ||
| mock_logger.info.assert_called_with( |
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 think this is the only assertion needed in the conditional. You should be able to remove the else block, and move all other assertions after (or before) the conditional, with the caveat of updating one assertion to:
mock_set_attr.assert_called_once_with('session_cleanup.logout_required', user_authenticated)
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.
Addressed.
| self.assertNotEqual(request.session.session_key, initial_session_key) | ||
| self.assertTrue(request.user.is_anonymous) |
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.
In this comment, I meant that I think these could move outside the conditional as well. Is that right?
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.
No, they should not be moved outside the conditional.
These assertions test the effects of logout(request), which only executes when user_authenticated=True. When user_authenticated=False, no logout happens, so the session key doesn't change and the user was already anonymous - moving the assertions outside would test nothing changed instead of logout worked correctly.
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.
@Akanshu-2u: I personally would have moved the assertions, because they should be true for both cases. From one perspective, the meaning of the assertions changes from "nothing changed" to "logout worked" depending on the test. But, from another perspective, the same assertions are true in both cases, because whether or not whether or not you start with an authenticated user, you end with an anonymous user.
It's fine to leave as-is. Or, we could follow-up with a minor PR that doesn't need to adjust changelog or version, because it would just affect tests. Either way.
auth_backends/tests/test_backends.py
Outdated
| else: | ||
| mock_set_attr.assert_called_once_with('session_cleanup.logout_required', False) | ||
|
|
||
| mock_logger.info.assert_not_called() |
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.
Oops. I missed this useful assertion. You can restore this. Sorry. But the other can stay outside the conditional.
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.
Added the assertion. Thank you.
feanil
left a comment
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.
Thanks for the further cleanup, trusting Robert's review here, I can merge and release this one the last test request has been addressed.
|
@Akanshu-2u: In addition to the last change, can you confirm that you've tested this locally (or sandbox) and confirm that all works as expected? Switching the toggle on/off in the other service (e.g. discovery) should provide no change, and you should always get the logout from start. Thanks. |
auth_backends/pipeline.py
Outdated
|
|
||
| if username_mismatch: | ||
| # Log warning and set additional custom attributes for mismatches | ||
| # Log warning about the mismatch |
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.
@Akanshu-2u: You can remove this comment. It doesn't add anything.
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.
Addressed.
Yes, I have tested the current changes locally as well as on sandbox. For both the cases as expeted user is getting logged out from start. So changes are working well. |
Description:
This PR focusses on the removal of the toggles and custom attributes from both
EdXOAuth2.start()andupdate_email().Solution:
Removed
ENABLE_OAUTH_SESSION_CLEANUPfromEdXOAuth2.start().Removed
SKIP_UPDATE_EMAIL_ON_USERNAME_MISMATCHfromupdate_email().Custom-attributes in
EdXOAuth2.start():Removed:
session_cleanup.has_request: Tracks whether a request object is available during OAuth start. This is a technical implementation detail that doesn't provide actionable insights.session_cleanup.logged_out_username: Records the username that was logged out during session cleanup. Storing usernames in monitoring data may violate privacy policies.Retained:
session_cleanup.logout_required: Tracks whether a user was authenticated before session cleanup . Critical for detecting potential session hijacking and concurrent login attempts.Custom-attributes in
update_email():Removed:
update_email.details_username- Privacy risk: stores personal identifiers in monitoring data.update_email.user_username- Security risk: exposes usernames in monitoring dashboards.update_email.details_has_email- Low value: technical detail creating monitoring noise.Retained:
update_email.username_mismatch- Critical for security monitoring and detecting potential account takeover attempts.update_email.email_updated- Essential for tracking successful email updates and operational health.Related PRs:
JIRA Ticket:
BOMS-3