33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
|
|
def test_health_endpoint_no_auth_required():
|
|
client = TestClient(app)
|
|
resp = client.get("/health")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["status"] == "healthy"
|
|
assert data["service"] == "courrier"
|
|
assert "+01:00" in data["horodatage"]
|
|
|
|
def test_missing_cf_access_jwt_returns_401():
|
|
client = TestClient(app)
|
|
resp = client.get("/api/v1/categories")
|
|
assert resp.status_code == 401
|
|
assert "Cf-Access-Jwt-Assertion manquant" in resp.json()["detail"]
|
|
|
|
def test_invalid_cf_access_jwt_returns_401():
|
|
client = TestClient(app)
|
|
# Token malformé
|
|
resp = client.get(
|
|
"/api/v1/categories",
|
|
headers={"Cf-Access-Jwt-Assertion": "ceci.n-est-pas.un-jwt-valide"}
|
|
)
|
|
assert resp.status_code == 401
|
|
|
|
def test_valid_cf_access_jwt_returns_200(client):
|
|
resp = client.get("/api/v1/categories")
|
|
assert resp.status_code == 200
|
|
assert "categories" in resp.json()
|