Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ async def security_middleware(request: Request, call_next):
settings = Settings()
protected = path in _PROTECTED_PATHS
token = settings.api_auth_token.strip()
if settings.environment.lower() == "production" and not token:
return JSONResponse(
{"detail": "API_AUTH_TOKEN must be configured in production"},
status_code=503,
)
token_required = settings.environment.lower() == "production" and bool(token)
if protected and token_required:
authorization = request.headers.get("Authorization", "")
Expand Down
5 changes: 2 additions & 3 deletions tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ def test_production_requires_bearer_token(monkeypatch):
)


def test_production_without_auth_token_fails_closed(monkeypatch):
def test_production_without_auth_token_allows_public_requests(monkeypatch):
monkeypatch.setenv("ENVIRONMENT", "production")
monkeypatch.delenv("API_AUTH_TOKEN", raising=False)

client = TestClient(app)
response = client.post("/api/validate", json={})

assert response.status_code == 503
assert "API_AUTH_TOKEN" in response.json()["detail"]
assert response.status_code == 422
Loading