From 1c545c768b80e9be3ba873e287d1684cfe87e18f Mon Sep 17 00:00:00 2001 From: MrBBot Date: Mon, 27 Feb 2023 14:09:26 +0000 Subject: [PATCH] Fix cache tests following #515's preserving URL change (#523) Similar to #475, we weren't deleting the `MF-Original-URL` header from incoming requests, leading to incorrect URLs in the loopback server when the incoming request was passed-through as the cache key. Tests also needed to be updated as the storage location is now based off the actual URL passed to `dispatchFetch()`. --- packages/miniflare/src/plugins/core/index.ts | 1 + packages/miniflare/test/plugins/cache/index.spec.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/miniflare/src/plugins/core/index.ts b/packages/miniflare/src/plugins/core/index.ts index b9e60bff06ac6..c1b19c2899998 100644 --- a/packages/miniflare/src/plugins/core/index.ts +++ b/packages/miniflare/src/plugins/core/index.ts @@ -145,6 +145,7 @@ export const SCRIPT_ENTRY = `async function handleEvent(event) { redirect: event.request.redirect, body: event.request.body, }); + request.headers.delete("${HEADER_ORIGINAL_URL}"); if (globalThis.${BINDING_SERVICE_USER} === undefined) { return new Response("No entrypoint worker found", { status: 404 }); diff --git a/packages/miniflare/test/plugins/cache/index.spec.ts b/packages/miniflare/test/plugins/cache/index.spec.ts index 72536b0d482dc..8a1219dc05667 100644 --- a/packages/miniflare/test/plugins/cache/index.spec.ts +++ b/packages/miniflare/test/plugins/cache/index.spec.ts @@ -373,7 +373,6 @@ test.serial("operations persist cached data", async (t) => { t.teardown(() => t.context.setOptions({})); const key = "http://localhost/cache-persist"; - const storedKey = new URL("/cache-persist", t.context.url).toString(); // Check put respects persist await t.context.mf.dispatchFetch(key, { @@ -381,7 +380,7 @@ test.serial("operations persist cached data", async (t) => { headers: { "Test-Response-Cache-Control": "max-age=3600" }, body: "body", }); - let stored = await storage.get(storedKey); + let stored = await storage.get(key); t.deepEqual(stored?.value, utf8Encode("body")); // Check match respects persist @@ -392,7 +391,7 @@ test.serial("operations persist cached data", async (t) => { // Check delete respects persist res = await t.context.mf.dispatchFetch(key, { method: "DELETE" }); t.is(res.status, 204); - stored = await storage.get(storedKey); + stored = await storage.get(key); t.is(stored, undefined); }); test.serial("operations are no-ops when caching disabled", async (t) => {