mirror of https://github.com/zulip/zulip.git
github: Go to registration if email is invalid.
This commit is contained in:
parent
c5218fb584
commit
8e87ba439d
|
@ -623,11 +623,19 @@ class GitHubAuthBackendTest(ZulipTestCase):
|
||||||
from social_django import utils
|
from social_django import utils
|
||||||
utils.BACKENDS = ('zproject.backends.GitHubAuthBackend',)
|
utils.BACKENDS = ('zproject.backends.GitHubAuthBackend',)
|
||||||
with mock.patch('zproject.backends.GitHubAuthBackend.get_email_address',
|
with mock.patch('zproject.backends.GitHubAuthBackend.get_email_address',
|
||||||
return_value=None), \
|
return_value=None) as mock_get_email_address, \
|
||||||
mock.patch('zproject.backends.logging.exception'):
|
mock.patch('social_core.backends.oauth.OAuthAuth.validate_state',
|
||||||
result = self.client_get(reverse('social:complete', args=['github']))
|
return_value='state'), \
|
||||||
self.assertEqual(result.status_code, 302)
|
mock.patch('social_core.backends.oauth.BaseOAuth2.request_access_token',
|
||||||
self.assertIn('login', result.url)
|
return_value={'access_token': 'token'}), \
|
||||||
|
mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
|
||||||
|
side_effect=self.do_auth), \
|
||||||
|
mock.patch('zproject.backends.logging.warning'):
|
||||||
|
result = self.client_get(reverse('social:complete', args=['github']),
|
||||||
|
info={'state': 'state'})
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
self.assertIn("Let's get started", result.content.decode('utf8'))
|
||||||
|
self.assertEqual(mock_get_email_address.call_count, 2)
|
||||||
|
|
||||||
utils.BACKENDS = settings.AUTHENTICATION_BACKENDS
|
utils.BACKENDS = settings.AUTHENTICATION_BACKENDS
|
||||||
|
|
||||||
|
|
|
@ -198,13 +198,17 @@ class SocialAuthMixin(ZulipAuthMixin):
|
||||||
invalid_subdomain = return_data.get('invalid_subdomain')
|
invalid_subdomain = return_data.get('invalid_subdomain')
|
||||||
invalid_email = return_data.get('invalid_email')
|
invalid_email = return_data.get('invalid_email')
|
||||||
|
|
||||||
if inactive_user or inactive_realm or invalid_email:
|
if inactive_user or inactive_realm:
|
||||||
# Redirect to login page. We can't send to registration
|
# Redirect to login page. We can't send to registration
|
||||||
# workflow with these errors.
|
# workflow with these errors. We will redirect to login page.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# If user_profile is `None` here, send the user to registration
|
if invalid_email:
|
||||||
# workflow.
|
# In case of invalid email, we will end up on registration page.
|
||||||
|
# This seems better than redirecting to login page.
|
||||||
|
logging.warning(
|
||||||
|
"{} got invalid email argument.".format(self.auth_backend_name)
|
||||||
|
)
|
||||||
|
|
||||||
strategy = self.strategy # type: ignore # This comes from Python Social Auth.
|
strategy = self.strategy # type: ignore # This comes from Python Social Auth.
|
||||||
request = strategy.request
|
request = strategy.request
|
||||||
|
|
Loading…
Reference in New Issue