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": {