Пример #1
0
 def test_new_user_displayname_is_used_if_first_and_last_are_missing(self):
     """
     Azure AD does not mark the First and Last names as required, only the
     Display Name. If First and Last are missing, ensure that this
     information is then obtained from the Display Name
     """
     username = '******'
     reg_form = RegisterWebUserForm()
     reg_form.cleaned_data = {
         'email': username,
         'phone_number': '+15555555555',
         'project_name': 'test-vault',
         'persona': 'Other',
         'persona_other': "for tests",
     }
     generator.store_display_name_in_saml_user_data(self.request,
                                                    'Vanessa van Beek')
     AsyncSignupRequest.create_from_registration_form(reg_form)
     user = auth.authenticate(
         request=self.request,
         username=username,
         idp_slug=self.idp.slug,
         is_handshake_successful=True,
     )
     self.assertIsNotNone(user)
     self.assertEqual(user.username, username)
     self.assertEqual(user.first_name, 'Vanessa')
     self.assertEqual(user.last_name, 'van Beek')
     self.assertEqual(self.request.sso_new_user_messages['success'],
                      ["User account for [email protected] created."])
Пример #2
0
 def test_new_user_displayname_with_one_name_is_used_as_first_name(self):
     """
     Ensure that if the Azure AD "Display Name" has only one name/word in
     it that only the first name is populated.
     """
     username = '******'
     reg_form = RegisterWebUserForm()
     reg_form.cleaned_data = {
         'email': username,
         'phone_number': '+15555555555',
         'project_name': 'test-vault',
         'persona': 'Other',
         'persona_other': "for tests",
     }
     generator.store_display_name_in_saml_user_data(self.request, 'Test')
     AsyncSignupRequest.create_from_registration_form(reg_form)
     user = auth.authenticate(
         request=self.request,
         username=username,
         idp_slug=self.idp.slug,
         is_handshake_successful=True,
     )
     self.assertIsNotNone(user)
     self.assertEqual(user.username, username)
     self.assertEqual(user.first_name, 'Test')
     self.assertEqual(user.last_name, '')
     self.assertEqual(self.request.sso_new_user_messages['success'],
                      ["User account for [email protected] created."])
Пример #3
0
 def test_new_user_created_and_data_is_saved(self):
     """
     SsoBackend should create a new user if the username passed to does
     not exist and the email domain matches an AuthenticatedEmailDomain
     for the given IdentityProvider. It should also ensure that any
     user data from a registration form and/or the samlUserdata are all
     properly saved to the User model.
     """
     username = '******'
     reg_form = RegisterWebUserForm()
     reg_form.cleaned_data = {
         'email': username,
         'phone_number': '+15555555555',
         'project_name': 'test-vault',
         'persona': 'Other',
         'persona_other': "for tests",
     }
     generator.store_full_name_in_saml_user_data(self.request, 'Maarten',
                                                 'van der Berg')
     AsyncSignupRequest.create_from_registration_form(reg_form)
     user = auth.authenticate(
         request=self.request,
         username=username,
         idp_slug=self.idp.slug,
         is_handshake_successful=True,
     )
     self.assertIsNotNone(user)
     self.assertEqual(user.username, username)
     self.assertEqual(user.first_name, 'Maarten')
     self.assertEqual(user.last_name, 'van der Berg')
     web_user = WebUser.get_by_username(user.username)
     self.assertEqual(web_user.phone_numbers[0], '+15555555555')
     self.assertEqual(self.request.sso_new_user_messages['success'],
                      ["User account for [email protected] created."])