from fastapi.testclient import TestClient from tailscalesd.main import Settings, app, get_settings client = TestClient(app) def get_settings_override() -> Settings: return Settings(test_mode=True, tailnet="test", api_key="test", bearer_token="test") app.dependency_overrides[get_settings] = get_settings_override def test_auth_works(): response = client.get("/", headers={"Authorization": "Bearer test"}) assert response.status_code == 200 assert response.json() == [] def test_unauthorized_wrong_token(): response = client.get("/", headers={"Authorization": "Bearer incorrect_token"}) assert response.status_code == 401 assert response.json() == {"detail": "Invalid authentication credentials"} def test_unauthorized_no_token(): response = client.get("/") assert response.status_code == 403 assert response.json() == {"detail": "Not authenticated"}