|
|
@@ -8,6 +8,7 @@ from django.db import connection
|
|
|
from django.test import TestCase, override_settings, tag
|
|
|
from django.test.utils import CaptureQueriesContext
|
|
|
from django.utils import timezone
|
|
|
+from social_django.models import Nonce
|
|
|
|
|
|
from core.choices import DataSourceStatusChoices, JobIntervalChoices, JobStatusChoices
|
|
|
from core.events import JOB_COMPLETED
|
|
|
@@ -173,6 +174,7 @@ class SystemHousekeepingRunTestCase(HousekeepingRunnerMixin, TestCase):
|
|
|
SUBMETHODS = (
|
|
|
'send_census_report',
|
|
|
'clear_expired_sessions',
|
|
|
+ 'clear_social_auth_data',
|
|
|
'prune_changelog',
|
|
|
'delete_expired_jobs',
|
|
|
'check_for_new_releases',
|
|
|
@@ -291,6 +293,26 @@ class ClearExpiredSessionsTestCase(HousekeepingRunnerMixin, TestCase):
|
|
|
)
|
|
|
|
|
|
|
|
|
+class ClearSocialAuthDataTestCase(HousekeepingRunnerMixin, TestCase):
|
|
|
+ def test_clear_social_auth_data_deletes_only_stale_nonces(self):
|
|
|
+ # Each SSO login started leaves a nonce, which only a completed login removes (#23661).
|
|
|
+ now = int(timezone.now().timestamp())
|
|
|
+ Nonce.objects.create(server_url='social_core.oauth2.google-oauth2', timestamp=now - 86400 * 15, salt='old')
|
|
|
+ Nonce.objects.create(server_url='social_core.oauth2.google-oauth2', timestamp=now, salt='recent')
|
|
|
+
|
|
|
+ self._runner().clear_social_auth_data()
|
|
|
+
|
|
|
+ self.assertEqual(list(Nonce.objects.values_list('salt', flat=True)), ['recent'])
|
|
|
+
|
|
|
+ def test_clear_social_auth_data_failure_does_not_stop_housekeeping(self):
|
|
|
+ # e.g. a non-numeric PARTIAL_PIPELINE_EXPIRED_THRESHOLD raises TypeError inside clearsocial.
|
|
|
+ runner = self._runner()
|
|
|
+ with patch('core.jobs.call_command', side_effect=TypeError('bad threshold')):
|
|
|
+ runner.clear_social_auth_data() # must not raise
|
|
|
+
|
|
|
+ runner.logger.exception.assert_called_once()
|
|
|
+
|
|
|
+
|
|
|
class DeleteExpiredJobsTestCase(HousekeepingRunnerMixin, TestCase):
|
|
|
def test_delete_expired_jobs_skips_when_retention_unset(self):
|
|
|
old_job = Job.objects.create(name='old', job_id=uuid.uuid4())
|