From 2cde368c1e191887c23ddc2f63b1862dde1aea72 Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Fri, 13 Nov 2026 22:14:36 +0000 Subject: [PATCH] =?UTF-8?q?resolve=20payer:=20authenticate=20the=20lookup?= =?UTF-8?q?=20=E2=80=94=20without=20the=20token=20OC=20hides=20the=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Second live-only bug in the same helper. Sent unauthenticated, OC answers the public view of an account: name comes back, email does not. A hand query with the Personal-Token header returned conor.canaday@gmail.com for the very slug the helper reported as email=None — so the fix would have resolved nobody, silently, while looking like it worked. The test now pins the header (the stub records what it was called with), because the failure mode here is an absence, and an absence is exactly what a stub forgets to check. --- app/main.py | 11 ++++++++++- tests/test_resolve_payer.py | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b0211ab..bfdfd3c 100644 --- a/app/main.py +++ b/app/main.py @@ -7418,7 +7418,16 @@ async def fetch_account_by_slug(slug: str) -> dict | None: # around client.post), so the JSON is read here. Getting this wrong # is invisible to a stubbed test and fatal in the container: the # first live run raised 'Response object has no attribute get'. - resp = await _oc_graphql_post(client, {"query": query, "variables": {"slug": slug}}) + resp = await _oc_graphql_post( + client, + {"query": query, "variables": {"slug": slug}}, + # WITHOUT the personal token OC answers the unauthenticated view, + # which hides every email — the lookup then returns name='Conor W' + # and email=None while a hand query with the header returns + # conor.canaday@gmail.com. The header is the whole point. + headers={"Content-Type": "application/json", + "Personal-Token": OC_PERSONAL_TOKEN}, + ) data = resp.json() except Exception as e: # read failure: report, never raise logger.warning("OC account lookup failed for slug %s: %s", slug, e) diff --git a/tests/test_resolve_payer.py b/tests/test_resolve_payer.py index 03f6bac..b1a58e7 100644 --- a/tests/test_resolve_payer.py +++ b/tests/test_resolve_payer.py @@ -60,9 +60,14 @@ class FakeResponse: return self._payload +LAST_HEADERS = {} + + def fake_post(payload): """Stand in for OC's GraphQL endpoint (the response wrapper, not the JSON).""" async def _post(client, json_body, headers=None, attempts=2): + LAST_HEADERS.clear() + LAST_HEADERS.update(headers or {}) return FakeResponse(payload) return _post @@ -75,6 +80,9 @@ acct = asyncio.run(m.fetch_account_by_slug("guest-71e9d110")) check(acct and acct["email"] == "conor.canaday@gmail.com", f"the email is returned and normalised (got {acct and acct.get('email')!r})") check(acct and acct["name"] == "Conor W", "the name comes back too, for the welcome email") +check(LAST_HEADERS.get("Personal-Token") == "test-token", + "the lookup AUTHENTICATES: without the personal token OC answers the unauthenticated view and hides every email " + f"(headers sent: {sorted(LAST_HEADERS)})") print("2. an incognito profile yields NO email — and says so rather than guessing") m._oc_graphql_post = fake_post({"data": {"account": {