Files
monlet/server/tests/test_auth.py
2026-05-27 10:01:59 +04:00

36 lines
965 B
Python

import pytest
@pytest.mark.asyncio
async def test_health_no_auth(app_client):
r = await app_client.get("/api/v1/health")
assert r.status_code == 200
assert r.json()["status"] == "ok"
@pytest.mark.asyncio
async def test_metrics_no_auth(app_client):
r = await app_client.get("/metrics")
assert r.status_code == 200
@pytest.mark.asyncio
async def test_missing_token_401(app_client):
r = await app_client.get("/api/v1/agents")
assert r.status_code == 401
body = r.json()
assert body["error"]["code"] == "unauthorized"
assert body["error"]["request_id"]
@pytest.mark.asyncio
async def test_wrong_token_401(app_client):
r = await app_client.get("/api/v1/agents", headers={"Authorization": "Bearer nope"})
assert r.status_code == 401
@pytest.mark.asyncio
async def test_valid_token_200(app_client, auth_headers):
r = await app_client.get("/api/v1/agents", headers=auth_headers)
assert r.status_code == 200