26 lines
943 B
Python
26 lines
943 B
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", []))
|
||
|
|
# 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", []))
|