mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
/-/auth-token as root redirects to /, closes #2375
This commit is contained in:
parent
feccfa2a4d
commit
81b68a143a
2 changed files with 9 additions and 0 deletions
|
|
@ -75,6 +75,9 @@ class AuthTokenView(BaseView):
|
|||
has_json_alternate = False
|
||||
|
||||
async def get(self, request):
|
||||
# If already signed in as root, redirect
|
||||
if request.actor and request.actor.get("id") == "root":
|
||||
return Response.redirect(self.ds.urls.instance())
|
||||
token = request.args.get("token") or ""
|
||||
if not self.ds._root_token:
|
||||
raise Forbidden("Root token has already been used")
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ async def test_auth_token(ds_client):
|
|||
# Check that a second with same token fails
|
||||
assert ds_client.ds._root_token is None
|
||||
assert (await ds_client.get(path)).status_code == 403
|
||||
# But attempting with same token while logged in as root should redirect to /
|
||||
response = await ds_client.get(
|
||||
path, cookies={"ds_actor": ds_client.actor_cookie({"id": "root"})}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.headers["Location"] == "/"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue