Skip to content

Commit a400b82

Browse files
committedNov 18, 2020
Better error message for /indieauth/done
Closes #17
1 parent 8bf9d30 commit a400b82

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎datasette_indieauth/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ async def indieauth_page(request, datasette, status=200, error=None):
9090
async def indieauth_done(request, datasette):
9191
from datasette.utils.asgi import Response
9292

93-
state = request.args.get("state")
93+
state = request.args.get("state") or ""
9494
code = request.args.get("code")
9595
try:
9696
state_bits = datasette.unsign(state, DATASETTE_INDIEAUTH_STATE)
9797
except itsdangerous.BadSignature:
9898
return await indieauth_page(
99-
request, datasette, error="Invalid state returned by authorization server"
99+
request, datasette, error="Invalid state", status=400
100100
)
101101
authorization_endpoint = state_bits["a"]
102102

‎tests/test_indieauth.py

+10
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,13 @@ async def test_indieauth_succeeds(httpx_mock, auth_response_body, expected_profi
213213
assert datasette.unsign(response.cookies["ds_actor"], "actor") == {
214214
"a": expected_actor
215215
}
216+
217+
218+
@pytest.mark.asyncio
219+
async def test_indieauth_done_no_params_error():
220+
datasette = Datasette([], memory=True)
221+
app = datasette.app()
222+
async with httpx.AsyncClient(app=app) as client:
223+
response = await client.get("http://localhost/-/indieauth/done")
224+
assert response.status_code == 400
225+
assert "Invalid state" in response.text

0 commit comments

Comments
 (0)
Please sign in to comment.