[3.4] bpo-35647: Fix path check in cookiejar (GH-11436) by tirkarthi · Pull Request #12278 · python/cpython

Expand Up @@ -668,6 +668,32 @@ def test_request_path(self): 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 = '{0}{1}'.format(base_url, path) req = urllib.request.Request(url) h = interact_netscape(c, url) if ok: self.assertIn('spam=eggs', h, "cookie not set for {0}".format(path)) self.assertTrue(strict_ns_path_pol.set_ok_path(cookie, req)) else: self.assertNotIn('spam=eggs', h, "cookie set for {0}".format(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"}) Expand Down