Skip to content
Snippets Groups Projects
Unverified Commit c96bc833 authored by Feanil Patel's avatar Feanil Patel Committed by GitHub
Browse files

Merge pull request #18363 from edx/feanil/update_social_auth

Actually update social auth packages.
parents 62266fd9 69092ac1
No related merge requests found
......@@ -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."""
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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