summaryrefslogtreecommitdiff
path: root/cli/tests/unit/cache_api_test.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2022-10-05 13:01:24 +0200
committerGitHub <noreply@github.com>2022-10-05 16:31:24 +0530
commit3a3a8484069c9c6955fcb83ea761f9f74638175a (patch)
tree8040699890d5142126f10b7cff3ee3bb429f5f16 /cli/tests/unit/cache_api_test.ts
parentb5425ae2d37d3dd123cbc0430785c0f61082e3e3 (diff)
fix(ext/cache): prevent cache insert if body is not fully written (#16138)
Diffstat (limited to 'cli/tests/unit/cache_api_test.ts')
-rw-r--r--cli/tests/unit/cache_api_test.ts29
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/tests/unit/cache_api_test.ts b/cli/tests/unit/cache_api_test.ts
index 16996c821..7bc372003 100644
--- a/cli/tests/unit/cache_api_test.ts
+++ b/cli/tests/unit/cache_api_test.ts
@@ -130,7 +130,7 @@ Deno.test(async function cachePutResourceLeak() {
await assertRejects(
async () => {
await cache.put(
- new Request("https://example.com/"),
+ new Request("https://example.com/leak"),
new Response(stream),
);
},
@@ -138,3 +138,30 @@ Deno.test(async function cachePutResourceLeak() {
"leak",
);
});
+
+Deno.test(async function cachePutFailedBody() {
+ const cacheName = "cache-v1";
+ const cache = await caches.open(cacheName);
+
+ const request = new Request("https://example.com/failed-body");
+ const stream = new ReadableStream({
+ start(controller) {
+ controller.error(new Error("corrupt"));
+ },
+ });
+
+ await assertRejects(
+ async () => {
+ await cache.put(
+ request,
+ new Response(stream),
+ );
+ },
+ Error,
+ "corrupt",
+ );
+
+ const response = await cache.match(request);
+ // if it fails to read the body, the cache should be empty
+ assertEquals(response, undefined);
+});