Skip to content
Snippets Groups Projects
Commit 60ce8037 authored by zia.fazal@arbisoft.com's avatar zia.fazal@arbisoft.com
Browse files

Added link to error message displayed when TPA only user login from FPA login page

Added link to error message displayed when TPA only user login from FPA login page.
ENT-2535

Fixed pep8 quality violation

skip unit test if context is not LMS
parent 6349606b
No related merge requests found
......@@ -16,6 +16,7 @@ from django.contrib.auth import login as django_login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpRequest, HttpResponse
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt, csrf_protect, ensure_csrf_cookie
......@@ -292,11 +293,19 @@ def _check_user_auth_flow(site, user):
# If user belongs to allowed domain and not whitelisted then user must login through allowed domain SSO
if user_domain == allowed_domain and not AllowedAuthUser.objects.filter(site=site, email=user.email).exists():
msg = _(
u'As an {allowed_domain} user, You must login with your {allowed_domain} {provider} account.'
).format(
msg = Text(_(
u'As {allowed_domain} user, You must login with your {allowed_domain} '
u'{link_start}{provider} account{link_end}.'
)).format(
allowed_domain=allowed_domain,
provider=site.configuration.get_value('THIRD_PARTY_AUTH_ONLY_PROVIDER')
link_start=HTML("<a href='{tpa_provider_link}'>").format(
tpa_provider_link='{dashboard_url}?tpa_hint={tpa_hint}'.format(
dashboard_url=reverse('dashboard'),
tpa_hint=site.configuration.get_value('THIRD_PARTY_AUTH_HINT'),
)
),
provider=site.configuration.get_value('THIRD_PARTY_AUTH_ONLY_PROVIDER'),
link_end=HTML("</a>")
)
raise AuthFailedError(msg)
......
......@@ -616,6 +616,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
},
)
@ddt.unpack
@skip_unless_lms
def test_login_for_user_auth_flow(
self,
switch_enabled,
......@@ -629,6 +630,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
Verify that `login._check_user_auth_flow` works as expected.
"""
provider = 'Google'
provider_tpa_hint = 'saml-test'
username = 'batman'
user_email = '{username}@{domain}'.format(username=username, domain=user_domain)
user = self._create_user(username, user_email)
......@@ -636,6 +638,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
'SITE_NAME': allowed_domain,
'THIRD_PARTY_AUTH_ONLY_DOMAIN': allowed_domain,
'THIRD_PARTY_AUTH_ONLY_PROVIDER': provider,
'THIRD_PARTY_AUTH_HINT': provider_tpa_hint,
}
with ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY.override(switch_enabled):
......@@ -647,10 +650,14 @@ class LoginTest(SiteMixin, CacheIsolationTestCase):
else:
AllowedAuthUser.objects.filter(site=site, email=user.email).delete()
value = None if success else u'As an {0} user, You must login with your {0} {1} account.'.format(
allowed_domain,
provider
)
if success:
value = None
else:
value = u'As {0} user, You must login with your {0} <a href=\'{1}\'>{2} account</a>.'.format(
allowed_domain,
'{}?tpa_hint={}'.format(reverse("dashboard"), provider_tpa_hint),
provider,
)
response, __ = self._login_response(user.email, self.password)
self._assert_response(
response,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment