Commit 03c3ee53 by Andy Armstrong

Move cors_crsf to openedx/core

parent 8c22d522
...@@ -252,6 +252,7 @@ MAKO_TEMPLATES['main'] = [ ...@@ -252,6 +252,7 @@ MAKO_TEMPLATES['main'] = [
COMMON_ROOT / 'templates', COMMON_ROOT / 'templates',
COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates', COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates',
COMMON_ROOT / 'static', # required to statically include common Underscore templates COMMON_ROOT / 'static', # required to statically include common Underscore templates
OPENEDX_ROOT / 'core' / 'djangoapps' / 'cors_csrf' / 'templates',
OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates', OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates',
CMS_ROOT / 'djangoapps' / 'pipeline_js' / 'templates', CMS_ROOT / 'djangoapps' / 'pipeline_js' / 'templates',
] ]
......
...@@ -18,8 +18,8 @@ from rest_framework.throttling import UserRateThrottle ...@@ -18,8 +18,8 @@ from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView from rest_framework.views import APIView
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from embargo import api as embargo_api from embargo import api as embargo_api
from cors_csrf.authentication import SessionAuthenticationCrossDomainCsrf from openedx.core.djangoapps.cors_csrf.authentication import SessionAuthenticationCrossDomainCsrf
from cors_csrf.decorators import ensure_csrf_cookie_cross_domain from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain
from openedx.core.lib.api.authentication import ( from openedx.core.lib.api.authentication import (
SessionAuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser,
OAuth2AuthenticationAllowInactiveUser, OAuth2AuthenticationAllowInactiveUser,
......
...@@ -471,6 +471,7 @@ MAKO_TEMPLATES['main'] = [ ...@@ -471,6 +471,7 @@ MAKO_TEMPLATES['main'] = [
COMMON_ROOT / 'templates', COMMON_ROOT / 'templates',
COMMON_ROOT / 'lib' / 'capa' / 'capa' / 'templates', COMMON_ROOT / 'lib' / 'capa' / 'capa' / 'templates',
COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates', COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates',
OPENEDX_ROOT / 'core' / 'djangoapps' / 'cors_csrf' / 'templates',
OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates', OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates',
] ]
...@@ -1129,8 +1130,8 @@ MIDDLEWARE_CLASSES = ( ...@@ -1129,8 +1130,8 @@ MIDDLEWARE_CLASSES = (
# CORS and CSRF # CORS and CSRF
'corsheaders.middleware.CorsMiddleware', 'corsheaders.middleware.CorsMiddleware',
'cors_csrf.middleware.CorsCSRFMiddleware', 'openedx.core.djangoapps.cors_csrf.middleware.CorsCSRFMiddleware',
'cors_csrf.middleware.CsrfCrossDomainCookieMiddleware', 'openedx.core.djangoapps.cors_csrf.middleware.CsrfCrossDomainCookieMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'splash.middleware.SplashMiddleware', 'splash.middleware.SplashMiddleware',
...@@ -2072,7 +2073,7 @@ INSTALLED_APPS = ( ...@@ -2072,7 +2073,7 @@ INSTALLED_APPS = (
# CORS and cross-domain CSRF # CORS and cross-domain CSRF
'corsheaders', 'corsheaders',
'cors_csrf', 'openedx.core.djangoapps.cors_csrf',
'commerce', 'commerce',
......
...@@ -884,7 +884,7 @@ urlpatterns += ( ...@@ -884,7 +884,7 @@ urlpatterns += (
# XDomain proxy # XDomain proxy
urlpatterns += ( urlpatterns += (
url(r'^xdomain_proxy.html$', 'cors_csrf.views.xdomain_proxy', name='xdomain_proxy'), url(r'^xdomain_proxy.html$', 'openedx.core.djangoapps.cors_csrf.views.xdomain_proxy', name='xdomain_proxy'),
) )
# Custom courses on edX (CCX) URLs # Custom courses on edX (CCX) URLs
......
"""Manage cross-domain configuration. """ """
Manage cross-domain configuration.
"""
from django.contrib import admin from django.contrib import admin
from config_models.admin import ConfigurationModelAdmin from config_models.admin import ConfigurationModelAdmin
from cors_csrf.models import XDomainProxyConfiguration
from .models import XDomainProxyConfiguration
admin.site.register(XDomainProxyConfiguration, ConfigurationModelAdmin) admin.site.register(XDomainProxyConfiguration, ConfigurationModelAdmin)
"""Django Rest Framework Authentication classes for cross-domain end-points.""" """
Django Rest Framework Authentication classes for cross-domain end-points.
"""
from rest_framework import authentication from rest_framework import authentication
from cors_csrf.helpers import is_cross_domain_request_allowed, skip_cross_domain_referer_check
from .helpers import is_cross_domain_request_allowed, skip_cross_domain_referer_check
class SessionAuthenticationCrossDomainCsrf(authentication.SessionAuthentication): class SessionAuthenticationCrossDomainCsrf(authentication.SessionAuthentication):
......
...@@ -48,7 +48,7 @@ from django.conf import settings ...@@ -48,7 +48,7 @@ from django.conf import settings
from django.middleware.csrf import CsrfViewMiddleware from django.middleware.csrf import CsrfViewMiddleware
from django.core.exceptions import MiddlewareNotUsed, ImproperlyConfigured from django.core.exceptions import MiddlewareNotUsed, ImproperlyConfigured
from cors_csrf.helpers import is_cross_domain_request_allowed, skip_cross_domain_referer_check from .helpers import is_cross_domain_request_allowed, skip_cross_domain_referer_check
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
......
...@@ -7,7 +7,7 @@ from config_models.models import ConfigurationModel ...@@ -7,7 +7,7 @@ from config_models.models import ConfigurationModel
class XDomainProxyConfiguration(ConfigurationModel): class XDomainProxyConfiguration(ConfigurationModel):
"""Cross-domain proxy configuration. """Cross-domain proxy configuration.
See `cors_csrf.views.xdomain_proxy` for an explanation of how this works. See `openedx.core.djangoapps.cors_csrf.views.xdomain_proxy` for an explanation of how this works.
""" """
...@@ -17,3 +17,6 @@ class XDomainProxyConfiguration(ConfigurationModel): ...@@ -17,3 +17,6 @@ class XDomainProxyConfiguration(ConfigurationModel):
u"requests to this site. Please list each domain on its own line." u"requests to this site. Please list each domain on its own line."
) )
) )
def __unicode__(self):
return "XDomainProxyConfiguration()"
...@@ -8,7 +8,7 @@ from django.conf import settings ...@@ -8,7 +8,7 @@ from django.conf import settings
from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import PermissionDenied
from cors_csrf.authentication import SessionAuthenticationCrossDomainCsrf from ..authentication import SessionAuthenticationCrossDomainCsrf
class CrossDomainAuthTest(TestCase): class CrossDomainAuthTest(TestCase):
......
...@@ -3,7 +3,8 @@ import json ...@@ -3,7 +3,8 @@ import json
import mock import mock
from django.http import HttpResponse from django.http import HttpResponse
from django.test import TestCase from django.test import TestCase
from cors_csrf.decorators import ensure_csrf_cookie_cross_domain
from ..decorators import ensure_csrf_cookie_cross_domain
def fake_view(request): def fake_view(request):
......
...@@ -11,7 +11,7 @@ from django.core.exceptions import MiddlewareNotUsed, ImproperlyConfigured ...@@ -11,7 +11,7 @@ from django.core.exceptions import MiddlewareNotUsed, ImproperlyConfigured
from django.http import HttpResponse from django.http import HttpResponse
from django.middleware.csrf import CsrfViewMiddleware from django.middleware.csrf import CsrfViewMiddleware
from cors_csrf.middleware import CorsCSRFMiddleware, CsrfCrossDomainCookieMiddleware from ..middleware import CorsCSRFMiddleware, CsrfCrossDomainCookieMiddleware
SENTINEL = object() SENTINEL = object()
......
"""Tests for cross-domain request views. """ """Tests for cross-domain request views. """
import ddt
import json import json
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
import ddt
from config_models.models import cache from config_models.models import cache
from cors_csrf.models import XDomainProxyConfiguration
from ..models import XDomainProxyConfiguration
@ddt.ddt @ddt.ddt
......
...@@ -5,7 +5,8 @@ from django.conf import settings ...@@ -5,7 +5,8 @@ from django.conf import settings
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from django.http import HttpResponseNotFound from django.http import HttpResponseNotFound
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
from cors_csrf.models import XDomainProxyConfiguration
from .models import XDomainProxyConfiguration
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment