tailscalesd/tests/test_auth.py

36 lines
972 B
Python
Raw Normal View History

2023-11-07 10:47:24 +01:00
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",
client_id="test",
client_secret="test",
bearer_token="test",
)
2023-11-07 10:47:24 +01:00
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"}