mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
Handle social auth exception in auth_complete.
In case of an exception, we log it and return None which results in a redirect to the login page.
This commit is contained in:
@@ -37,7 +37,7 @@ from zproject.backends import ZulipDummyBackend, EmailAuthBackend, \
|
|||||||
from zerver.views.auth import maybe_send_to_registration
|
from zerver.views.auth import maybe_send_to_registration
|
||||||
from version import ZULIP_VERSION
|
from version import ZULIP_VERSION
|
||||||
|
|
||||||
from social_core.exceptions import AuthFailed
|
from social_core.exceptions import AuthFailed, AuthStateForbidden
|
||||||
from social_django.strategy import DjangoStrategy
|
from social_django.strategy import DjangoStrategy
|
||||||
from social_django.storage import BaseDjangoStorage
|
from social_django.storage import BaseDjangoStorage
|
||||||
from social_core.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
|
from social_core.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
|
||||||
@@ -521,6 +521,19 @@ class GitHubAuthBackendTest(ZulipTestCase):
|
|||||||
|
|
||||||
utils.BACKENDS = settings.AUTHENTICATION_BACKENDS
|
utils.BACKENDS = settings.AUTHENTICATION_BACKENDS
|
||||||
|
|
||||||
|
def test_github_complete_when_base_exc_is_raised(self):
|
||||||
|
# type: () -> None
|
||||||
|
from social_django import utils
|
||||||
|
utils.BACKENDS = ('zproject.backends.GitHubAuthBackend',)
|
||||||
|
with mock.patch('social_core.backends.oauth.BaseOAuth2.auth_complete',
|
||||||
|
side_effect=AuthStateForbidden('State forbidden')), \
|
||||||
|
mock.patch('zproject.backends.logging.exception'):
|
||||||
|
result = self.client_get(reverse('social:complete', args=['github']))
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
self.assertIn('login', result.url)
|
||||||
|
|
||||||
|
utils.BACKENDS = settings.AUTHENTICATION_BACKENDS
|
||||||
|
|
||||||
class ResponseMock(object):
|
class ResponseMock(object):
|
||||||
def __init__(self, status_code, data):
|
def __init__(self, status_code, data):
|
||||||
# type: (int, Any) -> None
|
# type: (int, Any) -> None
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from apiclient.sample_tools import client as googleapiclient
|
|||||||
from oauth2client.crypt import AppIdentityError
|
from oauth2client.crypt import AppIdentityError
|
||||||
from social_core.backends.github import GithubOAuth2, GithubOrganizationOAuth2, \
|
from social_core.backends.github import GithubOAuth2, GithubOrganizationOAuth2, \
|
||||||
GithubTeamOAuth2
|
GithubTeamOAuth2
|
||||||
from social_core.exceptions import AuthFailed
|
from social_core.exceptions import AuthFailed, SocialAuthBaseException
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from zerver.lib.users import check_full_name
|
from zerver.lib.users import check_full_name
|
||||||
from zerver.lib.request import JsonableError
|
from zerver.lib.request import JsonableError
|
||||||
@@ -185,6 +185,9 @@ class SocialAuthMixin(ZulipAuthMixin):
|
|||||||
return super(SocialAuthMixin, self).auth_complete(*args, **kwargs) # type: ignore
|
return super(SocialAuthMixin, self).auth_complete(*args, **kwargs) # type: ignore
|
||||||
except AuthFailed:
|
except AuthFailed:
|
||||||
return None
|
return None
|
||||||
|
except SocialAuthBaseException as e:
|
||||||
|
logging.exception(e)
|
||||||
|
return None
|
||||||
|
|
||||||
class ZulipDummyBackend(ZulipAuthMixin):
|
class ZulipDummyBackend(ZulipAuthMixin):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user