Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Adding tests where no csrf token is given
Browse files Browse the repository at this point in the history
  • Loading branch information
JarneClauw committed Apr 28, 2024
1 parent 13e9b2e commit d53a31c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/tests/endpoints/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def auth_test(

for k, v in data_map.items():
endpoint = endpoint.replace(k, str(v))
csrf = get_csrf_from_login(client, token) if token else None

return endpoint, getattr(client, method), get_csrf_from_login(client, token), allowed
return endpoint, getattr(client, method), csrf, allowed



Expand Down
7 changes: 5 additions & 2 deletions backend/tests/endpoints/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def authentication_tests(endpoint: str, methods: list[str]) -> list[Any]:
tests = []

for method in methods:
for token in ["0123456789", "login"]:
for token in [None, "0123456789", "login"]:
allowed = token == "login"
tests.append(param(
(endpoint, method, token, allowed),
Expand Down Expand Up @@ -89,7 +89,10 @@ def authentication(self, auth_test: tuple[str, Any, str, bool]):

endpoint, method, csrf, allowed = auth_test

response = method(endpoint, headers = {"X-CSRF-TOKEN":csrf})
if csrf:
response = method(endpoint, headers = {"X-CSRF-TOKEN":csrf})
else:
response = method(endpoint)
assert allowed == (response.status_code != 401)

def authorization(self, auth_test: tuple[str, Any, str, bool]):
Expand Down

0 comments on commit d53a31c

Please sign in to comment.