Esempio n. 1
0
def test_get_cookies_for_url_ignores_secure_cookies_for_http():
    jar = CookieJar()

    jar.add(URL(b"https://foo.org"), Cookie(b"hello", b"world", secure=True))

    cookies = list(jar.get_cookies_for_url(URL(b"http://foo.org/hello-world")))
    assert len(cookies) == 0
Esempio n. 2
0
def test_get_cookies_for_url():
    jar = CookieJar()

    jar.add(URL(b"https://foo.org"), Cookie("hello", "world"))

    cookies = list(jar.get_cookies_for_url(URL(b"https://foo.org/hello-world")))

    assert len(cookies) == 1
    assert cookies[0].name == "hello"
    assert cookies[0].value == "world"
Esempio n. 3
0
def test_get_cookies_for_url():
    jar = CookieJar()

    jar.add(URL(b'https://foo.org'), Cookie(b'hello', b'world'))

    cookies = list(jar.get_cookies_for_url(
        URL(b'https://foo.org/hello-world')))

    assert len(cookies) == 1
    assert cookies[0].name == b'hello'
    assert cookies[0].value == b'world'
Esempio n. 4
0
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"
Esempio n. 5
0
def test_cookiejar_invalid_domain(request_url, cookie_domain):
    jar = CookieJar()
    cookie = Cookie(b'Name', b'Value', domain=cookie_domain)

    with pytest.raises(InvalidCookieDomain):
        jar.add(request_url, cookie)