From 5804d7434e4f60e98c94a6862ec4c1d068ec0650 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 22 Mar 2023 10:49:29 +0000 Subject: fix(ext/kv): don't request permissions for ":memory:" (#18346) Currently `Deno.openKv(":memory:")` requests read+write permissions for `./:memory:` even though no file is read or written. Also added some guards for special sqlite paths that were unintentionally opted into. --- cli/tests/unit/kv_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts index 7bb4656c1..c50e52c52 100644 --- a/cli/tests/unit/kv_test.ts +++ b/cli/tests/unit/kv_test.ts @@ -7,6 +7,32 @@ import { assertThrows, } from "./test_util.ts"; +Deno.test({ + name: "openKv :memory: no permissions", + permissions: {}, + async fn() { + const db = await Deno.openKv(":memory:"); + await db.close(); + }, +}); + +Deno.test({ + name: "openKv invalid filenames", + permissions: {}, + async fn() { + await assertRejects( + async () => await Deno.openKv(""), + TypeError, + "Filename cannot be empty", + ); + await assertRejects( + async () => await Deno.openKv(":foo"), + TypeError, + "Filename cannot start with ':' unless prefixed with './'", + ); + }, +}); + function dbTest(name: string, fn: (db: Deno.Kv) => Promise) { Deno.test({ name, -- cgit v1.2.3