fix(pwa): look up credit packs by own property only#53
Open
khipu-agent wants to merge 1 commit into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
POST /credits/buypicks the pack withPACKS[req.body.pack] || PACKS.starter.PACKSis a plain object literal, so a pack name likeconstructor,toString, orhasOwnPropertyresolves to something offObject.prototype— which is truthy, so the starter fallback is skipped. The CoinPay payment is then created withpack.usd/pack.creditsbeingundefined: the request to CoinPay goes out with no amount and no credits (the keys are dropped from the JSON body), while acredit_purchasesrow 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.mjsboots the real router against a stub CoinPay API and postspack=constructor— before the fix, the stub receives a body withamountabsent 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 tostarteras intended.Tests
New integration tests in
apps/pwa/test/credits-pack.test.mjs:pro) reaches CoinPay with the right amount/credits;Object.prototypename (constructor) falls back to starter too.Full suite: 167/167 green.