def test_cookie_jar_does_not_override_http_only_cookie_with_non_http_only_cookie( ): jar = CookieJar() jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=True, ), ) jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world2", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=True, ), ) cookie = jar.get(b"foo.org", b"/", b"hello") assert cookie is not None assert cookie.cookie.value == b"world2" jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world modified", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=False, ), ) cookie = jar.get(b"foo.org", b"/", b"hello") assert cookie is not None assert cookie.cookie.value == b"world2"
def test_cookie_jar_check_cookies_removes_expired(): jar = CookieJar() # simulate an expired cookie that gets removed jar._domain_cookies jar._host_only_cookies = { b"foo.org": { b"/": { b"hello": StoredCookie( Cookie(b"hello", b"world", expires=b"Fri, 17 Aug 2018 20:55:04 GMT")) } } } list( jar._get_cookies_checking_exp( b"https", jar._host_only_cookies[b"foo.org"][b"/"])) assert jar.get(b"foo.org", b"/", b"hello") is None
def test_cookie_jar_check_cookies_removes_expired(): jar = CookieJar() # simulate an expired cookie that gets removed jar._domain_cookies jar._host_only_cookies = { "foo.org": { "/": { "hello": StoredCookie( Cookie( "hello", "world", expires=datetime_from_cookie_format( b"Fri, 17 Aug 2018 20:55:04 GMT" ), ) ) } } } list(jar._get_cookies_checking_exp("https", jar._host_only_cookies["foo.org"]["/"])) assert jar.get("foo.org", "/", "hello") is None