Skip to content

Commit

Permalink
fix(cookies): use updated args for werkzeug >3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Avantol13 committed May 20, 2024
1 parent d8ced18 commit 5a3c7e5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
16 changes: 8 additions & 8 deletions fence/resources/user/user_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def save_session(self, app, session, response):
token = session.get_updated_token(app)
if token:
response.set_cookie(
app.config["SESSION_COOKIE_NAME"],
token,
key=app.config["SESSION_COOKIE_NAME"],
value=token,
expires=self.get_expiration_time(app, session),
httponly=True,
domain=domain,
Expand All @@ -210,7 +210,7 @@ def save_session(self, app, session, response):
# okay if user is hitting with just an access_token
if user_sess_id != "" and not user:
response.set_cookie(
config["ACCESS_TOKEN_COOKIE_NAME"],
key=config["ACCESS_TOKEN_COOKIE_NAME"],
expires=0,
httponly=True,
domain=domain,
Expand All @@ -221,7 +221,7 @@ def save_session(self, app, session, response):
# clear access token if not
elif user_sess_id != "" and user.id != user_sess_id:
response.set_cookie(
config["ACCESS_TOKEN_COOKIE_NAME"],
key=config["ACCESS_TOKEN_COOKIE_NAME"],
expires=0,
httponly=True,
domain=domain,
Expand Down Expand Up @@ -250,14 +250,14 @@ def save_session(self, app, session, response):
# expiration it just won't be stored in the cookie
# anymore
response.set_cookie(
app.config["SESSION_COOKIE_NAME"],
key=app.config["SESSION_COOKIE_NAME"],
expires=0,
httponly=True,
domain=domain,
secure=secure,
)
response.set_cookie(
config["ACCESS_TOKEN_COOKIE_NAME"],
key=config["ACCESS_TOKEN_COOKIE_NAME"],
expires=0,
httponly=True,
domain=domain,
Expand Down Expand Up @@ -337,8 +337,8 @@ def _create_access_token_cookie(app, session, response, user):

domain = app.session_interface.get_cookie_domain(app)
response.set_cookie(
config["ACCESS_TOKEN_COOKIE_NAME"],
access_token,
key=config["ACCESS_TOKEN_COOKIE_NAME"],
value=access_token,
expires=expiration,
httponly=True,
domain=domain,
Expand Down
2 changes: 1 addition & 1 deletion fence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def clear_cookies(response):
Set all cookies to empty and expired.
"""
for cookie_name in list(flask.request.cookies.keys()):
response.set_cookie(cookie_name, "", expires=0, httponly=True)
response.set_cookie(key=cookie_name, value="", expires=0, httponly=True)


def get_error_params(error, description):
Expand Down
54 changes: 27 additions & 27 deletions tests/link/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def test_google_link_auth_return(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -258,9 +258,9 @@ def test_patch_google_link(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -362,9 +362,9 @@ def test_patch_google_link_account_not_in_token(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -418,9 +418,9 @@ def test_patch_google_link_account_doesnt_exist(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -487,9 +487,9 @@ def test_google_link_g_account_exists(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -566,9 +566,9 @@ def test_google_link_g_account_access_extension(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -653,9 +653,9 @@ def test_google_link_g_account_exists_linked_to_different_user(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -721,9 +721,9 @@ def test_google_link_no_proxy_group(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -807,9 +807,9 @@ def test_google_link_when_google_mocked(

# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down
6 changes: 3 additions & 3 deletions tests/login/test_google_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def test_google_login_http_headers_are_less_than_4k_for_user_with_many_projects(
},
)
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down
60 changes: 30 additions & 30 deletions tests/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def test_valid_session(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand All @@ -82,9 +82,9 @@ def test_valid_session_modified(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -112,9 +112,9 @@ def test_expired_session_lifetime(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -144,9 +144,9 @@ def test_expired_session_timeout(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand All @@ -168,9 +168,9 @@ def test_session_cleared(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand All @@ -190,9 +190,9 @@ def test_invalid_session_cookie(app):
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -234,16 +234,16 @@ def test_valid_session_valid_access_token(
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
client.set_cookie(
"localhost",
config["ACCESS_TOKEN_COOKIE_NAME"],
test_access_jwt,
domain="localhost",
key=config["ACCESS_TOKEN_COOKIE_NAME"],
value=test_access_jwt,
httponly=True,
samesite="Lax",
)
Expand Down Expand Up @@ -287,16 +287,16 @@ def test_valid_session_valid_access_token_diff_user(
with app.test_client() as client:
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
client.set_cookie(
"localhost",
config["ACCESS_TOKEN_COOKIE_NAME"],
test_access_jwt,
domain="localhost",
key=config["ACCESS_TOKEN_COOKIE_NAME"],
value=test_access_jwt,
httponly=True,
samesite="Lax",
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def test_logout_fence(app, client, user_with_fence_provider, monkeypatch):
with mock.patch("fence.allowed_login_redirects", return_value={"some_site.com"}):
# manually set cookie for initial session
client.set_cookie(
"localhost",
config["SESSION_COOKIE_NAME"],
test_session_jwt,
domain="localhost",
key=config["SESSION_COOKIE_NAME"],
value=test_session_jwt,
httponly=True,
samesite="Lax",
)
Expand Down

0 comments on commit 5a3c7e5

Please sign in to comment.