diff --git a/backend/tests/test_ha.py b/backend/tests/test_ha.py index 6bfc8b4..82165eb 100644 --- a/backend/tests/test_ha.py +++ b/backend/tests/test_ha.py @@ -59,3 +59,16 @@ async def test_ha_status_lifecycle(client: AsyncClient, ha_headers): d = await client.delete("/api/v1/users/me/ha-token", headers=ha_headers) assert d.status_code == 204 assert (await client.get("/api/v1" + new_path)).status_code == 404 + + +@pytest.mark.asyncio(loop_scope="session") +async def test_ha_token_rejected_for_inactive_company(client: AsyncClient, ha_headers, db_session): + from sqlalchemy import text + r = await client.post("/api/v1/users/me/ha-token", json={}, headers=ha_headers) + path = r.json()["url"].split("/api/v1", 1)[1] + assert (await client.get("/api/v1" + path)).status_code == 200 + + await db_session.execute(text("SET LOCAL app.bypass_rls = 'on'")) + await db_session.execute(text("UPDATE companies SET is_active = false WHERE name = 'HA GmbH'")) + await db_session.commit() + assert (await client.get("/api/v1" + path)).status_code == 404