Ticket #20411: test_20411.diff

File test_20411.diff, 1.0 KB (added by Baptiste Mispelon, 12 years ago)

Minimal test case for #20411

  • tests/csrf_tests/tests.py

    diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py
    index 5300b21..b9e8cb5 100644
    a b class CsrfViewMiddlewareTest(TestCase):  
    284284        self.assertEqual(403, req2.status_code)
    285285
    286286    @override_settings(ALLOWED_HOSTS=['www.example.com'])
     287    def test_https_malformed_referer(self):
     288        """
     289        Test that a POST HTTPS request with a bad referer is rejected
     290        """
     291        req = self._get_POST_request_with_token()
     292        req._is_secure_override = True
     293        req.META['HTTP_HOST'] = 'www.example.com'
     294        req.META['HTTP_REFERER'] = 'http://http://www.example.com/'
     295        req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {})
     296        self.assertNotEqual(None, req2)
     297        self.assertEqual(403, req2.status_code)
     298
     299    @override_settings(ALLOWED_HOSTS=['www.example.com'])
    287300    def test_https_good_referer(self):
    288301        """
    289302        Test that a POST HTTPS request with a good referer is accepted
Back to Top