-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test_auth_tkt.py
111 lines (101 loc) · 4.85 KB
/
test_auth_tkt.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from ckan.new_tests import helpers
from ckan.lib.auth_tkt import CkanAuthTktCookiePlugin, make_plugin
class TestCkanAuthTktCookiePlugin(object):
'''
Test the added methods used by this subclass of
repoze.who.plugins.auth_tkt.AuthTktCookiePlugin
'''
def _make_plugin(self, httponly):
'''Only httponly needs to be set.'''
return CkanAuthTktCookiePlugin(httponly=httponly,
secret=None,
cookie_name='auth_tkt',
secure=False,
include_ip=False,
timeout=None,
reissue_time=None,
userid_checker=None)
@helpers.change_config('who.httponly', True)
def test_httponly_expected_cookies_with_config_httponly_true(self):
'''
The returned cookies are in the format we expect, with HttpOnly flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0; HttpOnly')
]
assert cookies == expected_cookies
@helpers.change_config('who.httponly', False)
def test_httponly_expected_cookies_with_config_httponly_false(self):
'''
The returned cookies are in the format we expect, without HttpOnly
flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0')
]
assert cookies == expected_cookies
def test_httponly_expected_cookies_without_config_httponly(self):
'''
The returned cookies are in the format we expect, with HttpOnly flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0; HttpOnly')
]
assert cookies == expected_cookies
@helpers.change_config('who.secure', True)
def test_secure_expected_cookies_with_config_secure_true(self):
'''
The returned cookies are in the format we expect, with secure flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; secure; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0; secure; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0; secure; HttpOnly')
]
assert cookies == expected_cookies
@helpers.change_config('who.secure', False)
def test_secure_expected_cookies_with_config_secure_false(self):
'''
The returned cookies are in the format we expect, without secure
flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0; HttpOnly')
]
assert cookies == expected_cookies
def test_secure_expected_cookies_without_config_secure(self):
'''
The returned cookies are in the format we expect, without secure flag.
'''
plugin = make_plugin(secret='sosecret')
cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'},
value='HELLO')
expected_cookies = [
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=0.0.0.0; HttpOnly'),
('Set-Cookie', 'auth_tkt="HELLO"; Path=/; Domain=.0.0.0.0; HttpOnly')
]
assert cookies == expected_cookies