diff options
author | Luca Casonato <hello@lcas.dev> | 2023-04-29 17:43:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-29 17:43:07 +0200 |
commit | 10664908474c262192aa7951cc1b54ee43a9c249 (patch) | |
tree | 3a8e9a0d1d76c78edda3634b7ab51b5efda2d8f5 /cli/tests | |
parent | 10ae5ee26557107b22524b1a84ebb56ed7d23fb4 (diff) |
fix(ext/kv): stricter structured clone serializer (#18914)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/kv_test.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts index 0dc1690aa..5a202fb0b 100644 --- a/cli/tests/unit/kv_test.ts +++ b/cli/tests/unit/kv_test.ts @@ -123,6 +123,36 @@ dbTest("set and get recursive object", async (db) => { assert(resultValue.a === resultValue); }); +// invalid values (as per structured clone algorithm with _for storage_, NOT JSON) +const INVALID_VALUE_CASES = [ + { name: "function", value: () => {} }, + { name: "symbol", value: Symbol() }, + { name: "WeakMap", value: new WeakMap() }, + { name: "WeakSet", value: new WeakSet() }, + { + name: "WebAssembly.Module", + value: new WebAssembly.Module( + new Uint8Array([0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00]), + ), + }, + { + name: "SharedArrayBuffer", + value: new SharedArrayBuffer(3), + }, +]; + +for (const { name, value } of INVALID_VALUE_CASES) { + dbTest(`set and get ${name} value (invalid)`, async (db) => { + await assertRejects( + async () => await db.set(["a"], value), + Error, + ); + const res = await db.get(["a"]); + assertEquals(res.key, ["a"]); + assertEquals(res.value, null); + }); +} + const keys = [ ["a"], ["a", "b"], |