diff --git a/lms/envs/common.py b/lms/envs/common.py index 917dd025e96f..09591a54c43f 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3172,3 +3172,14 @@ def _should_send_certificate_events(settings): SSL_AUTH_DN_FORMAT_STRING = ( "/C=US/ST=Massachusetts/O=Massachusetts Institute of Technology/OU=Client CA v1/CN={0}/emailAddress={1}" ) + +OPEN_EDX_FILTERS_CONFIG = { + "org.openedx.learning.logistration.context.requested.v1": { + "fail_silently": True, + "pipeline": ["enterprise.filters.logistration.LogistrationContextEnricher"], + }, + "org.openedx.learning.auth.post_login.redirect_url.requested.v1": { + "fail_silently": True, + "pipeline": ["enterprise.filters.logistration.PostLoginEnterpriseRedirect"], + }, +} diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 0dd9a4819d5e..5e89d47c8114 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -7,8 +7,6 @@ import hashlib import json import logging -import re -import urllib from django.conf import settings from django.contrib.auth import authenticate, get_user_model @@ -29,7 +27,7 @@ from eventtracking import tracker from openedx_events.learning.data import UserData, UserPersonalData from openedx_events.learning.signals import SESSION_LOGIN_COMPLETED -from openedx_filters.learning.filters import StudentLoginRequested +from openedx_filters.learning.filters import PostLoginRedirectURLRequested, StudentLoginRequested from rest_framework import status from rest_framework.views import APIView @@ -56,11 +54,10 @@ ) from openedx.core.djangoapps.user_authn.views.login_form import get_login_session_form from openedx.core.djangoapps.user_authn.views.password_reset import send_password_reset_email_for_user -from openedx.core.djangoapps.user_authn.views.utils import API_V1, ENTERPRISE_ENROLLMENT_URL_REGEX, UUID4_REGEX +from openedx.core.djangoapps.user_authn.views.utils import API_V1 from openedx.core.djangoapps.util.user_messages import PageLevelMessages from openedx.core.djangolib.markup import HTML, Text from openedx.core.lib.api.view_utils import require_post_params # lint-amnesty, pylint: disable=unused-import -from openedx.features.enterprise_support.api import activate_learner_enterprise, get_enterprise_learner_data_from_api log = logging.getLogger("edx.student") AUDIT_LOG = logging.getLogger("audit") @@ -478,35 +475,6 @@ def finish_auth(request): ) -def enterprise_selection_page(request, user, next_url): - """ - Updates redirect url to enterprise selection page if user is associated - with multiple enterprises otherwise return the next url. - - param: - next_url(string): The URL to redirect to after multiple enterprise selection or in case - the selection page is bypassed e.g when dealing with direct enrolment urls. - """ - redirect_url = next_url - - response = get_enterprise_learner_data_from_api(user) - if response and len(response) > 1: - redirect_url = reverse("enterprise_select_active") + "/?success_url=" + urllib.parse.quote(next_url) - - # Check to see if next url has an enterprise in it. In this case if user is associated with - # that enterprise, activate that enterprise and bypass the selection page. - if re.match(ENTERPRISE_ENROLLMENT_URL_REGEX, urllib.parse.unquote(next_url)): - enterprise_in_url = re.search(UUID4_REGEX, next_url).group(0) - for enterprise in response: - if enterprise_in_url == str(enterprise["enterprise_customer"]["uuid"]): - is_activated_successfully = activate_learner_enterprise(request, user, enterprise_in_url) - if is_activated_successfully: - redirect_url = next_url - break - - return redirect_url - - @ensure_csrf_cookie @require_http_methods(["POST"]) @ratelimit( @@ -649,7 +617,11 @@ def login_user(request, api_version="v1"): # pylint: disable=too-many-statement elif should_redirect_to_authn_microfrontend(): next_url, root_url = get_next_url_for_login_page(request, include_host=True) redirect_url = get_redirect_url_with_host( - root_url, enterprise_selection_page(request, possibly_authenticated_user, finish_auth_url or next_url) + root_url, PostLoginRedirectURLRequested.run_filter( + redirect_url='', + user=possibly_authenticated_user, + next_url=finish_auth_url or next_url, + ) or finish_auth_url or next_url ) if ( diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index bb78a9df1a3c..9cdfcb72cf54 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -13,9 +13,14 @@ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods from django_ratelimit.decorators import ratelimit +from openedx_filters.learning.filters import LogistrationContextRequested from common.djangoapps import third_party_auth from common.djangoapps.edxmako.shortcuts import render_to_response +from common.djangoapps.student.helpers import get_next_url_for_login_page +from common.djangoapps.third_party_auth import pipeline +from common.djangoapps.third_party_auth.decorators import xframe_allow_whitelisted +from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import accounts from openedx.core.djangoapps.user_api.accounts.utils import ( @@ -23,21 +28,13 @@ ) from openedx.core.djangoapps.user_api.helpers import FormDescription from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies -from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend +from openedx.core.djangoapps.user_authn.toggles import ( + is_require_third_party_auth_enabled, + should_redirect_to_authn_microfrontend, +) from openedx.core.djangoapps.user_authn.views.password_reset import get_password_reset_form from openedx.core.djangoapps.user_authn.views.registration_form import RegistrationFormFactory from openedx.core.djangoapps.user_authn.views.utils import third_party_auth_context -from openedx.core.djangoapps.user_authn.toggles import is_require_third_party_auth_enabled -from openedx.features.enterprise_support.api import enterprise_customer_for_request, enterprise_enabled -from openedx.features.enterprise_support.utils import ( - get_enterprise_slug_login_url, - handle_enterprise_cookies_for_logistration, - update_logistration_context_for_enterprise -) -from common.djangoapps.student.helpers import get_next_url_for_login_page -from common.djangoapps.third_party_auth import pipeline -from common.djangoapps.third_party_auth.decorators import xframe_allow_whitelisted -from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH log = logging.getLogger(__name__) @@ -56,22 +53,8 @@ def _apply_third_party_auth_overrides(request, form_desc): running_pipeline = third_party_auth.pipeline.get(request) if running_pipeline: current_provider = third_party_auth.provider.Registry.get_from_pipeline(running_pipeline) - if current_provider and enterprise_customer_for_request(request): - pipeline_kwargs = running_pipeline.get('kwargs') - - # Details about the user sent back from the provider. - details = pipeline_kwargs.get('details') - email = details.get('email', '') - - # override the email field. - form_desc.override_field_properties( - "email", - default=email, - restrictions={"readonly": "readonly"} if email else { - "min_length": accounts.EMAIL_MIN_LENGTH, - "max_length": accounts.EMAIL_MAX_LENGTH, - } - ) + if current_provider: + pass # SSO-specific form overrides are handled by filter pipeline steps. def get_login_session_form(request): @@ -200,12 +183,7 @@ def login_and_registration_form(request, initial_mode="login"): running_pipeline.get('backend'), running_pipeline.get('kwargs') ) - enterprise_customer = enterprise_customer_for_request(request) - - if should_redirect_to_authn_microfrontend() and \ - not enterprise_customer and \ - not tpa_hint_provider and \ - not saml_provider: + if should_redirect_to_authn_microfrontend() and not tpa_hint_provider and not saml_provider: # This is to handle a case where a logged-in cookie is not present but the user is authenticated. # Note: If we don't handle this learner is redirected to authn MFE and then back to dashboard @@ -260,8 +238,6 @@ def login_and_registration_form(request, initial_mode="login"): 'ALLOW_PUBLIC_ACCOUNT_CREATION', settings.FEATURES.get('ALLOW_PUBLIC_ACCOUNT_CREATION', True)), 'register_links_allowed': settings.FEATURES.get('SHOW_REGISTRATION_LINKS', True), 'is_account_recovery_feature_enabled': is_secondary_email_feature_enabled(), - 'enterprise_slug_login_url': get_enterprise_slug_login_url(), - 'is_enterprise_enable': enterprise_enabled(), 'is_require_third_party_auth_enabled': is_require_third_party_auth_enabled(), 'enable_coppa_compliance': settings.ENABLE_COPPA_COMPLIANCE, 'edx_user_info_cookie_name': settings.EDXMKTG_USER_INFO_COOKIE_NAME, @@ -277,11 +253,8 @@ def login_and_registration_form(request, initial_mode="login"): ), } - update_logistration_context_for_enterprise(request, context, enterprise_customer) - + context, _ = LogistrationContextRequested.run_filter(context=context, request=request) response = render_to_response('student_account/login_and_register.html', context) - handle_enterprise_cookies_for_logistration(request, response, context) - return response diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index c8bfa082900b..470d288af741 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -7,7 +7,6 @@ import hashlib import json import unicodedata -import urllib.parse from unittest.mock import Mock, patch import ddt @@ -41,7 +40,6 @@ from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.api.test_utils import ApiTestCase -from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory from common.djangoapps.student.models import LoginFailures from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH from common.test.utils import assert_dict_contains_subset @@ -218,113 +216,6 @@ def test_login_success_with_redirect(self, next_url, course_id, expected_redirec self._assert_response(response, success=True) self._assert_redirect_url(response, expected_redirect) - @ddt.data(('/dashboard', False), ('/enterprise/select/active/?success_url=/dashboard', True)) - @ddt.unpack - @patch.dict(settings.FEATURES, {'ENABLE_AUTHN_MICROFRONTEND': True, 'ENABLE_ENTERPRISE_INTEGRATION': True}) - @override_settings(LOGIN_REDIRECT_WHITELIST=['openedx.service']) - @patch('openedx.features.enterprise_support.api.EnterpriseApiClient') - @patch('openedx.core.djangoapps.user_authn.views.login.reverse') - @skip_unless_lms - def test_login_success_for_multiple_enterprises( - self, expected_redirect, user_has_multiple_enterprises, reverse_mock, mock_api_client_class - ): - """ - Test that if multiple enterprise feature is enabled, user is redirected - to correct page - """ - api_response = {'results': []} - enterprise = EnterpriseCustomerUserFactory(user_id=self.user.id).enterprise_customer - api_response['results'].append( - { - "enterprise_customer": { - "uuid": enterprise.uuid, - "name": enterprise.name, - "active": enterprise.active, - } - } - ) - - if user_has_multiple_enterprises: - enterprise = EnterpriseCustomerUserFactory(user_id=self.user.id).enterprise_customer - api_response['results'].append( - { - "enterprise_customer": { - "uuid": enterprise.uuid, - "name": enterprise.name, - "active": enterprise.active, - } - } - ) - - mock_client = mock_api_client_class.return_value - mock_client.fetch_enterprise_learner_data.return_value = api_response - reverse_mock.return_value = '/enterprise/select/active' - - response, _ = self._login_response( - self.user.email, - self.password, - HTTP_ACCEPT='*/*', - ) - self._assert_response(response, success=True) - self._assert_redirect_url(response, settings.LMS_ROOT_URL + expected_redirect) - - @ddt.data(('', True), ('/enterprise/select/active/?success_url=', False)) - @ddt.unpack - @patch.dict(settings.FEATURES, {'ENABLE_AUTHN_MICROFRONTEND': True, 'ENABLE_ENTERPRISE_INTEGRATION': True}) - @patch('openedx.features.enterprise_support.api.EnterpriseApiClient') - @patch('openedx.core.djangoapps.user_authn.views.login.activate_learner_enterprise') - @patch('openedx.core.djangoapps.user_authn.views.login.reverse') - @skip_unless_lms - def test_enterprise_in_url( - self, expected_redirect, is_activated, reverse_mock, mock_activate_learner_enterprise, mock_api_client_class - ): - """ - If user has multiple enterprises and the enterprise is present in url, - activate that url - """ - api_response = {} - enterprise_1 = EnterpriseCustomerUserFactory(user_id=self.user.id).enterprise_customer - enterprise_2 = EnterpriseCustomerUserFactory(user_id=self.user.id).enterprise_customer - api_response['results'] = [ - { - "enterprise_customer": { - "uuid": enterprise_1.uuid, - "name": enterprise_1.name, - "active": enterprise_1.active, - } - }, - { - "enterprise_customer": { - "uuid": enterprise_2.uuid, - "name": enterprise_2.name, - "active": enterprise_2.active, - } - } - ] - - next_url = '/enterprise/{}/course/{}/enroll/?catalog=catalog_uuid&utm_medium=enterprise'.format( - enterprise_1.uuid, - 'course-v1:testX+test101+2T2020' - ) - - mock_client = mock_api_client_class.return_value - mock_client.fetch_enterprise_learner_data.return_value = api_response - mock_activate_learner_enterprise.return_value = is_activated - reverse_mock.return_value = '/enterprise/select/active' - - response, _ = self._login_response( - self.user.email, - self.password, - extra_post_params={'next': next_url}, - HTTP_ACCEPT='*/*', - ) - - if not is_activated: - next_url = urllib.parse.quote(next_url) - - self._assert_response(response, success=True) - self._assert_redirect_url(response, settings.LMS_ROOT_URL + expected_redirect + next_url) - @patch.dict("django.conf.settings.FEATURES", {'SQUELCH_PII_IN_LOGS': True}) def test_login_success_no_pii(self): response, mock_audit_log = self._login_response( diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py index 3f67191ae982..ab075b7fd0c7 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py @@ -1,32 +1,22 @@ """ Tests for Logistration views. """ -from http.cookies import SimpleCookie from urllib.parse import urlencode from unittest import mock import ddt from django.conf import settings -from django.contrib import messages -from django.contrib.auth.models import AnonymousUser -from django.contrib.messages.middleware import MessageMiddleware -from django.contrib.sessions.middleware import SessionMiddleware from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase -from django.test.client import RequestFactory from django.test.utils import override_settings from django.urls import reverse -from django.utils.translation import gettext as _ from common.djangoapps.course_modes.models import CourseMode -from lms.djangoapps.branding.api import get_privacy_url from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context from openedx.core.djangoapps.user_authn.cookies import JWT_COOKIE_NAMES from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client -from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form from openedx.core.djangolib.js_utils import dump_js_escaped_json -from openedx.core.djangolib.markup import HTML, Text from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.third_party_auth.tests.testutil import ThirdPartyAuthTestMixin, simulate_running_pipeline from common.djangoapps.util.testing import UrlResetMixin @@ -191,29 +181,17 @@ def test_login_and_registration_form_signin_not_preserves_params(self, theme, ur @ddt.data("signin_user", "register_user") def test_third_party_auth_disabled(self, url_name): response = self.client.get(reverse(url_name)) - self._assert_third_party_auth_data(response, None, None, [], None) + self._assert_third_party_auth_data(response, None, None, []) - @mock.patch('openedx.core.djangoapps.user_authn.views.login_form.enterprise_customer_for_request') @ddt.data( - ("signin_user", None, None, None, False), - ("register_user", None, None, None, False), - ("signin_user", "google-oauth2", "Google", None, False), - ("register_user", "google-oauth2", "Google", None, False), - ("signin_user", "facebook", "Facebook", None, False), - ("register_user", "facebook", "Facebook", None, False), - ("signin_user", "dummy", "Dummy", None, False), - ("register_user", "dummy", "Dummy", None, False), - ( - "signin_user", - "google-oauth2", - "Google", - { - 'name': 'FakeName', - 'logo': 'https://host.com/logo.jpg', - 'welcome_msg': 'No message' - }, - True - ) + ("signin_user", None, None), + ("register_user", None, None), + ("signin_user", "google-oauth2", "Google"), + ("register_user", "google-oauth2", "Google"), + ("signin_user", "facebook", "Facebook"), + ("register_user", "facebook", "Facebook"), + ("signin_user", "dummy", "Dummy"), + ("register_user", "dummy", "Dummy"), ) @ddt.unpack def test_third_party_auth( @@ -221,9 +199,6 @@ def test_third_party_auth( url_name, current_backend, current_provider, - expected_enterprise_customer_mock_attrs, - add_user_details, - enterprise_customer_mock, ): params = [ ('course_id', 'course-v1:Org+Course+Run'), @@ -233,26 +208,10 @@ def test_third_party_auth( ('next', '/custom/final/destination'), ] - if expected_enterprise_customer_mock_attrs: - expected_ec = { - 'name': expected_enterprise_customer_mock_attrs['name'], - 'branding_configuration': { - 'logo': 'https://host.com/logo.jpg', - 'welcome_message': expected_enterprise_customer_mock_attrs['welcome_msg'] - } - } - else: - expected_ec = None - - email = None - if add_user_details: - email = 'test@test.com' - enterprise_customer_mock.return_value = expected_ec - # Simulate a running pipeline if current_backend is not None: pipeline_target = "openedx.core.djangoapps.user_authn.views.login_form.third_party_auth.pipeline" - with simulate_running_pipeline(pipeline_target, current_backend, email=email): + with simulate_running_pipeline(pipeline_target, current_backend): response = self.client.get(reverse(url_name), params, HTTP_ACCEPT="text/html") # Do NOT simulate a running pipeline @@ -297,91 +256,6 @@ def test_third_party_auth( current_backend, current_provider, expected_providers, - expected_ec, - add_user_details - ) - - def _configure_testshib_provider(self, provider_name, idp_slug): - """ - Enable and configure the TestShib SAML IdP as a third_party_auth provider. - """ - kwargs = {} - kwargs.setdefault('name', provider_name) - kwargs.setdefault('enabled', True) - kwargs.setdefault('visible', True) - kwargs.setdefault('slug', idp_slug) - kwargs.setdefault('entity_id', 'https://idp.testshib.org/idp/shibboleth') - kwargs.setdefault('metadata_source', 'https://mock.testshib.org/metadata/testshib-providers.xml') - kwargs.setdefault('icon_class', 'fa-university') - kwargs.setdefault('attr_email', 'dummy-email-attr') - kwargs.setdefault('max_session_length', None) - kwargs.setdefault('skip_registration_form', False) - self.configure_saml_provider(**kwargs) - - @mock.patch('django.conf.settings.MESSAGE_STORAGE', 'django.contrib.messages.storage.cookie.CookieStorage') - @mock.patch('openedx.core.djangoapps.user_authn.views.login_form.enterprise_customer_for_request') - @ddt.data( - ( - 'signin_user', - 'tpa-saml', - 'TestShib', - ) - ) - @ddt.unpack - def test_saml_auth_with_error( - self, - url_name, - current_backend, - current_provider, - enterprise_customer_mock, - ): - params = [] - request = RequestFactory().get(reverse(url_name), params, HTTP_ACCEPT='text/html') - SessionMiddleware(get_response=lambda request: None).process_request(request) - request.user = AnonymousUser() - - self.enable_saml() - dummy_idp = 'testshib' - self._configure_testshib_provider(current_provider, dummy_idp) - enterprise_customer_data = { - 'uuid': '72416e52-8c77-4860-9584-15e5b06220fb', - 'name': 'Dummy Enterprise', - 'identity_provider': dummy_idp, - } - enterprise_customer_mock.return_value = enterprise_customer_data - dummy_error_message = 'Authentication failed: SAML login failed ' \ - '["invalid_response"] [SAML Response must contain 1 assertion]' - - # Add error message for error in auth pipeline - MessageMiddleware(get_response=lambda request: None).process_request(request) - messages.error(request, dummy_error_message, extra_tags='social-auth') - - # Simulate a running pipeline - pipeline_response = { - 'response': { - 'idp_name': dummy_idp - } - } - pipeline_target = 'openedx.core.djangoapps.user_authn.views.login_form.third_party_auth.pipeline' - with simulate_running_pipeline(pipeline_target, current_backend, **pipeline_response): - with mock.patch('common.djangoapps.edxmako.request_context.get_current_request', return_value=request): - response = login_and_registration_form(request) - - expected_error_message = Text(_( - 'We are sorry, you are not authorized to access {platform_name} via this channel. ' - 'Please contact your learning administrator or manager in order to access {platform_name}.' - '{line_break}{line_break}' - 'Error Details:{line_break}{error_message}') - ).format( - platform_name=settings.PLATFORM_NAME, - error_message=dummy_error_message, - line_break=HTML('
') - ) - self._assert_saml_auth_data_with_error( - response, - current_backend, - current_provider, - expected_error_message ) def test_hinted_login(self): @@ -463,79 +337,6 @@ def test_settings_tpa_hinted_login_dialog_disabled(self, url_name, auth_entry): target_status_code=302 ) - @mock.patch('openedx.core.djangoapps.user_authn.views.login_form.enterprise_customer_for_request') - @ddt.data( - ('signin_user', False, None, None, False), - ('register_user', False, None, None, False), - ('signin_user', True, 'Fake EC', 'http://logo.com/logo.jpg', False), - ('register_user', True, 'Fake EC', 'http://logo.com/logo.jpg', False), - ('signin_user', True, 'Fake EC', 'http://logo.com/logo.jpg', True), - ('register_user', True, 'Fake EC', 'http://logo.com/logo.jpg', True), - ('signin_user', True, 'Fake EC', None, False), - ('register_user', True, 'Fake EC', None, False), - ) - @ddt.unpack - def test_enterprise_register(self, url_name, ec_present, ec_name, logo_url, is_proxy, mock_get_ec): - """ - Verify that when an EnterpriseCustomer is received on the login and register views, - the appropriate sidebar is rendered. - """ - if ec_present: - mock_get_ec.return_value = { - 'name': ec_name, - 'branding_configuration': {'logo': logo_url} - } - else: - mock_get_ec.return_value = None - - params = [] - if is_proxy: - params.append(("proxy_login", "True")) - - response = self.client.get(reverse(url_name), params, HTTP_ACCEPT="text/html") - - enterprise_sidebar_div_id = 'enterprise-content-container' - - if not ec_present: - self.assertNotContains(response, text=enterprise_sidebar_div_id) - else: - self.assertContains(response, text=enterprise_sidebar_div_id) - if is_proxy: - welcome_message = settings.ENTERPRISE_PROXY_LOGIN_WELCOME_TEMPLATE - else: - welcome_message = settings.ENTERPRISE_SPECIFIC_BRANDED_WELCOME_TEMPLATE - expected_message = Text(welcome_message).format( - start_bold=HTML(''), - end_bold=HTML(''), - line_break=HTML('
'), - enterprise_name=ec_name, - platform_name=settings.PLATFORM_NAME, - privacy_policy_link_start=HTML("").format( - pp_url=get_privacy_url() - ), - privacy_policy_link_end=HTML(""), - ) - self.assertContains(response, expected_message) - if logo_url: - self.assertContains(response, logo_url) - - def test_enterprise_cookie_delete(self): - """ - Test that enterprise cookies are deleted in login/registration views. - - Cookies must be deleted in login/registration views so that *default* login/registration branding - is displayed to subsequent requests from non-enterprise customers. - """ - cookies = SimpleCookie() - cookies[settings.ENTERPRISE_CUSTOMER_COOKIE_NAME] = 'test-enterprise-customer' - response = self.client.get(reverse('signin_user'), HTTP_ACCEPT="text/html", cookies=cookies) - - assert settings.ENTERPRISE_CUSTOMER_COOKIE_NAME in response.cookies - enterprise_cookie = response.cookies[settings.ENTERPRISE_CUSTOMER_COOKIE_NAME] - - assert enterprise_cookie['domain'] == settings.BASE_COOKIE_DOMAIN - assert enterprise_cookie.value == '' - def test_login_registration_xframe_protected(self): resp = self.client.get( reverse("register_user"), @@ -554,8 +355,7 @@ def test_login_registration_xframe_protected(self): assert resp['X-Frame-Options'] == 'ALLOW' - def _assert_third_party_auth_data(self, response, current_backend, current_provider, providers, expected_ec, - add_user_details=False): + def _assert_third_party_auth_data(self, response, current_backend, current_provider, providers): """Verify that third party auth info is rendered correctly in a DOM data attribute. """ finish_auth_url = None if current_backend: @@ -569,41 +369,9 @@ def _assert_third_party_auth_data(self, response, current_backend, current_provi "errorMessage": None, "registerFormSubmitButtonText": "Create Account", "syncLearnerProfileData": False, - "pipeline_user_details": {"email": "test@test.com"} if add_user_details else {}, + "pipeline_user_details": {}, "skipRegistrationOptionalCheckboxes": False } - if expected_ec is not None: - # If we set an EnterpriseCustomer, third-party auth providers ought to be hidden. - auth_info['providers'] = [] - auth_info = dump_js_escaped_json(auth_info) - - expected_data = '"third_party_auth": {auth_info}'.format( - auth_info=auth_info - ) - self.assertContains(response, expected_data) - - def _assert_saml_auth_data_with_error( - self, response, current_backend, current_provider, expected_error_message - ): - """ - Verify that third party auth info is rendered correctly in a DOM data attribute. - """ - finish_auth_url = None - if current_backend: - finish_auth_url = reverse('social:complete', kwargs={'backend': current_backend}) + '?' - - auth_info = { - 'currentProvider': current_provider, - 'platformName': settings.PLATFORM_NAME, - 'providers': [], - 'secondaryProviders': [], - 'finishAuthUrl': finish_auth_url, - 'errorMessage': expected_error_message, - 'registerFormSubmitButtonText': 'Create Account', - 'syncLearnerProfileData': False, - 'pipeline_user_details': {'response': {'idp_name': 'testshib'}}, - 'skipRegistrationOptionalCheckboxes': False - } auth_info = dump_js_escaped_json(auth_info) expected_data = '"third_party_auth": {auth_info}'.format(