Skip to content

fix(pwa): look up credit packs by own property only#53

Open
khipu-agent wants to merge 1 commit into
moshcoder:mainfrom
khipu-agent:fix/credits-pack-own-property
Open

fix(pwa): look up credit packs by own property only#53
khipu-agent wants to merge 1 commit into
moshcoder:mainfrom
khipu-agent:fix/credits-pack-own-property

Conversation

@khipu-agent

Copy link
Copy Markdown
Contributor

Bug

POST /credits/buy picks the pack with PACKS[req.body.pack] || PACKS.starter. PACKS is a plain object literal, so a pack name like constructor, toString, or hasOwnProperty resolves to something off Object.prototype — which is truthy, so the starter fallback is skipped. The CoinPay payment is then created with pack.usd / pack.credits being undefined: the request to CoinPay goes out with no amount and no credits (the keys are dropped from the JSON body), while a credit_purchases row is inserted with NULL-ish values.

Same class of bug as the engine/tool resolver fixed in #48.

Repro: apps/pwa/test/credits-pack.test.mjs boots the real router against a stub CoinPay API and posts pack=constructor — before the fix, the stub receives a body with amount absent instead of the starter pack's $5 / 1000 credits.

Fix

Look the pack up with Object.hasOwn(PACKS, req.body.pack) so only real pack names match; anything else falls back to starter as intended.

Tests

New integration tests in apps/pwa/test/credits-pack.test.mjs:

  • a named pack (pro) reaches CoinPay with the right amount/credits;
  • an unknown pack falls back to starter;
  • an Object.prototype name (constructor) falls back to starter too.

Full suite: 167/167 green.

PACKS is a plain object literal, so /credits/buy with pack=constructor
(or toString, hasOwnProperty, …) resolved off Object.prototype — truthy,
so the starter fallback was skipped and the CoinPay payment was created
with no amount and no credits. Same class as the engine/tool resolver
fix (moshcoder#48).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant