From 05677cbbfd09cfe8b36bf0cbb09f04a1199e4f07 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 23 Jan 2021 10:49:17 -0800 Subject: [PATCH] Store gh_ts in actor cookie, refs #67 --- datasette_auth_github/utils.py | 4 ++-- tests/test_datasette_auth_github.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/datasette_auth_github/utils.py b/datasette_auth_github/utils.py index 7e90f9e..4a0b1eb 100644 --- a/datasette_auth_github/utils.py +++ b/datasette_auth_github/utils.py @@ -54,8 +54,8 @@ async def load_orgs_and_teams(config, profile, access_token): extras["gh_teams"] = gh_teams store_timestamp = True - # if store_timestamp: - # extras["gh_ts"] = int(time.time()) + if store_timestamp: + extras["gh_ts"] = int(time.time()) return extras diff --git a/tests/test_datasette_auth_github.py b/tests/test_datasette_auth_github.py index bdb42bb..65fb971 100644 --- a/tests/test_datasette_auth_github.py +++ b/tests/test_datasette_auth_github.py @@ -7,7 +7,6 @@ import re - @pytest.fixture def non_mocked_hosts(): return ["localhost"] @@ -144,17 +143,17 @@ async def test_github_auth_callback(ds, mocked_github_api): "http://localhost/-/github-auth-callback?code=github-code-here", allow_redirects=False, ) + actor = ds.unsign(response.cookies["ds_actor"], "actor")["a"] assert { - "a": { - "display": "demouser", - "gh_id": "123", - "gh_name": "GitHub User", - "gh_login": "demouser", - "gh_email": "demouser@example.com", - "gh_orgs": ["demouser-org"], - "gh_teams": ["demouser-org/thetopteam"], - } - } == ds.unsign(response.cookies["ds_actor"], "actor") + "display": "demouser", + "gh_id": "123", + "gh_name": "GitHub User", + "gh_login": "demouser", + "gh_email": "demouser@example.com", + "gh_orgs": ["demouser-org"], + "gh_teams": ["demouser-org/thetopteam"], + }.items() <= actor.items() + assert isinstance(actor["gh_ts"], int) assert "/" == response.headers["location"]