|
|
@@ -0,0 +1,39 @@
|
|
|
+import { containsDangerousSubstitution, getCommandDecision } from "../commands"
|
|
|
+
|
|
|
+describe("containsDangerousSubstitution", () => {
|
|
|
+ describe("zsh array assignments (should NOT be flagged)", () => {
|
|
|
+ it("should return false for files=(a b c)", () => {
|
|
|
+ expect(containsDangerousSubstitution("files=(a b c)")).toBe(false)
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should return false for var=(item1 item2)", () => {
|
|
|
+ expect(containsDangerousSubstitution("var=(item1 item2)")).toBe(false)
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should return false for x=(hello)", () => {
|
|
|
+ expect(containsDangerousSubstitution("x=(hello)")).toBe(false)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe("zsh process substitution (should be flagged)", () => {
|
|
|
+ it("should return true for standalone =(whoami)", () => {
|
|
|
+ expect(containsDangerousSubstitution("=(whoami)")).toBe(true)
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should return true for =(ls) with leading space", () => {
|
|
|
+ expect(containsDangerousSubstitution(" =(ls)")).toBe(true)
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should return true for echo =(cat /etc/passwd)", () => {
|
|
|
+ expect(containsDangerousSubstitution("echo =(cat /etc/passwd)")).toBe(true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe("getCommandDecision", () => {
|
|
|
+ it("should auto_approve array assignment command with wildcard allowlist", () => {
|
|
|
+ const command = 'files=(a.ts b.ts); for f in "${files[@]}"; do echo "$f"; done'
|
|
|
+ const result = getCommandDecision(command, ["*"])
|
|
|
+ expect(result).toBe("auto_approve")
|
|
|
+ })
|
|
|
+})
|