def test_get_enterprise_customer_logo_url_return_none_when_param_missing(self): """ Test get_enterprise_customer_logo_url return 'None' when filter parameters are missing. """ request = mock.MagicMock(session={}) branding_info = mock.Mock() set_enterprise_branding_filter_param(request, provider_id=None) with mock.patch("enterprise.api.get_enterprise_branding_info_by_provider_id", return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, None)
def test_get_enterprise_customer_logo_url_return_none(self): """ Test get_enterprise_customer_logo_url return 'None' when enterprise application is not installed. """ request = mock.MagicMock(session={}) branding_info = mock.Mock() set_enterprise_branding_filter_param(request, "test-idp") with mock.patch("enterprise.api.get_enterprise_branding_info_by_provider_id", return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, None)
def test_get_enterprise_customer_logo_url_return_none(self): """ Test get_enterprise_customer_logo_url return 'None' when enterprise application is not installed. """ request = mock.MagicMock(session={}) branding_info = mock.Mock() set_enterprise_branding_filter_param(request, 'test-idp') with mock.patch( 'enterprise.utils.get_enterprise_branding_info_by_provider_id', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, None)
def test_set_enterprise_branding_filter_param(self): """ Test that the enterprise customer branding parameters are setting correctly. """ ec_uuid = "97b4a894-cea9-4103-8f9f-2c5c95a58ba3" provider_id = "test-provider-idp" request = mock.MagicMock(session={}, GET={"ec_src": ec_uuid}) set_enterprise_branding_filter_param(request, provider_id=None) self.assertEqual(get_enterprise_branding_filter_param(request), {"ec_uuid": ec_uuid}) set_enterprise_branding_filter_param(request, provider_id=provider_id) self.assertEqual(get_enterprise_branding_filter_param(request), {"provider_id": provider_id})
def test_get_enterprise_customer_logo_url_return_none_when_param_missing( self): """ Test get_enterprise_customer_logo_url return 'None' when filter parameters are missing. """ request = mock.MagicMock(session={}) branding_info = mock.Mock() set_enterprise_branding_filter_param(request, provider_id=None) with mock.patch( 'enterprise.utils.get_enterprise_branding_info_by_provider_id', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, None)
def test_set_enterprise_branding_filter_param(self): """ Test that the enterprise customer branding parameters are setting correctly. """ ec_uuid = '97b4a894-cea9-4103-8f9f-2c5c95a58ba3' provider_id = 'test-provider-idp' request = mock.MagicMock(session={}, GET={'ec_src': ec_uuid}) set_enterprise_branding_filter_param(request, provider_id=None) self.assertEqual(get_enterprise_branding_filter_param(request), {'ec_uuid': ec_uuid}) set_enterprise_branding_filter_param(request, provider_id=provider_id) self.assertEqual(get_enterprise_branding_filter_param(request), {'provider_id': provider_id})
def test_get_enterprise_customer_logo_url(self): """ Test test_get_enterprise_customer_logo_url return the logo url as desired. """ ec_uuid = "97b4a894-cea9-4103-8f9f-2c5c95a58ba3" provider_id = "test-provider-idp" request = mock.MagicMock(session={}, GET={"ec_src": ec_uuid}) branding_info = mock.Mock(logo=mock.Mock(url="/test/image.png")) set_enterprise_branding_filter_param(request, provider_id=None) with mock.patch("enterprise.api.get_enterprise_branding_info_by_ec_uuid", return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, "/test/image.png") set_enterprise_branding_filter_param(request, provider_id) with mock.patch("enterprise.api.get_enterprise_branding_info_by_provider_id", return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, "/test/image.png")
def test_get_enterprise_customer_logo_url(self): """ Test test_get_enterprise_customer_logo_url return the logo url as desired. """ ec_uuid = '97b4a894-cea9-4103-8f9f-2c5c95a58ba3' provider_id = 'test-provider-idp' request = mock.MagicMock(session={}, GET={'ec_src': ec_uuid}) branding_info = mock.Mock(logo=mock.Mock(url='/test/image.png')) set_enterprise_branding_filter_param(request, provider_id=None) with mock.patch( 'enterprise.utils.get_enterprise_branding_info_by_ec_uuid', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, '/test/image.png') set_enterprise_branding_filter_param(request, provider_id) with mock.patch( 'enterprise.utils.get_enterprise_branding_info_by_provider_id', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, '/test/image.png')
def test_get_enterprise_customer_logo_url(self): """ Test test_get_enterprise_customer_logo_url return the logo url as desired. """ ec_uuid = '97b4a894-cea9-4103-8f9f-2c5c95a58ba3' provider_id = 'test-provider-idp' request = mock.MagicMock(session={}, GET={'ec_src': ec_uuid}) branding_info = mock.Mock( logo=mock.Mock( url='/test/image.png' ) ) set_enterprise_branding_filter_param(request, provider_id=None) with mock.patch('enterprise.utils.get_enterprise_branding_info_by_ec_uuid', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, '/test/image.png') set_enterprise_branding_filter_param(request, provider_id) with mock.patch('enterprise.utils.get_enterprise_branding_info_by_provider_id', return_value=branding_info): logo_url = get_enterprise_customer_logo_url(request) self.assertEqual(logo_url, '/test/image.png')
def login_and_registration_form(request, initial_mode="login"): """Render the combined login/registration form, defaulting to login This relies on the JS to asynchronously load the actual form from the user_api. Keyword Args: initial_mode (string): Either "login" or "register". """ # Determine the URL to redirect to following login/registration/third_party_auth redirect_to = get_next_url_for_login_page(request) # If we're already logged in, redirect to the dashboard if request.user.is_authenticated(): return redirect(redirect_to) # Retrieve the form descriptions from the user API form_descriptions = _get_form_descriptions(request) # Our ?next= URL may itself contain a parameter 'tpa_hint=x' that we need to check. # If present, we display a login page focused on third-party auth with that provider. third_party_auth_hint = None if '?' in redirect_to: try: next_args = urlparse.parse_qs(urlparse.urlparse(redirect_to).query) provider_id = next_args['tpa_hint'][0] if third_party_auth.provider.Registry.get(provider_id=provider_id): third_party_auth_hint = provider_id initial_mode = "hinted_login" except (KeyError, ValueError, IndexError): pass set_enterprise_branding_filter_param(request=request, provider_id=third_party_auth_hint) # If this is a themed site, revert to the old login/registration pages. # We need to do this for now to support existing themes. # Themed sites can use the new logistration page by setting # 'ENABLE_COMBINED_LOGIN_REGISTRATION' in their # configuration settings. if is_request_in_themed_site() and not configuration_helpers.get_value( 'ENABLE_COMBINED_LOGIN_REGISTRATION', False): if initial_mode == "login": return old_login_view(request) elif initial_mode == "register": return old_register_view(request) # Allow external auth to intercept and handle the request ext_auth_response = _external_auth_intercept(request, initial_mode) if ext_auth_response is not None: return ext_auth_response # Otherwise, render the combined login/registration page context = { 'data': { 'login_redirect_url': redirect_to, 'initial_mode': initial_mode, 'third_party_auth': _third_party_auth_context(request, redirect_to), 'third_party_auth_hint': third_party_auth_hint or '', 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'support_link': configuration_helpers.get_value('SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK), # Include form descriptions retrieved from the user API. # We could have the JS client make these requests directly, # but we include them in the initial page load to avoid # the additional round-trip to the server. 'login_form_desc': json.loads(form_descriptions['login']), 'registration_form_desc': json.loads(form_descriptions['registration']), 'password_reset_form_desc': json.loads(form_descriptions['password_reset']), }, 'login_redirect_url': redirect_to, # This gets added to the query string of the "Sign In" button in header 'responsive': True, 'allow_iframing': True, 'disable_courseware_js': True, 'disable_footer': not configuration_helpers.get_value( 'ENABLE_COMBINED_LOGIN_REGISTRATION_FOOTER', settings.FEATURES['ENABLE_COMBINED_LOGIN_REGISTRATION_FOOTER']), } return render_to_response('student_account/login_and_register.html', context)
def login_and_registration_form(request, initial_mode="login"): """Render the combined login/registration form, defaulting to login This relies on the JS to asynchronously load the actual form from the user_api. Keyword Args: initial_mode (string): Either "login" or "register". """ # Determine the URL to redirect to following login/registration/third_party_auth redirect_to = get_next_url_for_login_page(request) # If we're already logged in, redirect to the dashboard if UserProfile.has_registered(request.user): return redirect(redirect_to) if third_party_auth.is_enabled(): force_provider_id = settings.FORCED_TPA_PROVIDER_ID if force_provider_id: force_provider = third_party_auth.provider.Registry.get( provider_id=force_provider_id, ) if force_provider and force_provider.display_for_login: running_pipeline = third_party_auth.pipeline.get(request) if not running_pipeline: if initial_mode in [pipeline.AUTH_ENTRY_LOGIN, pipeline.AUTH_ENTRY_REGISTER]: tpa_url = pipeline.get_login_url( force_provider_id, initial_mode, redirect_url=redirect_to, ) return redirect(tpa_url) # Retrieve the form descriptions from the user API form_descriptions = _get_form_descriptions(request) # Our ?next= URL may itself contain a parameter 'tpa_hint=x' that we need to check. # If present, we display a login page focused on third-party auth with that provider. third_party_auth_hint = None if '?' in redirect_to: try: next_args = urlparse.parse_qs(urlparse.urlparse(redirect_to).query) provider_id = next_args['tpa_hint'][0] if third_party_auth.provider.Registry.get(provider_id=provider_id): third_party_auth_hint = provider_id initial_mode = "hinted_login" except (KeyError, ValueError, IndexError): pass set_enterprise_branding_filter_param(request=request, provider_id=third_party_auth_hint) # If this is a themed site, revert to the old login/registration pages. # We need to do this for now to support existing themes. # Themed sites can use the new logistration page by setting # 'ENABLE_COMBINED_LOGIN_REGISTRATION' in their # configuration settings. if is_request_in_themed_site() and not configuration_helpers.get_value('ENABLE_COMBINED_LOGIN_REGISTRATION', False): if initial_mode == "login": return old_login_view(request) elif initial_mode == "register": return old_register_view(request) # Allow external auth to intercept and handle the request ext_auth_response = _external_auth_intercept(request, initial_mode) if ext_auth_response is not None: return ext_auth_response # Otherwise, render the combined login/registration page context = { 'data': { 'login_redirect_url': redirect_to, 'initial_mode': initial_mode, 'third_party_auth': _third_party_auth_context(request, redirect_to), 'third_party_auth_hint': third_party_auth_hint or '', 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'support_link': configuration_helpers.get_value('SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK), 'privacy_policy_url': marketing_link('PRIVACY'), # Include form descriptions retrieved from the user API. # We could have the JS client make these requests directly, # but we include them in the initial page load to avoid # the additional round-trip to the server. 'login_form_desc': json.loads(form_descriptions['login']), 'registration_form_desc': json.loads(form_descriptions['registration']), 'password_reset_form_desc': json.loads(form_descriptions['password_reset']), }, 'login_redirect_url': redirect_to, # This gets added to the query string of the "Sign In" button in header 'responsive': True, 'allow_iframing': True, 'disable_courseware_js': True, 'disable_footer': not configuration_helpers.get_value( 'ENABLE_COMBINED_LOGIN_REGISTRATION_FOOTER', settings.FEATURES['ENABLE_COMBINED_LOGIN_REGISTRATION_FOOTER'] ), } return render_to_response('student_account/login_and_register.html', context)