Skip to content

Commit a70fd81

Browse files
committed
test(runtime): name the memo's verifier type and state exactly when resolveToken verifies
Claude-Session: https://claude.ai/code/session_01LmjU2x1faLZ39DVTFyVca6 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 810176f commit a70fd81

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎packages/runtime/src/domains/share-links-refusal-order.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ beforeAll(async () => {
175175
// [#24633] One scrypt verification per distinct (password, hash) pair, not
176176
// one per request. The production verifier derives a key at the account
177177
// parameters (scrypt N=16384, r=16) on every call, and `resolveToken` calls
178-
// it for every password presented to a protected link, an `email` one
179-
// included whatever email was sent. Counted at `eadea5720`: 70 calls, plus
178+
// it for each password presented to a live protected link, once a
179+
// `signed_in` link's caller is signed in, and on an `email` link whatever
180+
// email was sent. Counted at `eadea5720`: 70 calls, plus
180181
// the 4 mints below, and they were the file's wall time. It read 34.84 s in
181182
// CI (run 39298888283, Test Core 6/6, attempt 2), and the loop case with
182183
// 10 calls timed out at vitest's 5000 ms default on attempt 1. The calls
@@ -189,18 +190,20 @@ beforeAll(async () => {
189190
// no row here is legacy). The memo wraps the instance's own verifier,
190191
// which is not exported. If that member moves, this throws rather than
191192
// leave the file paying for every call again.
193+
type Verify = (plain: string, hash: string) => Promise<boolean>;
192194
const productionVerify: unknown = (svc as any).verifyPassword;
193195
if (typeof productionVerify !== 'function') {
194196
throw new Error('ShareLinkService no longer keeps its password verifier as `verifyPassword`; re-point the memo below');
195197
}
196198
const verdicts = new Map<string, Map<string, Promise<boolean>>>();
197-
(svc as any).verifyPassword = (plain: string, hash: string): Promise<boolean> => {
199+
const memoVerify: Verify = (plain, hash) => {
198200
let byPlain = verdicts.get(hash);
199201
if (!byPlain) verdicts.set(hash, (byPlain = new Map()));
200202
let verdict = byPlain.get(plain);
201-
if (!verdict) byPlain.set(plain, (verdict = (productionVerify as (p: string, h: string) => Promise<boolean>)(plain, hash)));
203+
if (!verdict) byPlain.set(plain, (verdict = (productionVerify as Verify)(plain, hash)));
202204
return verdict;
203205
};
206+
(svc as any).verifyPassword = memoVerify;
204207
const creator = { isSystem: true, userId: 'usr_creator' } as any;
205208
const mint = async (audience: 'public' | 'signed_in' | 'email', password?: string) =>
206209
svc.createLink(

0 commit comments

Comments
 (0)