Merge pull request #13658 from edx/common_cleanup/auth_exchange
Move auth_exchange from common to openedx/core
This commit is contained in:
@@ -21,7 +21,7 @@ from django.utils.http import int_to_base36
|
||||
from mock import Mock, patch
|
||||
import ddt
|
||||
|
||||
from lms.djangoapps.oauth_dispatch.tests import factories as dot_factories
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from student.views import password_reset, password_reset_confirm_wrapper, SETTING_CHANGE_INITIATED
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
@@ -35,7 +35,7 @@ from commerce.models import CommerceConfiguration
|
||||
from commerce.tests import TEST_API_URL, TEST_API_SIGNING_KEY, factories
|
||||
from commerce.tests.mocks import mock_get_orders
|
||||
from course_modes.models import CourseMode
|
||||
from lms.djangoapps.oauth_dispatch.tests import factories as dot_factories
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories
|
||||
from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin
|
||||
from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account
|
||||
from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH
|
||||
|
||||
@@ -440,7 +440,7 @@ OAUTH_EXPIRE_PUBLIC_CLIENT_DAYS = 30
|
||||
################################## DJANGO OAUTH TOOLKIT #######################################
|
||||
|
||||
OAUTH2_PROVIDER = {
|
||||
'OAUTH2_VALIDATOR_CLASS': 'lms.djangoapps.oauth_dispatch.dot_overrides.EdxOAuth2Validator',
|
||||
'OAUTH2_VALIDATOR_CLASS': 'openedx.core.djangoapps.oauth_dispatch.dot_overrides.EdxOAuth2Validator',
|
||||
'SCOPES': {
|
||||
'read': 'Read scope',
|
||||
'write': 'Write scope',
|
||||
@@ -1927,7 +1927,7 @@ INSTALLED_APPS = (
|
||||
|
||||
# django-oauth-toolkit
|
||||
'oauth2_provider',
|
||||
'lms.djangoapps.oauth_dispatch.apps.OAuthDispatchAppConfig',
|
||||
'openedx.core.djangoapps.oauth_dispatch.apps.OAuthDispatchAppConfig',
|
||||
|
||||
'third_party_auth',
|
||||
|
||||
@@ -1937,7 +1937,7 @@ INSTALLED_APPS = (
|
||||
# defined by oauth_provider. If those tables don't exist, an error can occur.
|
||||
'oauth_provider',
|
||||
|
||||
'auth_exchange',
|
||||
'openedx.core.djangoapps.auth_exchange',
|
||||
|
||||
# For the wiki
|
||||
'wiki', # The new django-wiki from benjaoming
|
||||
|
||||
@@ -8,10 +8,10 @@ from django.views.generic.base import RedirectView
|
||||
from ratelimitbackend import admin
|
||||
from django.conf.urls.static import static
|
||||
|
||||
import auth_exchange.views
|
||||
from courseware.views.views import EnrollStaffView
|
||||
from config_models.views import ConfigurationModelCurrentAPIView
|
||||
from courseware.views.index import CoursewareIndex
|
||||
from openedx.core.djangoapps.auth_exchange.views import LoginWithAccessTokenView
|
||||
from openedx.core.djangoapps.catalog.models import CatalogIntegration
|
||||
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
|
||||
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
|
||||
@@ -860,7 +860,7 @@ if settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER'):
|
||||
urlpatterns += (
|
||||
# These URLs dispatch to django-oauth-toolkit or django-oauth2-provider as appropriate.
|
||||
# Developers should use these routes, to maintain compatibility for existing client code
|
||||
url(r'^oauth2/', include('lms.djangoapps.oauth_dispatch.urls')),
|
||||
url(r'^oauth2/', include('openedx.core.djangoapps.oauth_dispatch.urls')),
|
||||
# These URLs contain the django-oauth2-provider default behavior. It exists to provide
|
||||
# URLs for django-oauth2-provider to call using reverse() with the oauth2 namespace, and
|
||||
# also to maintain support for views that have not yet been wrapped in dispatch views.
|
||||
@@ -938,7 +938,7 @@ if settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER'):
|
||||
urlpatterns += (
|
||||
url(
|
||||
r'^oauth2/login/$',
|
||||
auth_exchange.views.LoginWithAccessTokenView.as_view(),
|
||||
LoginWithAccessTokenView.as_view(),
|
||||
name="login_with_access_token"
|
||||
),
|
||||
)
|
||||
|
||||
@@ -8,8 +8,8 @@ Django-OAuth2-Provider.
|
||||
from unittest import skip, expectedFailure
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from lms.djangoapps.oauth_dispatch import adapters
|
||||
from lms.djangoapps.oauth_dispatch.tests.constants import DUMMY_REDIRECT_URL
|
||||
from openedx.core.djangoapps.oauth_dispatch import adapters
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests.constants import DUMMY_REDIRECT_URL
|
||||
|
||||
from ..views import DOTAccessTokenExchangeView
|
||||
|
||||
@@ -70,7 +70,10 @@ class AccessTokenExchangeViewTest(AccessTokenExchangeTestMixin):
|
||||
|
||||
self._setup_provider_response(success=True)
|
||||
for single_access_token in [True, False]:
|
||||
with mock.patch("auth_exchange.views.constants.SINGLE_ACCESS_TOKEN", single_access_token):
|
||||
with mock.patch(
|
||||
"openedx.core.djangoapps.auth_exchange.views.constants.SINGLE_ACCESS_TOKEN",
|
||||
single_access_token,
|
||||
):
|
||||
first_response = self.client.post(self.url, self.data)
|
||||
second_response = self.client.post(self.url, self.data)
|
||||
self.assertEqual(first_response.status_code, 200)
|
||||
@@ -26,8 +26,8 @@ from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
import social.apps.django_app.utils as social_utils
|
||||
|
||||
from auth_exchange.forms import AccessTokenExchangeForm
|
||||
from lms.djangoapps.oauth_dispatch import adapters
|
||||
from openedx.core.djangoapps.auth_exchange.forms import AccessTokenExchangeForm
|
||||
from openedx.core.djangoapps.oauth_dispatch import adapters
|
||||
from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class AccessTokenExchangeBase(APIView):
|
||||
"""
|
||||
form = AccessTokenExchangeForm(request=request, oauth2_adapter=self.oauth2_adapter, data=request.POST) # pylint: disable=no-member
|
||||
if not form.is_valid():
|
||||
return self.error_response(form.errors)
|
||||
return self.error_response(form.errors) # pylint: disable=no-member
|
||||
|
||||
user = form.cleaned_data["user"]
|
||||
scope = form.cleaned_data["scope"]
|
||||
@@ -11,4 +11,4 @@ class OAuthDispatchAppConfig(AppConfig):
|
||||
"""
|
||||
OAuthDispatch Configuration
|
||||
"""
|
||||
name = u'lms.djangoapps.oauth_dispatch'
|
||||
name = u'openedx.core.djangoapps.oauth_dispatch'
|
||||
@@ -2,7 +2,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from edx_oauth2_provider.tests.factories import ClientFactory
|
||||
@@ -15,6 +17,7 @@ from .constants import DUMMY_REDIRECT_URL
|
||||
from ..adapters import DOTAdapter
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled")
|
||||
class ClientCredentialsTest(mixins.AccessTokenMixin, TestCase):
|
||||
""" Tests validating the client credentials grant behavior. """
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from django.test import TestCase
|
||||
from oauth2_provider.models import Application, AccessToken, RefreshToken
|
||||
|
||||
from lms.djangoapps.oauth_dispatch.tests import factories
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests import factories
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
|
||||
@@ -5,30 +5,33 @@ Tests for Blocks Views
|
||||
import json
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
import httpretty
|
||||
from provider import constants
|
||||
import unittest
|
||||
|
||||
from student.tests.factories import UserFactory
|
||||
from third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle
|
||||
|
||||
from .constants import DUMMY_REDIRECT_URL
|
||||
from .. import adapters
|
||||
from .. import views
|
||||
if settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"):
|
||||
from .. import views
|
||||
from . import mixins
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled")
|
||||
class _DispatchingViewTestCase(TestCase):
|
||||
"""
|
||||
Base class for tests that exercise DispatchingViews.
|
||||
|
||||
Subclasses need to define self.url.
|
||||
"""
|
||||
dop_adapter = adapters.DOPAdapter()
|
||||
dot_adapter = adapters.DOTAdapter()
|
||||
|
||||
view_class = None
|
||||
url = None
|
||||
|
||||
def setUp(self):
|
||||
super(_DispatchingViewTestCase, self).setUp()
|
||||
self.user = UserFactory()
|
||||
@@ -50,7 +53,7 @@ class _DispatchingViewTestCase(TestCase):
|
||||
Call the view with a POST request objectwith the appropriate format,
|
||||
returning the response object.
|
||||
"""
|
||||
return self.client.post(self.url, self._post_body(user, client, token_type))
|
||||
return self.client.post(self.url, self._post_body(user, client, token_type)) # pylint: disable=no-member
|
||||
|
||||
def _post_body(self, user, client, token_type=None):
|
||||
"""
|
||||
@@ -64,9 +67,10 @@ class TestAccessTokenView(mixins.AccessTokenMixin, _DispatchingViewTestCase):
|
||||
"""
|
||||
Test class for AccessTokenView
|
||||
"""
|
||||
|
||||
view_class = views.AccessTokenView
|
||||
url = reverse('access_token')
|
||||
def setUp(self):
|
||||
self.url = reverse('access_token')
|
||||
self.view_class = views.AccessTokenView
|
||||
super(TestAccessTokenView, self).setUp()
|
||||
|
||||
def _post_body(self, user, client, token_type=None):
|
||||
"""
|
||||
@@ -124,9 +128,10 @@ class TestAccessTokenExchangeView(ThirdPartyOAuthTestMixinGoogle, ThirdPartyOAut
|
||||
"""
|
||||
Test class for AccessTokenExchangeView
|
||||
"""
|
||||
|
||||
view_class = views.AccessTokenExchangeView
|
||||
url = reverse('exchange_access_token', kwargs={'backend': 'google-oauth2'})
|
||||
def setUp(self):
|
||||
self.url = reverse('exchange_access_token', kwargs={'backend': 'google-oauth2'})
|
||||
self.view_class = views.AccessTokenExchangeView
|
||||
super(TestAccessTokenExchangeView, self).setUp()
|
||||
|
||||
def _post_body(self, user, client, token_type=None):
|
||||
return {
|
||||
@@ -143,6 +148,7 @@ class TestAccessTokenExchangeView(ThirdPartyOAuthTestMixinGoogle, ThirdPartyOAut
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
@ddt.ddt
|
||||
class TestAuthorizationView(_DispatchingViewTestCase):
|
||||
"""
|
||||
@@ -231,6 +237,7 @@ class TestAuthorizationView(_DispatchingViewTestCase):
|
||||
return response.redirect_chain[-1][0]
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled")
|
||||
class TestViewDispatch(TestCase):
|
||||
"""
|
||||
Test that the DispatchingView dispatches the right way.
|
||||
@@ -324,12 +331,11 @@ class TestRevokeTokenView(_DispatchingViewTestCase): # pylint: disable=abstract
|
||||
"""
|
||||
Test class for RevokeTokenView
|
||||
"""
|
||||
|
||||
login_with_access_token_url = reverse("login_with_access_token")
|
||||
revoke_token_url = reverse('revoke_token')
|
||||
access_token_url = reverse('access_token')
|
||||
|
||||
def setUp(self):
|
||||
self.login_with_access_token_url = reverse("login_with_access_token")
|
||||
self.revoke_token_url = reverse('revoke_token')
|
||||
self.access_token_url = reverse('access_token')
|
||||
|
||||
super(TestRevokeTokenView, self).setUp()
|
||||
response = self.client.post(self.access_token_url, self.access_token_post_body_with_password())
|
||||
access_token_data = json.loads(response.content)
|
||||
@@ -7,11 +7,11 @@ from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from auth_exchange import views as auth_exchange_views
|
||||
from django.views.generic import View
|
||||
from edx_oauth2_provider import views as dop_views # django-oauth2-provider views
|
||||
from oauth2_provider import models as dot_models, views as dot_views # django-oauth-toolkit
|
||||
|
||||
from openedx.core.djangoapps.auth_exchange import views as auth_exchange_views
|
||||
from openedx.core.lib.token_utils import JwtBuilder
|
||||
|
||||
from . import adapters
|
||||
@@ -27,7 +27,7 @@ from rest_framework.views import APIView
|
||||
from rest_framework_oauth import permissions
|
||||
from rest_framework_oauth.compat import oauth2_provider, oauth2_provider_scope
|
||||
|
||||
from lms.djangoapps.oauth_dispatch import adapters
|
||||
from openedx.core.djangoapps.oauth_dispatch import adapters
|
||||
from openedx.core.lib.api import authentication
|
||||
|
||||
factory = APIRequestFactory() # pylint: disable=invalid-name
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.test import TestCase
|
||||
import jwt
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
from lms.djangoapps.oauth_dispatch.tests import mixins
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests import mixins
|
||||
from openedx.core.lib.token_utils import JwtBuilder
|
||||
from student.tests.factories import UserFactory, UserProfileFactory
|
||||
|
||||
|
||||
Reference in New Issue
Block a user