summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorXtreak <tir.karthi@gmail.com>2019-03-10 17:12:28 (GMT)
committerSenthil Kumaran <skumaran@gatech.edu>2019-03-10 17:12:28 (GMT)
commit0e1f1f01058bd4a9b98cfe443214adecc019a38c (patch)
treeee5abf47d4caaad17e3f936d75a075dc568915f3 /Lib/test
parent1aeeaeb79efa4de41f97b58547e23c2965ecabc5 (diff)
downloadcpython-0e1f1f01058bd4a9b98cfe443214adecc019a38c.zip
cpython-0e1f1f01058bd4a9b98cfe443214adecc019a38c.tar.gz
cpython-0e1f1f01058bd4a9b98cfe443214adecc019a38c.tar.bz2
bpo-35647: Fix path check in cookiejar (#11436)
* Refactor cookie path check as per RFC 6265 * Add tests for prefix match of path * Add news entry * Fix set_ok_path and refactor tests * Use slice for last letter
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_http_cookiejar.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index acf315a..22bf41c 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -720,6 +720,30 @@ class CookieTests(unittest.TestCase):
req = urllib.request.Request("http://www.example.com")
self.assertEqual(request_path(req), "/")
+ def test_path_prefix_match(self):
+ pol = DefaultCookiePolicy()
+ strict_ns_path_pol = DefaultCookiePolicy(strict_ns_set_path=True)
+
+ c = CookieJar(pol)
+ base_url = "http://bar.com"
+ interact_netscape(c, base_url, 'spam=eggs; Path=/foo')
+ cookie = c._cookies['bar.com']['/foo']['spam']
+
+ for path, ok in [('/foo', True),
+ ('/foo/', True),
+ ('/foo/bar', True),
+ ('/', False),
+ ('/foobad/foo', False)]:
+ url = f'{base_url}{path}'
+ req = urllib.request.Request(url)
+ h = interact_netscape(c, url)
+ if ok:
+ self.assertIn('spam=eggs', h, f"cookie not set for {path}")
+ self.assertTrue(strict_ns_path_pol.set_ok_path(cookie, req))
+ else:
+ self.assertNotIn('spam=eggs', h, f"cookie set for {path}")
+ self.assertFalse(strict_ns_path_pol.set_ok_path(cookie, req))
+
def test_request_port(self):
req = urllib.request.Request("http://www.acme.com:1234/",
headers={"Host": "www.acme.com:4321"})