Skip to content

Commit

Permalink
tests: fix cookie_jar not existing anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Dec 4, 2024
1 parent f06a95c commit 318ce2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
12 changes: 6 additions & 6 deletions tests/test_invenio_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ def test_cookies(cookie_app, users):
data=dict(email=u["email"], password=u["password"], remember=True),
)
assert res.status_code == 302
cookies = {c.name: c for c in client.cookie_jar}
assert "session" in cookies
assert "remember_token" not in cookies

assert client.get_cookie(key="session", domain="example.com")
assert not client.get_cookie("remember_token")

# Cookie must be HTTP only, secure and have a domain specified.
for c in cookies.values():
for c in client._cookies.values():
assert c.path == "/"
assert c.domain_specified is True, "no domain in {}".format(c.name)
assert c.has_nonstandard_attr("HttpOnly")
Expand Down Expand Up @@ -269,6 +269,6 @@ def test_headers_info(app, users):
# Login
testutils.login_user_via_session(client, email=u["email"])
response = client.get(url)
cookie = requests.utils.dict_from_cookiejar(client.cookie_jar)
assert response.headers["X-Session-ID"] == cookie["session"].split(".")[0]
cookie = client.get_cookie("session", domain="example.com")
assert response.headers["X-Session-ID"] == cookie.value.split(".")[0]
assert int(response.headers["X-User-ID"]) == u["id"]
15 changes: 6 additions & 9 deletions tests/test_views_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2024 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE
Expand Down Expand Up @@ -65,7 +66,7 @@ def _login_user(client, user, email="[email protected]", password="123456"):
assert res.status_code == 200
assert payload["id"] == user.id
assert payload["email"].lower() == user.email.lower()
session_cookie = next(c for c in client.cookie_jar if c.name == "session")
session_cookie = client.get_cookie("session")
assert session_cookie is not None
assert session_cookie.value
assert current_user.is_authenticated
Expand Down Expand Up @@ -185,7 +186,7 @@ def test_registration_view(api):
assert res.status_code == 200
assert payload["id"] == 2
assert payload["email"] == "[email protected]"
session_cookie = next(c for c in client.cookie_jar if c.name == "session")
session_cookie = client.get_cookie("session")
assert session_cookie is not None
assert session_cookie.value

Expand Down Expand Up @@ -235,18 +236,14 @@ def test_logout_view(api):
with app.test_client() as client:
# Login user
_login_user(client, normal_user)
old_session_cookie = next(
c for c in client.cookie_jar if c.name == "session"
)
old_session_cookie = client.get_cookie("session")

# Log out user
url = url_for("invenio_accounts_rest_auth.logout")
res = client.post(url)
payload = get_json(res)
assert payload["message"] == "User logged out."
new_session_cookie = next(
c for c in client.cookie_jar if c.name == "session"
)
new_session_cookie = client.get_cookie("session")
assert old_session_cookie.value != new_session_cookie.value
assert current_user.is_anonymous

Expand Down Expand Up @@ -315,7 +312,7 @@ def test_reset_password_view(api):
assert res.status_code == 200
assert payload["id"] == normal_user.id
assert payload["email"] == normal_user.email
session_cookie = next(c for c in client.cookie_jar if c.name == "session")
session_cookie = client.get_cookie("session")
assert session_cookie is not None
assert session_cookie.value

Expand Down

0 comments on commit 318ce2b

Please sign in to comment.