MCPcopy Index your code
hub / github.com/python/cpython / test_secure_block

Method test_secure_block

Lib/test/test_http_cookiejar.py:1194–1220  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1192 "secure cookie registered non-secure")
1193
1194 def test_secure_block(self):
1195 pol = DefaultCookiePolicy()
1196 c = CookieJar(policy=pol)
1197
1198 headers = ["Set-Cookie: session=narf; secure; path=/"]
1199 req = urllib.request.Request("https://www.acme.com/")
1200 res = FakeResponse(headers, "https://www.acme.com/")
1201 c.extract_cookies(res, req)
1202 self.assertEqual(len(c), 1)
1203
1204 req = urllib.request.Request("https://www.acme.com/")
1205 c.add_cookie_header(req)
1206 self.assertTrue(req.has_header("Cookie"))
1207
1208 req = urllib.request.Request("http://www.acme.com/")
1209 c.add_cookie_header(req)
1210 self.assertFalse(req.has_header("Cookie"))
1211
1212 # secure websocket protocol
1213 req = urllib.request.Request("wss://www.acme.com/")
1214 c.add_cookie_header(req)
1215 self.assertTrue(req.has_header("Cookie"))
1216
1217 # non-secure websocket protocol
1218 req = urllib.request.Request("ws://www.acme.com/")
1219 c.add_cookie_header(req)
1220 self.assertFalse(req.has_header("Cookie"))
1221
1222 def test_custom_secure_protocols(self):
1223 pol = DefaultCookiePolicy(secure_protocols=["foos"])

Callers

nothing calls this directly

Calls 9

extract_cookiesMethod · 0.95
add_cookie_headerMethod · 0.95
has_headerMethod · 0.95
DefaultCookiePolicyClass · 0.90
CookieJarClass · 0.90
FakeResponseClass · 0.85
assertTrueMethod · 0.80
assertFalseMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected