|
@@ -1359,3 +1359,51 @@ class SocialAuthAllowlistTestCase(DjangoTestCase):
|
|
|
|
|
|
|
|
self.assertIn('_auth_user_id', self.client.session)
|
|
self.assertIn('_auth_user_id', self.client.session)
|
|
|
self.assertTrue(User.objects.filter(username='alice').exists())
|
|
self.assertTrue(User.objects.filter(username='alice').exists())
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class FullNameTestBackend(BaseAuth):
|
|
|
|
|
+ """
|
|
|
|
|
+ Stands in for an identity provider which supplies a user's full name but not its components.
|
|
|
|
|
+ """
|
|
|
|
|
+ name = 'fullname-test'
|
|
|
|
|
+ ID_KEY = 'email'
|
|
|
|
|
+
|
|
|
|
|
+ def auth_complete(self, *args, **kwargs):
|
|
|
|
|
+ kwargs.update(response={'email': self.data['email'], 'name': self.data['name']}, backend=self)
|
|
|
|
|
+ return self.strategy.authenticate(*args, **kwargs)
|
|
|
|
|
+
|
|
|
|
|
+ def get_user_details(self, response):
|
|
|
|
|
+ return {
|
|
|
|
|
+ 'username': response['email'].split('@')[0],
|
|
|
|
|
+ 'email': response['email'],
|
|
|
|
|
+ 'fullname': response['name'],
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@override_settings(
|
|
|
|
|
+ AUTHENTICATION_BACKENDS=[
|
|
|
|
|
+ 'netbox.tests.test_authentication.FullNameTestBackend',
|
|
|
|
|
+ 'netbox.authentication.ObjectPermissionBackend',
|
|
|
|
|
+ ],
|
|
|
|
|
+)
|
|
|
|
|
+class SocialAuthNamesTestCase(DjangoTestCase):
|
|
|
|
|
+ """
|
|
|
|
|
+ social-auth-core 6.0 moved name derivation out of the backends and into the social_names
|
|
|
|
|
+ pipeline step, which the default pipeline must therefore include (#23661).
|
|
|
|
|
+ """
|
|
|
|
|
+
|
|
|
|
|
+ def setUp(self):
|
|
|
|
|
+ # load_backends() caches the discovered backends in a module-level dict, so isolate the
|
|
|
|
|
+ # backend overridden above from the remainder of the test suite.
|
|
|
|
|
+ cache_patcher = patch.dict('social_core.backends.utils.BACKENDSCACHE', {}, clear=True)
|
|
|
|
|
+ cache_patcher.start()
|
|
|
|
|
+ self.addCleanup(cache_patcher.stop)
|
|
|
|
|
+
|
|
|
|
|
+ self.url = reverse('social:complete', args=['fullname-test'])
|
|
|
|
|
+
|
|
|
|
|
+ def test_first_and_last_name_derived_from_full_name(self):
|
|
|
|
|
+ self.client.get(self.url, {'email': 'alice@example.com', 'name': 'Alice Liddell'})
|
|
|
|
|
+
|
|
|
|
|
+ user = User.objects.get(username='alice')
|
|
|
|
|
+ self.assertEqual(user.first_name, 'Alice')
|
|
|
|
|
+ self.assertEqual(user.last_name, 'Liddell')
|