forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-backend: Raise zerver/views/registration.py test coverage to 100%.
- Loading branch information
1 parent
25d9aac
commit 1138057
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -999,6 +999,42 @@ def test_signup_invalid_name(self): | |
result = self.submit_reg_form_for_user(email, password, full_name="<invalid>") | ||
self.assert_in_success_response(["Invalid characters in name!"], result) | ||
|
||
def test_signup_without_password(self): | ||
# type: () -> None | ||
""" | ||
Check if signing up without a password works properly when | ||
password_auth_enabled is False. | ||
""" | ||
|
||
email = "[email protected]" | ||
|
||
result = self.client_post('/accounts/home/', {'email': email}) | ||
self.assertEqual(result.status_code, 302) | ||
self.assertTrue(result["Location"].endswith( | ||
"/accounts/send_confirm/%s" % (email,))) | ||
result = self.client_get(result["Location"]) | ||
self.assert_in_response("Check your email so we can get started.", result) | ||
|
||
# Visit the confirmation link. | ||
confirmation_url = self.get_confirmation_url_from_outbox(email) | ||
result = self.client_get(confirmation_url) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
with patch('zerver.views.registration.password_auth_enabled', return_value=False): | ||
result = self.client_post( | ||
'/accounts/register/', | ||
{'full_name': 'New User', | ||
'realm_name': 'Zulip Test', | ||
'realm_subdomain': 'zuliptest', | ||
'key': find_key_by_email(email), | ||
'realm_org_type': Realm.COMMUNITY, | ||
'terms': True}) | ||
|
||
# User should now be logged in. | ||
self.assertEqual(result.status_code, 302) | ||
user_profile = get_user_profile_by_email(email) | ||
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) | ||
|
||
def test_signup_without_full_name(self): | ||
# type: () -> None | ||
""" | ||
|
@@ -1031,6 +1067,46 @@ def test_signup_without_full_name(self): | |
'from_confirmation': '1'}) | ||
self.assert_in_success_response(["You're almost there."], result) | ||
|
||
def test_signup_invalid_subdomain(self): | ||
# type: () -> None | ||
""" | ||
Check if attempting to authenticate to the wrong subdomain logs an | ||
error and redirects. | ||
""" | ||
email = "[email protected]" | ||
password = "newpassword" | ||
|
||
result = self.client_post('/accounts/home/', {'email': email}) | ||
self.assertEqual(result.status_code, 302) | ||
self.assertTrue(result["Location"].endswith( | ||
"/accounts/send_confirm/%s" % (email,))) | ||
result = self.client_get(result["Location"]) | ||
self.assert_in_response("Check your email so we can get started.", result) | ||
|
||
# Visit the confirmation link. | ||
confirmation_url = self.get_confirmation_url_from_outbox(email) | ||
result = self.client_get(confirmation_url) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
def invalid_subdomain(**kwargs): | ||
# type: (**Any) -> Any | ||
return_data = kwargs.get('return_data', {}) | ||
return_data['invalid_subdomain'] = True | ||
|
||
with patch('zerver.views.registration.authenticate', side_effect=invalid_subdomain): | ||
with patch('logging.error') as mock_error: | ||
result = self.client_post( | ||
'/accounts/register/', | ||
{'password': password, | ||
'full_name': 'New User', | ||
'realm_name': 'Zulip Test', | ||
'realm_subdomain': 'zuliptest', | ||
'key': find_key_by_email(email), | ||
'realm_org_type': Realm.COMMUNITY, | ||
'terms': True}) | ||
mock_error.assert_called_once() | ||
self.assertEqual(result.status_code, 302) | ||
|
||
def test_unique_completely_open_domain(self): | ||
# type: () -> None | ||
password = "test" | ||
|
@@ -1222,14 +1298,47 @@ def test_registration_through_ldap(self): | |
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'): | ||
result = self.client_get(confirmation_url) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
# The full_name should not be overriden by the value from LDAP if | ||
# request.session['authenticated_full_name'] has not been set yet. | ||
with patch('zerver.views.registration.name_changes_disabled', return_value=True): | ||
result = self.submit_reg_form_for_user(email, | ||
password, | ||
full_name="Non LDAP Full Name", | ||
realm_name=realm_name, | ||
realm_subdomain=subdomain, | ||
# Pass HTTP_HOST for the target subdomain | ||
HTTP_HOST=subdomain + ".testserver") | ||
self.assert_in_success_response(["You're almost there.", | ||
"Non LDAP Full Name", | ||
"[email protected]"], | ||
result) | ||
|
||
# Submitting the registration form with from_confirmation='1' sets | ||
# the value of request.session['authenticated_full_name'] from LDAP. | ||
result = self.submit_reg_form_for_user(email, | ||
password, | ||
realm_name=realm_name, | ||
realm_subdomain=subdomain, | ||
from_confirmation='1', | ||
# Pass HTTP_HOST for the target subdomain | ||
HTTP_HOST=subdomain + ".testserver") | ||
self.assert_in_success_response(["You're almost there.", | ||
"New User Name", | ||
"[email protected]"], | ||
result) | ||
|
||
# The full name be populated from the value of | ||
# request.session['authenticated_full_name'] from LDAP in the case | ||
# where from_confirmation and name_changes_disabled are both False. | ||
with patch('zerver.views.registration.name_changes_disabled', return_value=True): | ||
result = self.submit_reg_form_for_user(email, | ||
password, | ||
full_name="Non LDAP Full Name", | ||
realm_name=realm_name, | ||
realm_subdomain=subdomain, | ||
# Pass HTTP_HOST for the target subdomain | ||
HTTP_HOST=subdomain + ".testserver") | ||
self.assert_in_success_response(["You're almost there.", | ||
"New User Name", | ||
"[email protected]"], | ||
|