social_auth tests: Test registration with ldap populator enabled.

Finishes testing for the last remaining case and thus closes #13298.
This commit is contained in:
Mateusz Mandera
2019-11-01 00:33:56 +01:00
committed by Tim Abbott
parent c1095474c6
commit 849c925dc9

View File

@@ -766,8 +766,9 @@ class SocialAuthBase(ZulipTestCase):
# Name wasn't changed at all
self.assertEqual(hamlet.full_name, "King Hamlet")
def stage_two_of_registration(self, result: HttpResponse, realm: Realm, email: str,
name: str, expected_final_name: str) -> None:
def stage_two_of_registration(self, result: HttpResponse, realm: Realm, subdomain: str,
email: str, name: str, expected_final_name: str,
skip_registration_form: bool) -> None:
data = load_subdomain_token(result)
self.assertEqual(data['email'], email)
self.assertEqual(data['name'], name)
@@ -789,7 +790,7 @@ class SocialAuthBase(ZulipTestCase):
data = {"from_confirmation": "1",
"key": confirmation_key}
result = self.client_post('/accounts/register/', data)
if not self.BACKEND_CLASS.full_name_validated:
if not skip_registration_form:
self.assert_in_response("We just need you to do one last thing", result)
# Verify that the user is asked for name but not password
@@ -815,18 +816,21 @@ class SocialAuthBase(ZulipTestCase):
"""If the user doesn't exist yet, social auth can be used to register an account"""
email = "newuser@zulip.com"
name = 'Full Name'
subdomain = 'zulip'
realm = get_realm("zulip")
account_data_dict = self.get_account_data_dict(email=email, name=name)
result = self.social_auth_test(account_data_dict,
expect_choose_email_screen=True,
subdomain='zulip', is_signup='1')
self.stage_two_of_registration(result, realm, email, name, name)
subdomain=subdomain, is_signup='1')
self.stage_two_of_registration(result, realm, subdomain, email, name, name,
self.BACKEND_CLASS.full_name_validated)
@override_settings(TERMS_OF_SERVICE=None)
def test_social_auth_registration_using_multiuse_invite(self) -> None:
"""If the user doesn't exist yet, social auth can be used to register an account"""
email = "newuser@zulip.com"
name = 'Full Name'
subdomain = 'zulip'
realm = get_realm("zulip")
realm.invite_required = True
realm.save()
@@ -848,16 +852,17 @@ class SocialAuthBase(ZulipTestCase):
# First, try to signup for closed realm without using an invitation
result = self.social_auth_test(account_data_dict,
expect_choose_email_screen=True,
subdomain='zulip', is_signup='1')
subdomain=subdomain, is_signup='1')
result = self.client_get(result.url)
# Verify that we're unable to signup, since this is a closed realm
self.assertEqual(result.status_code, 200)
self.assert_in_success_response(["Sign up"], result)
result = self.social_auth_test(account_data_dict, subdomain='zulip', is_signup='1',
result = self.social_auth_test(account_data_dict, subdomain=subdomain, is_signup='1',
expect_choose_email_screen=True,
multiuse_object_key=multiuse_object_key)
self.stage_two_of_registration(result, realm, email, name, name)
self.stage_two_of_registration(result, realm, subdomain, email, name, name,
self.BACKEND_CLASS.full_name_validated)
def test_social_auth_registration_without_is_signup(self) -> None:
"""If `is_signup` is not set then a new account isn't created"""
@@ -908,6 +913,32 @@ class SocialAuthBase(ZulipTestCase):
'in one of the domains that are allowed to register '
'for accounts in this organization.'.format(email), result)
@override_settings(TERMS_OF_SERVICE=None)
def test_social_auth_with_ldap_populate_registration_from_confirmation(self) -> None:
self.init_default_ldap_database()
email = "newuser@zulip.com"
name = "Full Name"
realm = get_realm("zulip")
subdomain = "zulip"
ldap_user_attr_map = {'full_name': 'cn'}
account_data_dict = self.get_account_data_dict(email=email, name=name)
backend_path = 'zproject.backends.{}'.format(self.BACKEND_CLASS.__name__)
with self.settings(
POPULATE_PROFILE_VIA_LDAP=True,
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map,
AUTHENTICATION_BACKENDS=(backend_path,
'zproject.backends.ZulipLDAPUserPopulator',
'zproject.backends.ZulipDummyBackend')
):
result = self.social_auth_test(account_data_dict,
expect_choose_email_screen=True,
subdomain=subdomain, is_signup='1')
# Full name should get populated from ldap:
self.stage_two_of_registration(result, realm, subdomain, email, name, "New LDAP fullname",
skip_registration_form=True)
def test_social_auth_complete(self) -> None:
with mock.patch('social_core.backends.oauth.BaseOAuth2.process_error',
side_effect=AuthFailed('Not found')):