diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index f831edff01..89ca6208b3 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -4,7 +4,7 @@ import copy import mock from mock import patch import shutil -import lxml +import lxml.html from datetime import timedelta from fs.osfs import OSFS @@ -26,7 +26,7 @@ from contentstore.views.component import ADVANCED_COMPONENT_TYPES from xmodule.contentstore.django import contentstore from xmodule.contentstore.utils import restore_asset_from_trashcan, empty_asset_trashcan -from xmodule.exceptions import NotFoundError, InvalidVersionError +from xmodule.exceptions import InvalidVersionError from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.inheritance import own_metadata @@ -1747,6 +1747,35 @@ class EntryPageTestCase(TestCase): self._test_page("/logout", 302) +class SigninPageTestCase(TestCase): + """ + Tests that the CSRF token is directly included in the signin form. This is + important to make sure that the script is functional independently of any + other script. + """ + + def test_csrf_token_is_present_in_form(self): + # Expected html: + #
+ response = self.client.get("/signin") + csrf_token = response.cookies.get("csrftoken") + form = lxml.html.fromstring(response.content).get_element_by_id("login_form") + csrf_input_field = form.find(".//input[@name='csrfmiddlewaretoken']") + + self.assertIsNotNone(csrf_token) + self.assertIsNotNone(csrf_token.value) + self.assertIsNotNone(csrf_input_field) + self.assertEqual(csrf_token.value, csrf_input_field.attrib["value"]) + + def _create_course(test, course_key, course_data): """ Creates a course via an AJAX request and verifies the URL returned in the response. diff --git a/cms/static/js/factories/login.js b/cms/static/js/factories/login.js index da35af0b28..fcf8ee3069 100644 --- a/cms/static/js/factories/login.js +++ b/cms/static/js/factories/login.js @@ -8,7 +8,6 @@ define(['jquery.cookie', 'utility'], function() { dataType: 'json', data: data, success: callback, - headers : {'X-CSRFToken':$.cookie('csrftoken')} }); } diff --git a/cms/templates/login.html b/cms/templates/login.html index c0ab813ae0..deb959861a 100644 --- a/cms/templates/login.html +++ b/cms/templates/login.html @@ -21,6 +21,7 @@ from django.utils.translation import ugettext as _