|
|
@@ -4,6 +4,7 @@ import re
|
|
|
import sys
|
|
|
from types import ModuleType
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
+from urllib.parse import parse_qs, urlsplit
|
|
|
|
|
|
from django.conf import settings
|
|
|
from django.contrib.messages.storage.fallback import FallbackStorage
|
|
|
@@ -15,7 +16,7 @@ from django.urls import reverse
|
|
|
from django.utils.timezone import now
|
|
|
from rest_framework.test import APIClient
|
|
|
from social_core.backends.base import BaseAuth
|
|
|
-from social_core.exceptions import AuthFailed
|
|
|
+from social_core.exceptions import AuthResponseError
|
|
|
from social_django.models import UserSocialAuth
|
|
|
|
|
|
from account.views import LoginView
|
|
|
@@ -1144,8 +1145,9 @@ class SocialAuthBeginViewTestCase(DjangoTestCase):
|
|
|
"""
|
|
|
response = self.client.post(self.url, headers={'accept': 'application/json'})
|
|
|
|
|
|
- state = self.client.session['google-oauth2_state']
|
|
|
- self.assertIn(f'state={state}', response.json()['url'])
|
|
|
+ state = parse_qs(urlsplit(response.json()['url']).query)['state'][0]
|
|
|
+ transaction = self.client.session[f'google-oauth2_oauth2_state_{state}']
|
|
|
+ self.assertEqual(transaction['state'], state)
|
|
|
|
|
|
@override_settings(AUTHENTICATION_BACKENDS=SSO_BACKENDS)
|
|
|
def test_next_recorded_in_session(self):
|
|
|
@@ -1273,7 +1275,7 @@ class SocialAuthExceptionMiddlewareTestCase(SimpleTestCase):
|
|
|
The raw exception text should never be surfaced to the user.
|
|
|
"""
|
|
|
request = self._make_request()
|
|
|
- exception = AuthFailed(self.FakeBackend(), 'raw internal SAML detail')
|
|
|
+ exception = AuthResponseError(self.FakeBackend(), 'raw internal SAML detail')
|
|
|
self.assertEqual(self.middleware.get_message(request, exception), self.GENERIC_MESSAGE)
|
|
|
|
|
|
def test_redirect_on_failure(self):
|
|
|
@@ -1281,7 +1283,7 @@ class SocialAuthExceptionMiddlewareTestCase(SimpleTestCase):
|
|
|
A SocialAuthBaseException should redirect to the login page with the generic message set.
|
|
|
"""
|
|
|
request = self._make_request()
|
|
|
- exception = AuthFailed(self.FakeBackend(), 'raw internal SAML detail')
|
|
|
+ exception = AuthResponseError(self.FakeBackend(), 'raw internal SAML detail')
|
|
|
response = self.middleware.process_exception(request, exception)
|
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|