From 0e49842e227a0f1f69d48108c87d17fe0379e548 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 13 Jun 2020 11:29:14 -0700 Subject: [PATCH] datasette/actor_auth_cookie.py coverae to 100%, refs #841 --- tests/test_auth.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_auth.py b/tests/test_auth.py index 5e847445..bb4bee4b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -26,6 +26,17 @@ def test_actor_cookie(app_client): assert {"id": "test"} == app_client.ds._last_request.scope["actor"] +def test_actor_cookie_invalid(app_client): + cookie = app_client.actor_cookie({"id": "test"}) + # Break the signature + response = app_client.get("/", cookies={"ds_actor": cookie[:-1] + "."}) + assert None == app_client.ds._last_request.scope["actor"] + # Break the cookie format + cookie = app_client.ds.sign({"b": {"id": "test"}}, "actor") + response = app_client.get("/", cookies={"ds_actor": cookie}) + assert None == app_client.ds._last_request.scope["actor"] + + @pytest.mark.parametrize( "offset,expected", [((24 * 60 * 60), {"id": "test"}), (-(24 * 60 * 60), None),] )