An open-source, self-hosted system for apps built with web technologies.
Resetting a Program permission removes its stored decision and announces the declaration again
zohayrslilehb8bcc494e0dd
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.tsindex 72b8d99..092f8bb 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -92,7 +92,7 @@ export default class ProgramManager extends TheLink {public async permissions<Name extends PermissionName>(subject: unknown,- operation: "all" | "get" | "allows" | "allow" | "deny",+ operation: "all" | "get" | "allows" | "allow" | "deny" | "reset",name?: Name,value?: PermissionRequestInput<Name>) {diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex e6da1bb..20adc4a 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -836,7 +836,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dconst operation = args[1]- if (operation !== "all" && operation !== "get" && operation !== "allows" && operation !== "allow" && operation !== "deny") throw new Error(`The System does not know the Program permission operation "${String(operation)}"`)+ if (operation !== "all" && operation !== "get" && operation !== "allows" && operation !== "allow" && operation !== "deny" && operation !== "reset") throw new Error(`The System does not know the Program permission operation "${String(operation)}"`)if (operation === "all") return [parsePermissions(program.permissions)]@@ -876,7 +876,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dreturn []}- if (operation === "deny") {+ if (operation === "deny" || operation === "reset") {await access.requireAll()await programManager.permissions(address(program), operation, permission)diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex 45ad222..0b92aa5 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -2082,6 +2082,13 @@ export default class ProcessManager extends TheLink {return []}+ if (operation === "reset") {++ access.requireAll()+ await this.authManager.programManager.resetPermission(program, parsePermissionName(rest[2]))++ return []+ }throw new Error(`The System does not know the Program permission operation "${String(operation)}"`)}diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.tsindex 54130b2..43cb57d 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -261,6 +261,24 @@ export default class ProgramManager extends TheLink {if (entry && !isDeepStrictEqual(before, after)) await this.announcePermissions(entry)}+ /** Removes one stored permission, so the Program definition's declaration applies again. */+ public async resetPermission(program: Program, name: PermissionName): Promise<void> {++ const entry = this.programs?.get(program.identity)+ if (entry && entry.program !== program) throw new Error("The Program represented by this handle does not exist")++ const state = new ProgramStateStorage(program)+ if (state.permissions()[name] === undefined) return++ const before = entry?.permissions() ?? this.resolvePermissions(program)+ state.removePermission(name)++ const after = this.resolvePermissions(program)+ entry?.updatePermissions(after)++ if (entry && !isDeepStrictEqual(before, after)) await this.announcePermissions(entry)+ }+private async announcePermissions(entry: Entry) {const permissions = entry.permissions()@@ -299,6 +317,12 @@ export default class ProgramManager extends TheLink {return}+ if (operation === "reset") {++ await this.resetPermission(program, parsePermissionName(first))++ return+ }throw new Error(`The System does not know the Program permission operation "${String(operation)}"`)}diff --git a/source/server/core/link-manager/auth-manager/program-manager/state.ts b/source/server/core/link-manager/auth-manager/program-manager/state.tsindex 23f75ed..66ffdd8 100644--- a/source/server/core/link-manager/auth-manager/program-manager/state.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/state.ts@@ -35,6 +35,13 @@ export default class ProgramStateStorage {})}+ public removePermission(name: PermissionName) {+ this.change(state => {+ const { [name]: _removed, ...permissions } = permissionCatalog.stored(state.permissions ?? {})+ state.permissions = permissions+ })+ }+public pinned(): boolean {const value = this.read().pinnedif (value === undefined) return falsediff --git a/tests/client-permission-boundary.test.ts b/tests/client-permission-boundary.test.tsindex 7aa9d10..570c43d 100644--- a/tests/client-permission-boundary.test.ts+++ b/tests/client-permission-boundary.test.ts@@ -105,10 +105,13 @@ test("Program permission reads require Program access while owner decisions requawait expect(answer("program-permissions", target, "request", "request", "network", ["https://example.com"])).rejects.toThrow("does not know")await expect(answer("program-permissions", target, "allow", "network", ["https://example.com"])).rejects.toThrow("Execution is not permitted")await expect(answer("program-permissions", target, "deny", "network")).rejects.toThrow("Execution is not permitted")+ await expect(answer("program-permissions", target, "reset", "network")).rejects.toThrow("Execution is not permitted")permissions = { all: [] }await expect(answer("program-permissions", target, "allow", "network", ["https://example.com"])).resolves.toEqual([])await expect(answer("program-permissions", target, "deny", "network")).resolves.toEqual([])+ await expect(answer("program-permissions", target, "reset", "network")).resolves.toEqual([])+ expect(read).toHaveBeenLastCalledWith(target, "reset", "network")})test("Program log access follows the Program handle while System logs require logs", async () => {diff --git a/tests/program-creation.test.ts b/tests/program-creation.test.tsindex 6d3d8fb..6fc40a6 100644--- a/tests/program-creation.test.ts+++ b/tests/program-creation.test.ts@@ -128,6 +128,23 @@ test("permission changes publish one complete effective snapshot through both Pr)})+test("resetting a permission removes only its stored assignment and announces the declaration again", async context => {+ const { manager, definition, announceSubject } = fixture(context)+ const program = await manager.create(definition({ network: ["https://api.example.test"] }))+ await manager.setPermission(program, "network", false)+ await manager.setPermission(program, "uploads", true)+ announceSubject.mockClear()++ await manager.resetPermission(program, "network")+ await manager.resetPermission(program, "network")++ expect(new ProgramStateStorage(program).permissions()).toEqual({ uploads: [] })+ expect(manager.permissions(program)).toEqual({ network: ["https://api.example.test"], uploads: [] })+ expect(announceSubject).toHaveBeenCalledExactlyOnceWith(+ "program", program.identity, "changePermissions", program.reference, { network: ["https://api.example.test"], uploads: [] }+ )+})+test("pinning emits Program and global events only when the boolean changes", async context => {const { manager, definition, announceHost, announceSubject } = fixture(context)const program = await manager.create(definition())