34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
import unittest
|
|
|
|
import main
|
|
|
|
|
|
class TestOpenAPISecurity(unittest.TestCase):
|
|
def test_bearer_auth_included(self):
|
|
spec = main.app.openapi()
|
|
comps = spec.get("components", {})
|
|
sec = comps.get("securitySchemes", {})
|
|
assert "bearerAuth" in sec
|
|
bearer = sec["bearerAuth"]
|
|
assert bearer.get("type") == "http"
|
|
assert bearer.get("scheme") == "bearer"
|
|
assert bearer.get("bearerFormat") == "JWT"
|
|
|
|
def test_household_routes_require_bearer(self):
|
|
spec = main.app.openapi()
|
|
paths = spec.get("paths", {})
|
|
# Users me households
|
|
op = paths.get("/api/v1/users/me/households", {}).get("get")
|
|
assert op and any("bearerAuth" in s for s in op.get("security", []))
|
|
# and has 403 in responses
|
|
assert "403" in op.get("responses", {})
|
|
# Household whoami
|
|
op = paths.get("/api/v1/households/{householdSlug}/whoami", {}).get("get")
|
|
assert op and any("bearerAuth" in s for s in op.get("security", []))
|
|
assert "403" in op.get("responses", {})
|
|
|
|
def test_problem_403_component_present(self):
|
|
spec = main.app.openapi()
|
|
comps = spec.get("components", {})
|
|
responses = comps.get("responses", {})
|
|
assert "Problem403" in responses
|