|
|
@@ -1,7 +1,7 @@
|
|
|
import os
|
|
|
import sys
|
|
|
import tempfile
|
|
|
-from types import ModuleType
|
|
|
+from types import MappingProxyType, ModuleType, SimpleNamespace
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
from django.conf import settings as django_settings
|
|
|
@@ -542,3 +542,90 @@ class LoadLdapConfigTest(SimpleTestCase):
|
|
|
django_settings.CONFIGURATION_DIR,
|
|
|
os.path.dirname(os.path.abspath(configuration_testing.__file__)),
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+class SocialAuthOldIdKeysTest(SimpleTestCase):
|
|
|
+ """
|
|
|
+ social-auth-core 5.2.0 stored Google's `sub` as the uid when USE_UNIQUE_USER_ID was set, which
|
|
|
+ social-auth-app-django's id_key backfill migration cannot detect (#23661).
|
|
|
+ """
|
|
|
+ @staticmethod
|
|
|
+ def old_id_keys(**params):
|
|
|
+ return settings_utils.social_auth_old_id_keys(SimpleNamespace(**params))
|
|
|
+
|
|
|
+ def test_nothing_configured(self):
|
|
|
+ self.assertEqual(self.old_id_keys(), {})
|
|
|
+
|
|
|
+ def test_google_oauth2_flag(self):
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID=True),
|
|
|
+ {'google-oauth2': 'sub'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_google_openidconnect_flag(self):
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(SOCIAL_AUTH_GOOGLE_OPENIDCONNECT_USE_UNIQUE_USER_ID=True),
|
|
|
+ {'google-openidconnect': 'sub'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_global_flag_covers_google_sub_backends(self):
|
|
|
+ # google-oauth (OAuth1) is left out: its current ID_KEY is `id`, not `sub`.
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(SOCIAL_AUTH_USE_UNIQUE_USER_ID=True),
|
|
|
+ {'google-oauth2': 'sub', 'google-onetap': 'sub', 'google-openidconnect': 'sub'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_backend_flag_overrides_global_flag(self):
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(
|
|
|
+ SOCIAL_AUTH_USE_UNIQUE_USER_ID=True,
|
|
|
+ SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID=False,
|
|
|
+ ),
|
|
|
+ {'google-onetap': 'sub', 'google-openidconnect': 'sub'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_id_key_overrides_flag(self):
|
|
|
+ # 5.2.0 used a configured ID_KEY ahead of USE_UNIQUE_USER_ID, so the uid is not `sub`.
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(
|
|
|
+ SOCIAL_AUTH_USE_UNIQUE_USER_ID=True,
|
|
|
+ SOCIAL_AUTH_GOOGLE_OAUTH2_ID_KEY='email',
|
|
|
+ ),
|
|
|
+ {'google-onetap': 'sub', 'google-openidconnect': 'sub'},
|
|
|
+ )
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(SOCIAL_AUTH_USE_UNIQUE_USER_ID=True, SOCIAL_AUTH_ID_KEY='email'),
|
|
|
+ {},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_configured_google_entry_wins(self):
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(
|
|
|
+ SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID=True,
|
|
|
+ SOCIAL_AUTH_OLD_ID_KEYS={'google-oauth2': 'email'},
|
|
|
+ ),
|
|
|
+ {'google-oauth2': 'email'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_configured_entries_are_kept(self):
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(
|
|
|
+ SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID=True,
|
|
|
+ SOCIAL_AUTH_OLD_ID_KEYS={'okta-oauth2': 'email'},
|
|
|
+ ),
|
|
|
+ {'google-oauth2': 'sub', 'okta-oauth2': 'email'},
|
|
|
+ )
|
|
|
+ self.assertEqual(
|
|
|
+ self.old_id_keys(SOCIAL_AUTH_OLD_ID_KEYS={'okta-oauth2': 'email'}),
|
|
|
+ {'okta-oauth2': 'email'},
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_invalid_configured_value_passed_through(self):
|
|
|
+ # The migration rejects anything but a dict with its own error. Settings must still load.
|
|
|
+ for value in (None, [('google-oauth2', 'sub')], 'google-oauth2', 1, MappingProxyType({'a': 'b'})):
|
|
|
+ with self.subTest(value=value):
|
|
|
+ result = self.old_id_keys(
|
|
|
+ SOCIAL_AUTH_GOOGLE_OAUTH2_USE_UNIQUE_USER_ID=True,
|
|
|
+ SOCIAL_AUTH_OLD_ID_KEYS=value,
|
|
|
+ )
|
|
|
+ self.assertIs(result, value)
|