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:
Umair Khan
2017-03-07 12:32:40 +05:00
committed by Tim Abbott
parent fa9b8d8114
commit 1f60baba6b
2 changed files with 18 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ from zproject.backends import ZulipDummyBackend, EmailAuthBackend, \
from zerver.views.auth import maybe_send_to_registration
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.storage import BaseDjangoStorage
from social_core.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
@@ -521,6 +521,19 @@ class GitHubAuthBackendTest(ZulipTestCase):
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):
def __init__(self, status_code, data):
# type: (int, Any) -> None