mirror of
https://github.com/kharonsec/br-acc
synced 2026-04-25 17:15:02 +02:00
Merge pull request #28 from joaobenedetmachado/api-health-version
Include API version in /health response
This commit is contained in:
@@ -2,7 +2,7 @@ import logging
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from slowapi import _rate_limit_exceeded_handler
|
||||
from slowapi.errors import RateLimitExceeded
|
||||
@@ -85,5 +85,5 @@ app.include_router(investigation.shared_router)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
async def health(request: Request) -> dict[str, str]:
|
||||
return {"status": "ok", "version": request.app.version}
|
||||
|
||||
@@ -205,4 +205,4 @@ async def test_health_not_masked(client: AsyncClient) -> None:
|
||||
"""Non-CPF JSON responses pass through unchanged."""
|
||||
resp = await client.get("/health")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == {"status": "ok"}
|
||||
assert resp.json()["status"] == "ok" and "version" in resp.json()
|
||||
|
||||
@@ -8,7 +8,9 @@ from httpx import AsyncClient
|
||||
async def test_health_returns_ok(client: AsyncClient) -> None:
|
||||
response = await client.get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ok"}
|
||||
data = response.json()
|
||||
assert data["status"] == "ok"
|
||||
assert "version" in data
|
||||
assert response.headers["x-content-type-options"] == "nosniff"
|
||||
assert response.headers["x-frame-options"] == "DENY"
|
||||
assert response.headers["referrer-policy"] == "no-referrer"
|
||||
|
||||
Reference in New Issue
Block a user