Merge pull request #22452 from edx/robrap/ARCH-1253-login-cleanup-part-2
ARCH-1253: return json for third party auth failure
This commit is contained in:
@@ -365,7 +365,11 @@ def login_user(request):
|
||||
except AuthFailedError as e:
|
||||
set_custom_metric('login_user_tpa_success', False)
|
||||
set_custom_metric('login_user_tpa_failure_msg', e.value)
|
||||
return HttpResponse(e.value, content_type="text/plain", status=403)
|
||||
|
||||
# user successfully authenticated with a third party provider, but has no linked Open edX account
|
||||
response_content = e.get_response()
|
||||
response_content['error_code'] = 'third-party-auth-with-no-linked-account'
|
||||
return JsonResponse(response_content, status=403)
|
||||
else:
|
||||
user = _get_user_by_email(request)
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_un
|
||||
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
|
||||
from openedx.core.lib.api.test_utils import ApiTestCase
|
||||
from student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory
|
||||
from util.json_request import JsonResponse
|
||||
from util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH
|
||||
|
||||
|
||||
@@ -818,8 +819,13 @@ class StudentViewShimTest(TestCase):
|
||||
self.captured_request = None
|
||||
|
||||
def test_third_party_auth_login_failure(self):
|
||||
mocked_response_content = {
|
||||
"success": False,
|
||||
"error_code": "third-party-auth-with-no-linked-account",
|
||||
"value": "Test message."
|
||||
}
|
||||
view = self._shimmed_view(
|
||||
HttpResponse(status=403),
|
||||
JsonResponse(mocked_response_content, status=403),
|
||||
check_logged_in=True
|
||||
)
|
||||
response = view(HttpRequest())
|
||||
|
||||
Reference in New Issue
Block a user