tailscalesd/tests/test_auth.py
Abel Luck b195bd1e8f Switch to using tailscale oauth api
This removes the need to update the API key every 90 days.
2024-07-17 09:48:30 +02:00

35 lines
972 B
Python

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",
)
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"}