diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2022-10-05 13:01:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 16:31:24 +0530 |
commit | 3a3a8484069c9c6955fcb83ea761f9f74638175a (patch) | |
tree | 8040699890d5142126f10b7cff3ee3bb429f5f16 /cli/tests/unit/cache_api_test.ts | |
parent | b5425ae2d37d3dd123cbc0430785c0f61082e3e3 (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.ts | 29 |
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); +}); |