(self)
| 1401 | self.assertEqual(parse_ns_headers([""]), []) |
| 1402 | |
| 1403 | def test_bad_cookie_header(self): |
| 1404 | |
| 1405 | def cookiejar_from_cookie_headers(headers): |
| 1406 | c = CookieJar() |
| 1407 | req = urllib.request.Request("http://www.example.com/") |
| 1408 | r = FakeResponse(headers, "http://www.example.com/") |
| 1409 | c.extract_cookies(r, req) |
| 1410 | return c |
| 1411 | |
| 1412 | future = time2netscape(time.time()+3600) |
| 1413 | |
| 1414 | # none of these bad headers should cause an exception to be raised |
| 1415 | for headers in [ |
| 1416 | ["Set-Cookie: "], # actually, nothing wrong with this |
| 1417 | ["Set-Cookie2: "], # ditto |
| 1418 | # missing domain value |
| 1419 | ["Set-Cookie2: a=foo; path=/; Version=1; domain"], |
| 1420 | # bad max-age |
| 1421 | ["Set-Cookie: b=foo; max-age=oops"], |
| 1422 | # bad version |
| 1423 | ["Set-Cookie: b=foo; version=spam"], |
| 1424 | ["Set-Cookie:; Expires=%s" % future], |
| 1425 | ]: |
| 1426 | c = cookiejar_from_cookie_headers(headers) |
| 1427 | # these bad cookies shouldn't be set |
| 1428 | self.assertEqual(len(c), 0) |
| 1429 | |
| 1430 | # cookie with invalid expires is treated as session cookie |
| 1431 | headers = ["Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000"] |
| 1432 | c = cookiejar_from_cookie_headers(headers) |
| 1433 | cookie = c._cookies["www.example.com"]["/"]["c"] |
| 1434 | self.assertIsNone(cookie.expires) |
| 1435 | |
| 1436 | |
| 1437 | class LWPCookieTests(unittest.TestCase): |
nothing calls this directly
no test coverage detected