-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Test for malformed and missing auth token
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- bump: patch | ||
changes: | ||
added: | ||
- Added tests for malformed and missing auth tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from tests.python.utils import client | ||
|
||
load_dotenv() | ||
|
||
# Note that this does not test the passage of a functioning token; | ||
# that is already handled by test_liveness in another file | ||
|
||
|
||
def test_malformed_token(client): | ||
"""Test that a malformed token, when passed to the API, returns a 401""" | ||
response = client.post( | ||
"/us/calculate", | ||
headers={ | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer garbage_token", | ||
}, | ||
data=open( | ||
"./tests/python/data/calculate_us_1_data.json", | ||
"r", | ||
encoding="utf-8", | ||
), | ||
) | ||
assert response.status_code == 401 | ||
|
||
|
||
def test_no_token(client): | ||
"""Test that API returns 401 when no token is passed""" | ||
response = client.post( | ||
"/us/calculate", | ||
headers={"Content-Type": "application/json"}, | ||
) | ||
assert response.status_code == 401 |