test(cache-storage): pin the anonymous same-origin stage request (02-02)

Cache Storage has no logout purge, so credentials omit and same-origin mode
are what keep per-user responses out of it. Removing either line, switching
credentials to include or dropping redirect error now fails this test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-25 23:59:53 +09:00
co-authored by Claude Opus 5.5
parent c9be8d65e4
commit 9a56741357
+48
View File
@@ -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",