clone

push a directory of html from the terminal and get a four-character url back. a deno cli on cloudflare

fix: refuse raw address targets when allowVaults is set

Dami committed cdcb215
commit
cdcb2154b8e80e903fdf1c04ff9a6646437fb6df
parent
91422bb7445893f3e2d25dfb2d630ca016988547
author
Dami <dami.etoile@gmail.com>
5 files changed, +89 -17
MREADME.md6++--
Mcli/commands/where.ts14++++---
Mcli/lib/api.ts12+++++--
Acli/lib/api_test.ts55++++++++++++++++++++++++++++++
Mcli/lib/config.ts19++++++++---
M README.md +3 -3
M cli/commands/where.ts +8 -6
M cli/lib/api.ts +9 -3
A cli/lib/api_test.ts +55 -0
@@ -0,0 +1,55 @@
1+import { commitTargetFor, resolveCliTarget } from "./api.ts";2+import type { Config } from "./config.ts";3+4+const unrestricted: Config = {5+ server: "https://example.com",6+ token: "test",7+};8+9+const restricted: Config = {10+ ...unrestricted,11+ allowVaults: ["home"],12+};13+14+function assertEquals(actual: unknown, expected: unknown): void {15+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {16+ throw new Error(`expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);17+ }18+}19+20+function assertThrows(fn: () => unknown, message: string): void {21+ try {22+ fn();23+ } catch (error) {24+ if (error instanceof Error && error.message.includes(message)) return;25+ throw error;26+ }27+ throw new Error(`expected error containing ${JSON.stringify(message)}`);28+}29+30+Deno.test("raw addresses remain available without allowVaults", () => {31+ assertEquals(resolveCliTarget("2a3f", unrestricted), "2a3f");32+ assertEquals(commitTargetFor("2a3f", unrestricted), { address: 0x2a3f });33+});34+35+Deno.test("resolveCliTarget refuses a raw address when allowVaults is set", () => {36+ assertThrows(37+ () => resolveCliTarget("2a3f", restricted),38+ "raw address targets are not allowed by this config because allowVaults is set",39+ );40+});41+42+Deno.test("commitTargetFor refuses a raw address when allowVaults is set", () => {43+ assertThrows(44+ () => commitTargetFor("2a3f", restricted),45+ "raw address targets are not allowed by this config because allowVaults is set",46+ );47+});48+49+Deno.test("allowVaults still accepts an allowed named target", () => {50+ assertEquals(resolveCliTarget("home:demo", restricted), "home:demo");51+ assertEquals(commitTargetFor("home:demo", restricted), {52+ vault: "home",53+ alias: "demo",54+ });55+});
M cli/lib/config.ts +14 -5