mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-25 12:01:04 +02:00
fix: keep current user route available in stack auth
This commit is contained in:
parent
f4c711627c
commit
76db7c2611
2 changed files with 73 additions and 3 deletions
63
api/tests/test_auth_routes.py
Normal file
63
api/tests/test_auth_routes.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
from types import SimpleNamespace
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from api.routes.auth import router
|
||||
from api.services.auth import depends as auth_depends
|
||||
from api.services.auth.depends import get_user
|
||||
|
||||
|
||||
def _make_test_app() -> FastAPI:
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
return app
|
||||
|
||||
|
||||
def test_stack_mode_hides_email_password_auth_routes(monkeypatch):
|
||||
monkeypatch.setattr(auth_depends, "AUTH_PROVIDER", "stack")
|
||||
client = TestClient(_make_test_app())
|
||||
|
||||
signup_response = client.post(
|
||||
"/auth/signup",
|
||||
json={
|
||||
"email": "user@example.com",
|
||||
"password": "password123",
|
||||
"name": "User",
|
||||
},
|
||||
)
|
||||
login_response = client.post(
|
||||
"/auth/login",
|
||||
json={
|
||||
"email": "user@example.com",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
assert signup_response.status_code == 404
|
||||
assert signup_response.json() == {"detail": "Not found"}
|
||||
assert login_response.status_code == 404
|
||||
assert login_response.json() == {"detail": "Not found"}
|
||||
|
||||
|
||||
def test_stack_mode_keeps_current_user_route_available(monkeypatch):
|
||||
monkeypatch.setattr(auth_depends, "AUTH_PROVIDER", "stack")
|
||||
app = _make_test_app()
|
||||
app.dependency_overrides[get_user] = lambda: SimpleNamespace(
|
||||
id=7,
|
||||
email="user@example.com",
|
||||
selected_organization_id=42,
|
||||
provider_id="stack-user-1",
|
||||
)
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/auth/me")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"id": 7,
|
||||
"email": "user@example.com",
|
||||
"name": None,
|
||||
"organization_id": 42,
|
||||
"provider_id": "stack-user-1",
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue