- Timestamp:
- 07/21/2026 03:17:16 AM (7 weeks ago)
- Branches:
- main
- Children:
- 072a242
- Parents:
- ec288dc
- git-author:
- Robin <roboburr@…> (07/21/2026 03:17:13 AM)
- git-committer:
- Robin <roboburr@…> (07/21/2026 03:17:16 AM)
- File:
-
- 1 edited
-
test/paid-patron.test.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
test/paid-patron.test.js
rec288dc rdede82e 35 35 }); 36 36 37 test('pickCampaignMembership: sole membership is used even if campaign_id is wrong (creator-scoped)', async () => {37 test('pickCampaignMembership: STRICT — a non-matching campaign_id is refused', async () => { 38 38 const { pickCampaignMembership } = await import('../src/services/PaidPatreonService.js'); 39 // /identity returns ALL the visitor's memberships across every creator, so a 40 // membership to a DIFFERENT campaign must never grant access here. 39 41 const id = identityWith('42', 'active_patron', 500); 40 // A typo'd campaign_id must not lock out a real patron: memberships from the 41 // owner's own client are already their campaign, so fall back to the sole one. 42 const m = pickCampaignMembership(id, '999'); 43 assert.equal(m.status, 'active_patron'); 44 assert.equal(m.cents, 500); 42 assert.equal(pickCampaignMembership(id, '999'), null); // different campaign → no 43 assert.equal(pickCampaignMembership(id, ''), null); // no campaign → null 44 assert.equal(pickCampaignMembership(id, '42').cents, 500); // exact → yes 45 45 }); 46 46 47 test('pickCampaignMembership: multiple memberships + no match → null (no silent grant)', async () => { 47 test('fetchOwnerCampaignId reads the creator campaign from the creator token', async () => { 48 PP.saveOwnerConfig('s3', { clientId: 'c', clientSecret: 's', campaignId: 'WRONG', accessToken: 'creator-tok', refreshToken: 'r', tokenExp: Math.floor(Date.now() / 1000) + 99999 }); 49 const fetchMock = async (url) => { 50 if (url.includes('/campaigns')) return { ok: true, json: async () => ({ data: [{ type: 'campaign', id: '16300989' }] }) }; 51 return { ok: false, status: 404, json: async () => ({}) }; 52 }; 53 const id = await PP.fetchOwnerCampaignId('s3', fetchMock); 54 assert.equal(id, '16300989'); 55 }); 56 57 test('pickCampaignMembership: many memberships, only the exact campaign matches', async () => { 48 58 const { pickCampaignMembership } = await import('../src/services/PaidPatreonService.js'); 49 59 const id = { … … 54 64 ], 55 65 }; 56 assert.equal(pickCampaignMembership(id, '999'), null); // ambiguous, refuse 57 assert.equal(pickCampaignMembership(id, '77').cents, 800); // exact still works 66 assert.equal(pickCampaignMembership(id, '999'), null); // none of them 67 assert.equal(pickCampaignMembership(id, '42').cents, 300); 68 assert.equal(pickCampaignMembership(id, '77').cents, 800); 58 69 }); 59 70
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)