add required bearer auth token
This commit is contained in:
parent
5da9d04d7e
commit
02151e49b8
3 changed files with 72 additions and 10 deletions
29
tests/test_auth.py
Normal file
29
tests/test_auth.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue