diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index 16d75b91408ad40fcaeed88d0d799bb13e7d648e..2933fa5e54f46f2b5605252b96f667f2412d93a1 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -2,12 +2,11 @@ Base integration test for provider implementations. """ +import json import unittest +from contextlib import contextmanager -import json import mock - -from contextlib import contextmanager from django import test from django.contrib import auth from django.contrib.auth import models as auth_models @@ -107,7 +106,7 @@ class IntegrationTestMixin(object): self._test_return_login(user_is_activated=True) def test_login(self): - self.user = UserFactory.create() # pylint: disable=attribute-defined-outside-init + self.user = UserFactory.create() # The user goes to the login page, and sees a button to login with this provider: provider_login_url = self._check_login_page() # The user clicks on the provider's button: @@ -421,7 +420,6 @@ class IntegrationTest(testutil.TestCase, test.TestCase): self.assertEqual(302, response.status_code) # NOTE: Ideally we should use assertRedirects(), however it errors out due to the hostname, testserver, # not being properly set. This may be an issue with the call made by PSA, but we are not certain. - # pylint: disable=protected-access self.assertTrue(response.get('Location').endswith(django_settings.SOCIAL_AUTH_LOGIN_REDIRECT_URL)) def assert_redirect_to_login_looks_correct(self, response): @@ -595,11 +593,13 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # expected state. self.client.get( pipeline.get_login_url(self.provider.provider_id, pipeline.AUTH_ENTRY_LOGIN)) - actions.do_complete(request.backend, social_views._do_login) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, # pylint: disable=protected-access + request=request) student_views.signin_user(strategy.request) student_views.login_user(strategy.request) - actions.do_complete(request.backend, social_views._do_login) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, # pylint: disable=protected-access + request=request) # First we expect that we're in the unlinked state, and that there # really is no association in the backend. @@ -610,20 +610,21 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # the "logged in" cookie for the marketing site. self.assert_logged_in_cookie_redirect(actions.do_complete( request.backend, social_views._do_login, request.user, None, # pylint: disable=protected-access - redirect_field_name=auth.REDIRECT_FIELD_NAME + redirect_field_name=auth.REDIRECT_FIELD_NAME, request=request )) # Set the cookie and try again self.set_logged_in_cookies(request) # Fire off the auth pipeline to link. - self.assert_redirect_to_dashboard_looks_correct( # pylint: disable=protected-access + self.assert_redirect_to_dashboard_looks_correct( actions.do_complete( request.backend, - social_views._do_login, + social_views._do_login, # pylint: disable=protected-access request.user, None, - redirect_field_name=auth.REDIRECT_FIELD_NAME + redirect_field_name=auth.REDIRECT_FIELD_NAME, + request=request ) ) @@ -648,12 +649,14 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # expected state. self.client.get( pipeline.get_login_url(self.provider.provider_id, pipeline.AUTH_ENTRY_LOGIN)) - actions.do_complete(request.backend, social_views._do_login) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, # pylint: disable=protected-access + request=request) with self._patch_edxmako_current_request(strategy.request): student_views.signin_user(strategy.request) student_views.login_user(strategy.request) - actions.do_complete(request.backend, social_views._do_login, user=user) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, user=user, # pylint: disable=protected-access + request=request) # First we expect that we're in the linked state, with a backend entry. self.assert_account_settings_context_looks_correct(account_settings_context(request), linked=True) @@ -694,7 +697,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase): with self.assertRaises(exceptions.AuthAlreadyAssociated): # pylint: disable=protected-access - actions.do_complete(backend, social_views._do_login, user=unlinked_user) + actions.do_complete(backend, social_views._do_login, user=unlinked_user, request=strategy.request) def test_already_associated_exception_populates_dashboard_with_error(self): # Instrument the pipeline with an exception. We test that the @@ -713,12 +716,14 @@ class IntegrationTest(testutil.TestCase, test.TestCase): self.client.get('/login') self.client.get(pipeline.get_login_url(self.provider.provider_id, pipeline.AUTH_ENTRY_LOGIN)) - actions.do_complete(request.backend, social_views._do_login) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, # pylint: disable=protected-access + request=request) with self._patch_edxmako_current_request(strategy.request): student_views.signin_user(strategy.request) student_views.login_user(strategy.request) - actions.do_complete(request.backend, social_views._do_login, user=user) # pylint: disable=protected-access + actions.do_complete(request.backend, social_views._do_login, # pylint: disable=protected-access + user=user, request=request) # Monkey-patch storage for messaging; pylint: disable=protected-access request._messages = fallback.FallbackStorage(request) @@ -754,7 +759,8 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # Next, the provider makes a request against /auth/complete/<provider> # to resume the pipeline. # pylint: disable=protected-access - self.assert_redirect_to_login_looks_correct(actions.do_complete(request.backend, social_views._do_login)) + self.assert_redirect_to_login_looks_correct(actions.do_complete(request.backend, social_views._do_login, + request=request)) # At this point we know the pipeline has resumed correctly. Next we # fire off the view that displays the login form and posts it via JS. @@ -770,21 +776,22 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # the "logged in" cookie for the marketing site. self.assert_logged_in_cookie_redirect(actions.do_complete( request.backend, social_views._do_login, request.user, None, # pylint: disable=protected-access - redirect_field_name=auth.REDIRECT_FIELD_NAME + redirect_field_name=auth.REDIRECT_FIELD_NAME, request=request )) # Set the cookie and try again self.set_logged_in_cookies(request) self.assert_redirect_to_dashboard_looks_correct( - actions.do_complete(request.backend, social_views._do_login, user=user)) + actions.do_complete(request.backend, social_views._do_login, user=user, request=request)) self.assert_account_settings_context_looks_correct(account_settings_context(request)) def test_signin_fails_if_account_not_active(self): _, strategy = self.get_request_and_strategy( auth_entry=pipeline.AUTH_ENTRY_LOGIN, redirect_uri='social:complete') strategy.request.backend.auth_complete = mock.MagicMock(return_value=self.fake_auth_complete(strategy)) - user = self.create_user_models_for_existing_account(strategy, 'user@example.com', 'password', self.get_username()) + user = self.create_user_models_for_existing_account(strategy, 'user@example.com', 'password', + self.get_username()) user.is_active = False user.save() @@ -833,7 +840,8 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # Next, the provider makes a request against /auth/complete/<provider>. # pylint: disable=protected-access - self.assert_redirect_to_register_looks_correct(actions.do_complete(request.backend, social_views._do_login)) + self.assert_redirect_to_register_looks_correct(actions.do_complete(request.backend, social_views._do_login, + request=request)) # At this point we know the pipeline has resumed correctly. Next we # fire off the view that displays the registration form. @@ -875,13 +883,13 @@ class IntegrationTest(testutil.TestCase, test.TestCase): # the "logged in" cookie for the marketing site. self.assert_logged_in_cookie_redirect(actions.do_complete( request.backend, social_views._do_login, request.user, None, # pylint: disable=protected-access - redirect_field_name=auth.REDIRECT_FIELD_NAME + redirect_field_name=auth.REDIRECT_FIELD_NAME, request=request )) # Set the cookie and try again self.set_logged_in_cookies(request) self.assert_redirect_to_dashboard_looks_correct( - actions.do_complete(strategy.request.backend, social_views._do_login, user=created_user)) + actions.do_complete(strategy.request.backend, social_views._do_login, user=created_user, request=request)) # 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_account_settings_context_looks_correct(account_settings_context(request), linked=True) @@ -898,7 +906,8 @@ class IntegrationTest(testutil.TestCase, test.TestCase): backend.auth_complete = mock.MagicMock(return_value=self.fake_auth_complete(strategy)) # If learner already has an account then make sure login page is served instead of registration. # pylint: disable=protected-access - self.assert_redirect_to_login_looks_correct(actions.do_complete(backend, social_views._do_login)) + self.assert_redirect_to_login_looks_correct(actions.do_complete(backend, social_views._do_login, + request=request)) distinct_username = pipeline.get(request)['kwargs']['username'] self.assertNotEqual(original_username, distinct_username) @@ -908,7 +917,8 @@ class IntegrationTest(testutil.TestCase, test.TestCase): backend = strategy.request.backend backend.auth_complete = mock.MagicMock(return_value=self.fake_auth_complete(strategy)) # pylint: disable=protected-access - self.assert_redirect_to_register_looks_correct(actions.do_complete(backend, social_views._do_login)) + self.assert_redirect_to_register_looks_correct(actions.do_complete(backend, social_views._do_login, + request=request)) with self._patch_edxmako_current_request(request): self.assert_register_response_in_pipeline_looks_correct( @@ -938,7 +948,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase): self.assertEqual(response.url, reverse('signin_user')) -# pylint: disable=test-inherits-tests, abstract-method +# pylint: disable=abstract-method @django_utils.override_settings(ECOMMERCE_API_URL=TEST_API_URL) class Oauth2IntegrationTest(IntegrationTest): """Base test case for integration tests of Oauth2 providers.""" diff --git a/requirements/edx/base.in b/requirements/edx/base.in index 14cf586519a86bd0a786dc5b15d2701e0a591ccd..bc6f6afd4043babbcd63698f26fa4ade84c7ddcc 100644 --- a/requirements/edx/base.in +++ b/requirements/edx/base.in @@ -125,8 +125,8 @@ python-saml==2.4.0 pyuca==1.1 # For more accurate sorting of translated country names in django-countries reportlab==3.1.44 # Used for shopping cart's pdf invoice/receipt generation rfc6266-parser # Used to generate Content-Disposition headers. -social-auth-app-django==1.2.0 -social-auth-core==1.4.0 +social-auth-app-django +social-auth-core pysrt==0.4.7 # Support for SubRip subtitle files, used in the video XModule pytz==2016.10 # Time zone information database PyYAML # Used to parse XModule resource templates diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index e7ab88d9ceff0073757099b937494860a15af4ec..46e6701cd45eb98ca2704f573709e6417d24d9a9 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -219,8 +219,8 @@ shortuuid==0.5.0 # via edx-django-oauth2-provider simplejson==3.15.0 # via django-rest-swagger, dogapi, mailsnake, sailthru-client, zendesk six==1.11.0 slumber==0.7.1 # via edx-rest-api-client -social-auth-app-django==1.2.0 -social-auth-core==1.4.0 +social-auth-app-django==2.1.0 +social-auth-core==1.7.0 sorl-thumbnail==12.3 sortedcontainers==0.9.2 stevedore==1.10.0 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 38221204662290cab3b0ac490c328f3d867580a2..d7bb71ea2c499f2f924fb78a94a79ca59dbc2f2b 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -305,8 +305,8 @@ six==1.11.0 slumber==0.7.1 snakefood==1.4 snowballstemmer==1.2.1 # via sphinx -social-auth-app-django==1.2.0 -social-auth-core==1.4.0 +social-auth-app-django==2.1.0 +social-auth-core==1.7.0 sorl-thumbnail==12.3 sortedcontainers==0.9.2 sphinx==1.7.5 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index f7d8fb828590c1a1021b53886cdd0c68cbe6cbab..2dabf82125821f041ee5956680c81150895d90cc 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -292,8 +292,8 @@ simplejson==3.15.0 singledispatch==3.4.0.3 six==1.11.0 slumber==0.7.1 -social-auth-app-django==1.2.0 -social-auth-core==1.4.0 +social-auth-app-django==2.1.0 +social-auth-core==1.7.0 sorl-thumbnail==12.3 sortedcontainers==0.9.2 splinter==0.8.0