summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cookie.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-07-02 07:48:27 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2014-07-02 07:48:27 (GMT)
commitcf0a706c15e7e82cceebbaf15a204f36ccece4d9 (patch)
treea3b0c6626599a95b89cce45354da7405525f555d /Lib/test/test_cookie.py
parent228b99e8a40554f75ba631e8daf42f7fb625bd0c (diff)
downloadcpython-cf0a706c15e7e82cceebbaf15a204f36ccece4d9.zip
cpython-cf0a706c15e7e82cceebbaf15a204f36ccece4d9.tar.gz
cpython-cf0a706c15e7e82cceebbaf15a204f36ccece4d9.tar.bz2
Issue #19870: BaseCookie now parses 'secure' and 'httponly' flags.
Backport of issue #16611.
Diffstat (limited to 'Lib/test/test_cookie.py')
-rw-r--r--Lib/test/test_cookie.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_cookie.py b/Lib/test/test_cookie.py
index 816133e..5370a8d 100644
--- a/Lib/test/test_cookie.py
+++ b/Lib/test/test_cookie.py
@@ -80,6 +80,51 @@ class CookieTests(unittest.TestCase):
self.assertEqual(C.output(['val']),
'Set-Cookie: val="some\\054funky\\073stuff"')
+ def test_set_secure_httponly_attrs(self):
+ C = Cookie.SimpleCookie('Customer="WILE_E_COYOTE"')
+ C['Customer']['secure'] = True
+ C['Customer']['httponly'] = True
+ self.assertEqual(C.output(),
+ 'Set-Cookie: Customer="WILE_E_COYOTE"; httponly; secure')
+
+ def test_secure_httponly_false_if_not_present(self):
+ C = Cookie.SimpleCookie()
+ C.load('eggs=scrambled; Path=/bacon')
+ self.assertFalse(C['eggs']['httponly'])
+ self.assertFalse(C['eggs']['secure'])
+
+ def test_secure_httponly_true_if_present(self):
+ # Issue 16611
+ C = Cookie.SimpleCookie()
+ C.load('eggs=scrambled; httponly; secure; Path=/bacon')
+ self.assertTrue(C['eggs']['httponly'])
+ self.assertTrue(C['eggs']['secure'])
+
+ def test_secure_httponly_true_if_have_value(self):
+ # This isn't really valid, but demonstrates what the current code
+ # is expected to do in this case.
+ C = Cookie.SimpleCookie()
+ C.load('eggs=scrambled; httponly=foo; secure=bar; Path=/bacon')
+ self.assertTrue(C['eggs']['httponly'])
+ self.assertTrue(C['eggs']['secure'])
+ # Here is what it actually does; don't depend on this behavior. These
+ # checks are testing backward compatibility for issue 16611.
+ self.assertEqual(C['eggs']['httponly'], 'foo')
+ self.assertEqual(C['eggs']['secure'], 'bar')
+
+ def test_bad_attrs(self):
+ # Issue 16611: make sure we don't break backward compatibility.
+ C = Cookie.SimpleCookie()
+ C.load('cookie=with; invalid; version; second=cookie;')
+ self.assertEqual(C.output(),
+ 'Set-Cookie: cookie=with\r\nSet-Cookie: second=cookie')
+
+ def test_extra_spaces(self):
+ C = Cookie.SimpleCookie()
+ C.load('eggs = scrambled ; secure ; path = bar ; foo=foo ')
+ self.assertEqual(C.output(),
+ 'Set-Cookie: eggs=scrambled; Path=bar; secure\r\nSet-Cookie: foo=foo')
+
def test_quoted_meta(self):
# Try cookie with quoted meta-data
C = Cookie.SimpleCookie()