Skip to content

Commit

Permalink
chore: set cookie secure (#377)
Browse files Browse the repository at this point in the history
* chore: fix secure alert about set_cookie

Signed-off-by: Keming <kemingy94@gmail.com>

* fix more set_cookie

Signed-off-by: Keming <kemingy94@gmail.com>

* fix test re

Signed-off-by: Keming <kemingy94@gmail.com>

---------

Signed-off-by: Keming <kemingy94@gmail.com>
  • Loading branch information
kemingy authored Oct 3, 2024
1 parent 89893e4 commit c828143
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/flask_imports/dry_plugin_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def test_flask_make_response_post(client):
assert resp.json == {"name": payload.name, "score": [payload.limit]}
assert resp.headers.get("lang") == "en-US"
cookie_result = re.match(
r"^test_cookie=\"((\w+\s?){3})\";\sPath=/$", resp.headers.get("Set-Cookie")
r"^test_cookie=\"((\w+\s?){3})\"; Secure; HttpOnly; Path=/; SameSite=Strict$",
resp.headers.get("Set-Cookie"),
)
assert cookie_result.group(1) == payload.name

Expand All @@ -227,7 +228,8 @@ def test_flask_make_response_get(client):
assert resp.json == {"name": payload.name, "score": [payload.limit]}
assert resp.headers.get("lang") == "en-US"
cookie_result = re.match(
r"^test_cookie=\"((\w+\s?){3})\";\sPath=/$", resp.headers.get("Set-Cookie")
r"^test_cookie=\"((\w+\s?){3})\"; Secure; HttpOnly; Path=/; SameSite=Strict$",
resp.headers.get("Set-Cookie"),
)
assert cookie_result.group(1) == payload.name

Expand Down
6 changes: 6 additions & 0 deletions tests/test_plugin_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def return_make_response_post():
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand All @@ -226,6 +229,9 @@ def return_make_response_get():
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand Down
6 changes: 6 additions & 0 deletions tests/test_plugin_flask_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def return_make_response_post():
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand All @@ -213,6 +216,9 @@ def return_make_response_get():
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand Down
6 changes: 6 additions & 0 deletions tests/test_plugin_flask_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ def post(self):
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand All @@ -229,6 +232,9 @@ def get(self):
response.set_cookie(
key="test_cookie",
value=model_data.name,
secure=True,
httponly=True,
samesite="Strict",
)
return response

Expand Down

0 comments on commit c828143

Please sign in to comment.