-
Notifications
You must be signed in to change notification settings - Fork 16
/
tests.py
56 lines (44 loc) · 1.91 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import unicode_literals
from django.test import TestCase
class MainTestCase(TestCase):
def test_home(self):
response = self.client.get('/', HTTP_X_XHR_REFERER='/page/')
self.assertEqual(response.content, b'/page/')
self.assertEqual(response.cookies.get('request_method').value, 'GET')
def test_redirect(self):
response = self.client.get('/redirect/', HTTP_X_XHR_REFERER='/page/')
self.assertEqual(
self.client.session.get('_turbolinks_redirect_to'),
'/page/',
)
self.assertNotIn('X-XHR-Redirected-To', response)
response = self.client.get('/page/', HTTP_X_XHR_REFERER='/redirect/')
self.assertNotIn('_turbolinks_redirect_to', self.client.session)
self.assertIn('X-XHR-Redirected-To', response)
def test_cookie(self):
self.client.cookies['request_method'] = 'GET'
response = self.client.get('/', HTTP_X_XHR_REFERER='/page/')
self.assertFalse(response.cookies)
def test_x_redirect(self):
response = self.client.get('/x-redirect/')
self.assertEqual(response.status_code, 302)
response = self.client.get('/x-redirect/', HTTP_X_XHR_REFERER='/page/')
self.assertEqual(response.status_code, 403)
# origin and redirect are exactly the same
response = self.client.get(
'/x-redirect/',
HTTP_X_XHR_REFERER='http://example.com/'
)
self.assertEqual(response.status_code, 302)
# port differs
response = self.client.get(
'/x-redirect/',
HTTP_X_XHR_REFERER='http://example.com:8000/'
)
self.assertEqual(response.status_code, 403)
# same domain, different URI
response = self.client.get(
'/x-redirect/',
HTTP_X_XHR_REFERER='http://example.com/example/'
)
self.assertEqual(response.status_code, 302)