|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { applyApprovalMigration, listLegacyApprovalItems } from "./approvals-migration.js"; |
| 3 | + |
| 4 | +describe("file-transfer approval migration", () => { |
| 5 | + it("enumerates legacy positive permissions without changing wildcard semantics", () => { |
| 6 | + expect( |
| 7 | + listLegacyApprovalItems({ |
| 8 | + nodes: { |
| 9 | + Shared: { allowReadPaths: ["/tmp/a", "/tmp/*.log", "/tmp/a"] }, |
| 10 | + "*": { allowWritePaths: ["/tmp/**"] }, |
| 11 | + }, |
| 12 | + }), |
| 13 | + ).toEqual([ |
| 14 | + { selector: "Shared", kind: "read", path: "/tmp/a" }, |
| 15 | + { selector: "Shared", kind: "read", path: "/tmp/*.log" }, |
| 16 | + { selector: "*", kind: "write", path: "/tmp/**" }, |
| 17 | + ]); |
| 18 | + }); |
| 19 | + |
| 20 | + it("atomically separates exact grants from confirmed authored globs", () => { |
| 21 | + const config = { |
| 22 | + nodes: { |
| 23 | + Shared: { |
| 24 | + ask: "off", |
| 25 | + allowReadPaths: ["/tmp/report-*.txt", "/var/log/**", "/tmp/remove.txt"], |
| 26 | + denyPaths: ["**/.ssh/**"], |
| 27 | + }, |
| 28 | + }, |
| 29 | + }; |
| 30 | + const items = listLegacyApprovalItems(config); |
| 31 | + const migrated = applyApprovalMigration(config, [ |
| 32 | + { |
| 33 | + item: items[0]!, |
| 34 | + action: "exact", |
| 35 | + }, |
| 36 | + { item: items[1]!, action: "keep-glob" }, |
| 37 | + { item: items[2]!, action: "remove" }, |
| 38 | + ]); |
| 39 | + |
| 40 | + expect(migrated).toEqual({ |
| 41 | + policyVersion: 2, |
| 42 | + pendingReapprovals: [{ selector: "Shared", kind: "read", path: "/tmp/report-*.txt" }], |
| 43 | + nodes: { |
| 44 | + Shared: { |
| 45 | + ask: "off", |
| 46 | + allowReadPaths: ["/var/log/**"], |
| 47 | + denyPaths: ["**/.ssh/**"], |
| 48 | + }, |
| 49 | + }, |
| 50 | + }); |
| 51 | + expect(config.nodes.Shared.allowReadPaths).toEqual([ |
| 52 | + "/tmp/report-*.txt", |
| 53 | + "/var/log/**", |
| 54 | + "/tmp/remove.txt", |
| 55 | + ]); |
| 56 | + }); |
| 57 | + |
| 58 | + it("does not widen an off policy while scheduling one exact path for reapproval", () => { |
| 59 | + const migrated = applyApprovalMigration( |
| 60 | + { |
| 61 | + nodes: { |
| 62 | + node: { ask: "off", allowReadPaths: ["/tmp/report-*.txt"] }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + [ |
| 66 | + { |
| 67 | + item: { selector: "node", kind: "read", path: "/tmp/report-*.txt" }, |
| 68 | + action: "exact", |
| 69 | + }, |
| 70 | + ], |
| 71 | + ); |
| 72 | + |
| 73 | + expect(migrated.nodes).toEqual({ node: { ask: "off", allowReadPaths: [] } }); |
| 74 | + expect(migrated.pendingReapprovals).toEqual([ |
| 75 | + { selector: "node", kind: "read", path: "/tmp/report-*.txt" }, |
| 76 | + ]); |
| 77 | + }); |
| 78 | +}); |
0 commit comments