-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: Redact SSO PII before deletion #38425
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
Merged
+330
−11
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9a178e3
fix: Redact SSO PII before deletion
ktyagiapphelix2u 8d57698
fix: Redact SSO PII before deletion
ktyagiapphelix2u 2688ac8
fix: Redact SSO PII before deletion
ktyagiapphelix2u ff4b57e
fix: Redact SSO PII before deletion
ktyagiapphelix2u 417aa3d
fix: Redact SSO PII before deletion
ktyagiapphelix2u 542b5be
fix: Redact SSO PII before deletion
ktyagiapphelix2u 1b46be6
fix: Redact SSO PII before deletion
ktyagiapphelix2u 74d655b
fix: Redact SSO PII before deletion
ktyagiapphelix2u 08b491f
fix: Redact SSO PII before deletion
ktyagiapphelix2u bbb5643
fix: Redact SSO PII before deletion
ktyagiapphelix2u 07b82ff
fix: Redact SSO PII before deletion
ktyagiapphelix2u 15bcdc0
fix: Redact SSO PII before deletion
ktyagiapphelix2u 2a9fba8
fix: Redact SSO PII before deletion
ktyagiapphelix2u dd7ac9c
fix: Redact SSO PII before deletion
ktyagiapphelix2u 5ca020f
fix: Redact SSO PII before deletion
ktyagiapphelix2u cdb49a2
fix: Redact SSO PII before deletion
ktyagiapphelix2u bd3c108
fix: Redact SSO PII before deletion
ktyagiapphelix2u 7528c08
fix: Redact SSO PII before deletion
ktyagiapphelix2u 2af3cb4
fix: Redact SSO PII before deletion
ktyagiapphelix2u 9a8ba84
fix: Redact SSO PII before deletion
ktyagiapphelix2u a75fb7f
Merge branch 'master' into ktyagi/SSOPII
ktyagiapphelix2u 0cbee49
fix: Redact SSO PII before deletion
ktyagiapphelix2u c902e56
fix: Redact SSO PII before deletion
ktyagiapphelix2u 5b3312e
fix: Redact SSO PII before deletion
ktyagiapphelix2u 9aa4192
fix: Redact SSO PII before deletion
ktyagiapphelix2u 36192df
fix: Redact SSO PII before deletion
ktyagiapphelix2u fa6c761
Merge branch 'master' into ktyagi/SSOPII
robrap 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
Some comments aren't visible on the classic Files Changed page.
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
76 changes: 76 additions & 0 deletions
76
openedx/core/djangoapps/user_api/accounts/tests/test_signals.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,76 @@ | ||
| """ | ||
| Tests for user_api accounts signals. | ||
| """ | ||
|
|
||
| import logging | ||
| from unittest.mock import patch | ||
|
|
||
| from django.test import TestCase | ||
| from social_django.models import UserSocialAuth | ||
|
|
||
| from common.djangoapps.student.tests.factories import UserFactory | ||
| from openedx.core.djangoapps.user_api.accounts.signals import get_redacted_social_auth_uid | ||
| from openedx.core.djangolib.testing.utils import skip_unless_lms | ||
|
|
||
|
|
||
| @skip_unless_lms | ||
| class RedactSocialAuthPIIOnDeleteSignalTest(TestCase): | ||
| """ | ||
| Tests for the redact_social_auth_pii_before_deletion pre_delete signal handler. | ||
| """ | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.user = UserFactory.create(username='testuser', email='testuser@example.com') | ||
|
|
||
| def _create_social_auth(self, uid='user@example.com', extra_data=None): | ||
| if extra_data is None: | ||
| extra_data = {'email': 'user@example.com', 'name': 'Test User'} | ||
| return UserSocialAuth.objects.create( | ||
| user=self.user, | ||
| provider='google-oauth2', | ||
| uid=uid, | ||
| extra_data=extra_data, | ||
| ) | ||
|
|
||
| def test_get_redacted_social_auth_uid_format(self): | ||
| """ | ||
| Test that get_redacted_social_auth_uid returns the expected string format. | ||
|
|
||
| This is the single source of truth for the redacted uid format. | ||
| """ | ||
| assert get_redacted_social_auth_uid(42) == 'redacted-before-delete-42@safe.com' | ||
| assert get_redacted_social_auth_uid(1) == 'redacted-before-delete-1@safe.com' | ||
|
|
||
| @patch('openedx.core.djangoapps.user_api.accounts.signals.redact_and_delete_social_auth') | ||
| def test_signal_warns_and_redacts_when_not_already_redacted(self, mock_redact): | ||
| """ | ||
| When a UserSocialAuth is deleted without prior redaction, the signal handler | ||
| should log a warning and call redact_and_delete_social_auth with skip_delete=True. | ||
| """ | ||
| social_auth = self._create_social_auth() | ||
|
|
||
| with self.assertLogs( | ||
| 'openedx.core.djangoapps.user_api.accounts.signals', level=logging.WARNING | ||
| ) as log_ctx: | ||
| social_auth.delete() | ||
|
|
||
| mock_redact.assert_called_once_with(self.user.id, skip_delete=True) | ||
| assert any('was deleted without first being redacted' in msg for msg in log_ctx.output) | ||
|
|
||
| @patch('openedx.core.djangoapps.user_api.accounts.signals.redact_and_delete_social_auth') | ||
| def test_signal_skips_warning_and_redaction_when_already_redacted(self, mock_redact): | ||
| """ | ||
| When a UserSocialAuth is already redacted before deletion, the signal handler | ||
| should not log a warning and should not call redact_and_delete_social_auth. | ||
| """ | ||
| social_auth = self._create_social_auth() | ||
| social_auth.uid = get_redacted_social_auth_uid(social_auth.pk) | ||
| social_auth.extra_data = {} | ||
| social_auth.save(update_fields=['uid', 'extra_data']) | ||
| social_auth_id = social_auth.id | ||
|
|
||
| social_auth.delete() | ||
|
|
||
| mock_redact.assert_not_called() | ||
| assert not UserSocialAuth.objects.filter(id=social_auth_id).exists() |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.