-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: prevent silent errors during SSO (account settings) #38673
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
Draft
Gi-ron
wants to merge
3
commits into
openedx:master
Choose a base branch
from
eduNEXT:sgb/render-tpa-account-mfe-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−8
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
openedx/core/djangoapps/user_api/tests/test_legacy_urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """ | ||
| Tests for account_settings_redirect_view in legacy_urls.py. | ||
| """ | ||
| from django.test import RequestFactory, TestCase, override_settings | ||
|
|
||
| from common.djangoapps.third_party_auth.middleware import ( | ||
| TPA_ERROR_BACKEND_SESSION_KEY, | ||
| TPA_ERROR_CODE_SESSION_KEY, | ||
| ) | ||
| from openedx.core.djangoapps.user_api.legacy_urls import account_settings_redirect_view | ||
|
|
||
|
|
||
| @override_settings(ACCOUNT_MICROFRONTEND_URL='https://account.example.com') | ||
| class AccountSettingsRedirectViewTests(TestCase): | ||
| """ | ||
| Tests for the view that replaces the legacy /account/settings | ||
| RedirectView, so that third-party-auth errors saved in the session by | ||
| ExceptionMiddleware are forwarded to the Account MFE as query params. | ||
| """ | ||
|
|
||
| def _build_request(self, error_code=None, backend_name=None): | ||
| """Build a fake request with optional TPA error session data.""" | ||
| request = RequestFactory().get('/account/settings') | ||
| request.session = {} | ||
| if error_code: | ||
| request.session[TPA_ERROR_CODE_SESSION_KEY] = error_code | ||
| if backend_name: | ||
| request.session[TPA_ERROR_BACKEND_SESSION_KEY] = backend_name | ||
| return request | ||
|
|
||
| def test_redirects_without_params_when_no_error_in_session(self): | ||
| """Redirect to Account MFE without query params when session has no errors.""" | ||
| request = self._build_request() | ||
|
|
||
| response = account_settings_redirect_view(request) | ||
|
|
||
| assert response.status_code == 302 | ||
| assert response.url == 'https://account.example.com' | ||
|
|
||
| def test_redirects_with_duplicate_provider_param(self): | ||
| """Redirect includes duplicate_provider-specific query param when applicable.""" | ||
| request = self._build_request(error_code='duplicate_provider', backend_name='tpa-saml') | ||
|
|
||
| response = account_settings_redirect_view(request) | ||
|
|
||
| assert response.status_code == 302 | ||
| assert response.url.startswith('https://account.example.com/?') | ||
| assert 'tpa_error_code=duplicate_provider' in response.url | ||
| assert 'duplicate_provider=' in response.url | ||
|
|
||
| def test_redirects_with_other_error_code_without_duplicate_provider_param(self): | ||
| """ | ||
| For error codes other than 'duplicate_provider', only tpa_error_code | ||
| should be sent -- 'duplicate_provider' is specific to the | ||
| AuthAlreadyAssociated case, which is the only one the Account MFE | ||
| currently knows how to render. | ||
| """ | ||
| request = self._build_request(error_code='auth_canceled', backend_name='tpa-saml') | ||
|
|
||
| response = account_settings_redirect_view(request) | ||
|
|
||
| assert response.status_code == 302 | ||
| assert 'tpa_error_code=auth_canceled' in response.url | ||
| assert 'duplicate_provider' not in response.url | ||
|
|
||
| def test_session_error_keys_are_consumed(self): | ||
| """Ensure TPA error session keys are cleared after redirect.""" | ||
| request = self._build_request(error_code='duplicate_provider', backend_name='tpa-saml') | ||
|
|
||
| account_settings_redirect_view(request) | ||
|
|
||
| assert TPA_ERROR_CODE_SESSION_KEY not in request.session | ||
| assert TPA_ERROR_BACKEND_SESSION_KEY not in request.session |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we send the params only on this error occurrence? Could we just send the params for any error type? The error should land in the list defined by
TPA_ERROR_CODES