diff --git a/tests/unit/public-response-cache.test.ts b/tests/unit/public-response-cache.test.ts index 30dd1df8..e0b2c0aa 100644 --- a/tests/unit/public-response-cache.test.ts +++ b/tests/unit/public-response-cache.test.ts @@ -112,6 +112,54 @@ describe("public response Cache Storage adapter", () => { expect(match.ok && match.value !== null).toBe(true); }); + it("stages with an anonymous same-origin request that fails on redirect (02-02)", async () => { + const policy = createDefaultPublicCachePolicy( + "https://assets.example.test", + ); + const bytes = new Uint8Array([5, 5, 5, 5]); + const asset: PublicCacheAsset = { + absoluteUrl: "https://assets.example.test/anonymous.js", + expectedByteLength: bytes.byteLength, + expectedContentType: "application/javascript", + integrity: { + algorithm: "SHA-256", + digestHex: await digestHex(bytes), + }, + }; + const requests: Request[] = []; + const adapter = createPublicResponseCacheAdapter({ + cacheStorage: new MemoryCacheStorage() as unknown as CacheStorage, + crypto: globalThis.crypto, + mutationLock: immediateLock, + policy, + fetcher: async (request) => { + requests.push(request); + return new Response(bytes, { + headers: { + "cache-control": "public, max-age=31536000, immutable", + "content-type": "application/javascript", + }, + }); + }, + }); + const manifest = await manifestFor("anonymous-release", [asset], policy); + + expect(await adapter.admin.stageRelease(manifest)).toMatchObject({ + ok: true, + }); + // The Cache Storage is origin-wide and has no logout purge, so a cookie + // on this request would let a per-user response outlive the session. + expect( + requests.map(({ credentials, mode, redirect }) => ({ + credentials, + mode, + redirect, + })), + ).toEqual([ + { credentials: "omit", mode: "same-origin", redirect: "error" }, + ]); + }); + it("restages an evicted entry even when the release marker remains", async () => { const policy = createDefaultPublicCachePolicy( "https://assets.example.test",