This reverts commit 08f5e7e563.
This commit is contained in:
committed by
GitHub
parent
08f5e7e563
commit
caf8e456e2
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Test that various filters are fired for models/views in the student app.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
from django.test import override_settings
|
||||
from django.urls import reverse
|
||||
@@ -422,7 +421,7 @@ class StudentDashboardFiltersTest(ModuleStoreTestCase):
|
||||
response = self.client.get(self.dashboard_url)
|
||||
|
||||
self.assertEqual(status.HTTP_302_FOUND, response.status_code)
|
||||
self.assertEqual(settings.ACCOUNT_MICROFRONTEND_URL, response.url)
|
||||
self.assertEqual(reverse("account_settings"), response.url)
|
||||
|
||||
@override_settings(
|
||||
OPEN_EDX_FILTERS_CONFIG={
|
||||
|
||||
@@ -233,7 +233,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
|
||||
"""
|
||||
UserProfile.objects.get(user=self.user).delete()
|
||||
response = self.client.get(self.path)
|
||||
self.assertRedirects(response, settings.ACCOUNT_MICROFRONTEND_URL, target_status_code=302)
|
||||
self.assertRedirects(response, reverse('account_settings'))
|
||||
|
||||
@patch('common.djangoapps.student.views.dashboard.should_redirect_to_learner_home_mfe')
|
||||
def test_redirect_to_learner_home(self, mock_should_redirect_to_learner_home_mfe):
|
||||
|
||||
@@ -519,7 +519,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
"""
|
||||
user = request.user
|
||||
if not UserProfile.objects.filter(user=user).exists():
|
||||
return redirect(settings.ACCOUNT_MICROFRONTEND_URL)
|
||||
return redirect(reverse('account_settings'))
|
||||
|
||||
if should_redirect_to_learner_home_mfe(user):
|
||||
return redirect(settings.LEARNER_HOME_MICROFRONTEND_URL)
|
||||
@@ -624,7 +624,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
"Go to {link_start}your Account Settings{link_end}.")
|
||||
).format(
|
||||
link_start=HTML("<a href='{account_setting_page}'>").format(
|
||||
account_setting_page=settings.ACCOUNT_MICROFRONTEND_URL,
|
||||
account_setting_page=reverse('account_settings'),
|
||||
),
|
||||
link_end=HTML("</a>")
|
||||
)
|
||||
@@ -897,7 +897,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
except DashboardRenderStarted.RenderInvalidDashboard as exc:
|
||||
response = render_to_response(exc.dashboard_template, exc.template_context)
|
||||
except DashboardRenderStarted.RedirectToPage as exc:
|
||||
response = HttpResponseRedirect(exc.redirect_to or settings.ACCOUNT_MICROFRONTEND_URL)
|
||||
response = HttpResponseRedirect(exc.redirect_to or reverse('account_settings'))
|
||||
except DashboardRenderStarted.RenderCustomResponse as exc:
|
||||
response = exc.response
|
||||
else:
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
Tests for the Third Party Auth REST API
|
||||
"""
|
||||
|
||||
import urllib
|
||||
from unittest.mock import patch
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
import six
|
||||
from django.http import QueryDict
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
@@ -220,7 +219,7 @@ class UserViewV2APITests(UserViewsMixin, TpaAPITestCase):
|
||||
"""
|
||||
return '?'.join([
|
||||
reverse('third_party_auth_users_api_v2'),
|
||||
urllib.parse.urlencode(identifier)
|
||||
six.moves.urllib.parse.urlencode(identifier)
|
||||
])
|
||||
|
||||
|
||||
@@ -378,12 +377,11 @@ class TestThirdPartyAuthUserStatusView(ThirdPartyAuthTestMixin, APITestCase):
|
||||
"""
|
||||
self.client.login(username=self.user.username, password=PASSWORD)
|
||||
response = self.client.get(self.url, content_type="application/json")
|
||||
next_url = urllib.parse.quote(settings.ACCOUNT_MICROFRONTEND_URL, safe="")
|
||||
assert response.status_code == 200
|
||||
assert (response.data ==
|
||||
[{
|
||||
'accepts_logins': True, 'name': 'Google',
|
||||
'disconnect_url': '/auth/disconnect/google-oauth2/?',
|
||||
'connect_url': f'/auth/login/google-oauth2/?auth_entry=account_settings&next={next_url}',
|
||||
'connect_url': '/auth/login/google-oauth2/?auth_entry=account_settings&next=%2Faccount%2Fsettings',
|
||||
'connected': False, 'id': 'oa2-google-oauth2'
|
||||
}])
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.conf import settings
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
from django.urls import reverse
|
||||
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
|
||||
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
|
||||
from rest_framework import exceptions, permissions, status, throttling
|
||||
@@ -424,7 +425,7 @@ class ThirdPartyAuthUserStatusView(APIView):
|
||||
state.provider.provider_id,
|
||||
pipeline.AUTH_ENTRY_ACCOUNT_SETTINGS,
|
||||
# The url the user should be directed to after the auth process has completed.
|
||||
redirect_url=settings.ACCOUNT_MICROFRONTEND_URL,
|
||||
redirect_url=reverse('account_settings'),
|
||||
),
|
||||
'accepts_logins': state.provider.accepts_logins,
|
||||
# If the user is connected, sending a POST request to this url removes the connection
|
||||
|
||||
@@ -11,7 +11,7 @@ from unittest import mock
|
||||
import pytest
|
||||
from django import test
|
||||
from django.conf import settings
|
||||
from django.contrib import auth, messages
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth import models as auth_models
|
||||
from django.contrib.messages.storage import fallback
|
||||
from django.contrib.sessions.backends import cache
|
||||
@@ -28,6 +28,7 @@ from openedx.core.djangoapps.user_authn.views.login_form import login_and_regist
|
||||
from openedx.core.djangoapps.user_authn.views.register import RegistrationView
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
|
||||
from openedx.core.djangoapps.user_api.accounts.settings_views import account_settings_context
|
||||
from common.djangoapps.student import models as student_models
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
|
||||
@@ -98,43 +99,6 @@ class HelperMixin:
|
||||
if prepopulated_form_data in required_fields:
|
||||
self.assertContains(response, form_field_data[prepopulated_form_data])
|
||||
|
||||
def _get_user_providers_state(self, request):
|
||||
"""
|
||||
Return provider user states and duplicated providers.
|
||||
"""
|
||||
data = {
|
||||
'auth': {},
|
||||
}
|
||||
data['duplicate_provider'] = pipeline.get_duplicate_provider(messages.get_messages(request))
|
||||
auth_states = pipeline.get_provider_user_states(request.user)
|
||||
data['auth']['providers'] = [{
|
||||
'name': state.provider.name,
|
||||
'connected': state.has_account,
|
||||
} for state in auth_states if state.provider.display_for_login or state.has_account]
|
||||
return data
|
||||
|
||||
def assert_third_party_accounts_state(self, request, duplicate=False, linked=None):
|
||||
"""
|
||||
Asserts the user's third party account in the expected state.
|
||||
|
||||
If duplicate is True, we expect data['duplicate_provider'] to contain
|
||||
the duplicate provider backend name. If linked is passed, we conditionally
|
||||
check that the provider is included in data['auth']['providers'] and
|
||||
its connected state is correct.
|
||||
"""
|
||||
data = self._get_user_providers_state(request)
|
||||
if duplicate:
|
||||
assert data['duplicate_provider'] == self.provider.backend_name
|
||||
else:
|
||||
assert data['duplicate_provider'] is None
|
||||
|
||||
if linked is not None:
|
||||
expected_provider = [
|
||||
provider for provider in data['auth']['providers'] if provider['name'] == self.provider.name
|
||||
][0]
|
||||
assert expected_provider is not None
|
||||
assert expected_provider['connected'] == linked
|
||||
|
||||
def assert_register_form_populates_unicode_username_correctly(self, request): # lint-amnesty, pylint: disable=invalid-name
|
||||
"""
|
||||
Check the registration form username field behaviour with unicode values.
|
||||
@@ -154,6 +118,27 @@ class HelperMixin:
|
||||
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_UNICODE_USERNAME': True}):
|
||||
self._check_registration_form_username(pipeline_kwargs, unicode_username, unicode_username)
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def assert_account_settings_context_looks_correct(self, context, duplicate=False, linked=None):
|
||||
"""Asserts the user's account settings page context is in the expected state.
|
||||
|
||||
If duplicate is True, we expect context['duplicate_provider'] to contain
|
||||
the duplicate provider backend name. If linked is passed, we conditionally
|
||||
check that the provider is included in context['auth']['providers'] and
|
||||
its connected state is correct.
|
||||
"""
|
||||
if duplicate:
|
||||
assert context['duplicate_provider'] == self.provider.backend_name
|
||||
else:
|
||||
assert context['duplicate_provider'] is None
|
||||
|
||||
if linked is not None:
|
||||
expected_provider = [
|
||||
provider for provider in context['auth']['providers'] if provider['name'] == self.provider.name
|
||||
][0]
|
||||
assert expected_provider is not None
|
||||
assert expected_provider['connected'] == linked
|
||||
|
||||
def assert_exception_redirect_looks_correct(self, expected_uri, auth_entry=None):
|
||||
"""Tests middleware conditional redirection.
|
||||
|
||||
@@ -626,7 +611,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
|
||||
# First we expect that we're in the unlinked state, and that there
|
||||
# really is no association in the backend.
|
||||
self.assert_third_party_accounts_state(get_request, linked=False)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(get_request), linked=False)
|
||||
self.assert_social_auth_does_not_exist_for_user(get_request.user, strategy)
|
||||
|
||||
# We should be redirected back to the complete page, setting
|
||||
@@ -645,7 +630,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
|
||||
# Now we expect to be in the linked state, with a backend entry.
|
||||
self.assert_social_auth_exists_for_user(get_request.user, strategy)
|
||||
self.assert_third_party_accounts_state(get_request, linked=True)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(get_request), linked=True)
|
||||
|
||||
def test_full_pipeline_succeeds_for_unlinking_account(self):
|
||||
# First, create, the GET request and strategy that store pipeline state,
|
||||
@@ -677,7 +662,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
get_request.user = post_request.user
|
||||
|
||||
# First we expect that we're in the linked state, with a backend entry.
|
||||
self.assert_third_party_accounts_state(get_request, linked=True)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(get_request), linked=True)
|
||||
self.assert_social_auth_exists_for_user(get_request.user, strategy)
|
||||
|
||||
# Fire off the disconnect pipeline to unlink.
|
||||
@@ -691,7 +676,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
)
|
||||
|
||||
# Now we expect to be in the unlinked state, with no backend entry.
|
||||
self.assert_third_party_accounts_state(get_request, linked=False)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(get_request), linked=False)
|
||||
self.assert_social_auth_does_not_exist_for_user(user, strategy)
|
||||
|
||||
def test_linking_already_associated_account_raises_auth_already_associated(self):
|
||||
@@ -749,8 +734,8 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
post_request,
|
||||
exceptions.AuthAlreadyAssociated(self.provider.backend_name, 'account is already in use.'))
|
||||
|
||||
self.assert_third_party_accounts_state(
|
||||
post_request, duplicate=True, linked=True)
|
||||
self.assert_account_settings_context_looks_correct(
|
||||
account_settings_context(post_request), duplicate=True, linked=True)
|
||||
|
||||
@mock.patch('common.djangoapps.third_party_auth.pipeline.segment.track')
|
||||
def test_full_pipeline_succeeds_for_signing_in_to_existing_active_account(self, _mock_segment_track):
|
||||
@@ -810,7 +795,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
self.assert_redirect_after_pipeline_completes(
|
||||
self.do_complete(strategy, get_request, partial_pipeline_token, partial_data, user)
|
||||
)
|
||||
self.assert_third_party_accounts_state(get_request)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(get_request))
|
||||
|
||||
def test_signin_fails_if_account_not_active(self):
|
||||
_, strategy = self.get_request_and_strategy(
|
||||
@@ -952,7 +937,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
)
|
||||
# Now the user has been redirected to the dashboard. Their third party account should now be linked.
|
||||
self.assert_social_auth_exists_for_user(created_user, strategy)
|
||||
self.assert_third_party_accounts_state(request, linked=True)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(request), linked=True)
|
||||
|
||||
def test_new_account_registration_assigns_distinct_username_on_collision(self):
|
||||
original_username = self.get_username()
|
||||
|
||||
@@ -27,6 +27,7 @@ from common.djangoapps.third_party_auth.saml import SapSuccessFactorsIdentityPro
|
||||
from common.djangoapps.third_party_auth.saml import log as saml_log
|
||||
from common.djangoapps.third_party_auth.tasks import fetch_saml_metadata
|
||||
from common.djangoapps.third_party_auth.tests import testutil, utils
|
||||
from openedx.core.djangoapps.user_api.accounts.settings_views import account_settings_context
|
||||
from openedx.core.djangoapps.user_authn.views.login import login_user
|
||||
from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerFactory
|
||||
|
||||
@@ -238,10 +239,12 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin
|
||||
}
|
||||
|
||||
@patch('openedx.features.enterprise_support.api.enterprise_customer_for_request')
|
||||
@patch('openedx.core.djangoapps.user_api.accounts.settings_views.enterprise_customer_for_request')
|
||||
@patch('openedx.features.enterprise_support.utils.third_party_auth.provider.Registry.get')
|
||||
def test_full_pipeline_succeeds_for_unlinking_testshib_account(
|
||||
self,
|
||||
mock_auth_provider,
|
||||
mock_enterprise_customer_for_request_settings_view,
|
||||
mock_enterprise_customer_for_request,
|
||||
):
|
||||
|
||||
@@ -281,6 +284,7 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin
|
||||
}
|
||||
mock_auth_provider.return_value.backend_name = 'tpa-saml'
|
||||
mock_enterprise_customer_for_request.return_value = enterprise_customer_data
|
||||
mock_enterprise_customer_for_request_settings_view.return_value = enterprise_customer_data
|
||||
|
||||
# Instrument the pipeline to get to the dashboard with the full expected state.
|
||||
self.client.get(
|
||||
@@ -295,7 +299,7 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin
|
||||
request=request)
|
||||
|
||||
# First we expect that we're in the linked state, with a backend entry.
|
||||
self.assert_third_party_accounts_state(request, linked=True)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(request), linked=True)
|
||||
self.assert_social_auth_exists_for_user(request.user, strategy)
|
||||
|
||||
FEATURES_WITH_ENTERPRISE_ENABLED = settings.FEATURES.copy()
|
||||
@@ -323,7 +327,7 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin
|
||||
)
|
||||
)
|
||||
# Now we expect to be in the unlinked state, with no backend entry.
|
||||
self.assert_third_party_accounts_state(request, linked=False)
|
||||
self.assert_account_settings_context_looks_correct(account_settings_context(request), linked=False)
|
||||
self.assert_social_auth_does_not_exist_for_user(user, strategy)
|
||||
assert EnterpriseCustomerUser.objects\
|
||||
.filter(enterprise_customer=enterprise_customer, user_id=user.id).count() == 0
|
||||
|
||||
Reference in New Issue
Block a user