From 53e76cb94f0c8f47f51b21780b7200e15fc9a868 Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Fri, 14 Nov 2014 13:34:05 +0000 Subject: [PATCH] [#1941] More robust get_cookies test --- ckan/new_tests/lib/test_auth_tkt.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ckan/new_tests/lib/test_auth_tkt.py b/ckan/new_tests/lib/test_auth_tkt.py index 615c1b5681e..788d31f7709 100644 --- a/ckan/new_tests/lib/test_auth_tkt.py +++ b/ckan/new_tests/lib/test_auth_tkt.py @@ -136,18 +136,26 @@ def _make_plugin(self, httponly): reissue_time=None, userid_checker=None) - def test_httponly_present(self): - '''HttpOnly flag should be present in cookie values.''' + def test_httponly_expected_cookies_with_httponly(self): + '''The returned cookies are still what we expect.''' plugin = self._make_plugin(httponly=True) cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'}, - value='ANYTHING') - for cookie in cookies: - assert 'HttpOnly' in cookie[1] + 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_httponly_absent(self): - '''HttpOnly flag should be absent in cookie values.''' + def test_httponly_expected_cookies_without_httponly(self): + '''The returned cookies are still what we expect.''' plugin = self._make_plugin(httponly=False) cookies = plugin._get_cookies(environ={'SERVER_NAME': '0.0.0.0'}, - value='ANYTHING') - for cookie in cookies: - assert 'HttpOnly' not in cookie[1] + 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