Skip to content

Commit

Permalink
test: Test for malformed and missing auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Jan 3, 2024
1 parent 7d5a916 commit c4e0d17
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
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
34 changes: 34 additions & 0 deletions tests/python/test_auth.py
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

0 comments on commit c4e0d17

Please sign in to comment.