|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { validateConfigObject } from "./config.js"; |
3 | 3 |
|
4 | | -describe('dmPolicy="allowlist" requires non-empty allowFrom', () => { |
| 4 | +describe('dmPolicy="allowlist" requires non-empty effective allowFrom', () => { |
5 | 5 | it('rejects telegram dmPolicy="allowlist" without allowFrom', () => { |
6 | 6 | const res = validateConfigObject({ |
7 | 7 | channels: { telegram: { dmPolicy: "allowlist", botToken: "fake" } }, |
8 | 8 | }); |
9 | 9 | expect(res.ok).toBe(false); |
10 | 10 | if (!res.ok) { |
11 | | - expect(res.issues.some((i) => i.path.includes("allowFrom"))).toBe(true); |
| 11 | + expect(res.issues.some((i) => i.path.includes("channels.telegram.allowFrom"))).toBe(true); |
12 | 12 | } |
13 | 13 | }); |
14 | 14 |
|
15 | | - it('rejects telegram dmPolicy="allowlist" with empty allowFrom', () => { |
| 15 | + it('rejects signal dmPolicy="allowlist" without allowFrom', () => { |
16 | 16 | const res = validateConfigObject({ |
17 | | - channels: { telegram: { dmPolicy: "allowlist", allowFrom: [], botToken: "fake" } }, |
| 17 | + channels: { signal: { dmPolicy: "allowlist" } }, |
18 | 18 | }); |
19 | 19 | expect(res.ok).toBe(false); |
20 | 20 | if (!res.ok) { |
21 | | - expect(res.issues.some((i) => i.path.includes("allowFrom"))).toBe(true); |
| 21 | + expect(res.issues.some((i) => i.path.includes("channels.signal.allowFrom"))).toBe(true); |
22 | 22 | } |
23 | 23 | }); |
24 | 24 |
|
25 | | - it('accepts telegram dmPolicy="allowlist" with allowFrom entries', () => { |
| 25 | + it('rejects discord dmPolicy="allowlist" without allowFrom', () => { |
26 | 26 | const res = validateConfigObject({ |
27 | | - channels: { telegram: { dmPolicy: "allowlist", allowFrom: ["12345"], botToken: "fake" } }, |
| 27 | + channels: { discord: { dmPolicy: "allowlist" } }, |
28 | 28 | }); |
29 | | - expect(res.ok).toBe(true); |
| 29 | + expect(res.ok).toBe(false); |
| 30 | + if (!res.ok) { |
| 31 | + expect( |
| 32 | + res.issues.some((i) => i.path.includes("channels.discord") && i.path.includes("allowFrom")), |
| 33 | + ).toBe(true); |
| 34 | + } |
30 | 35 | }); |
31 | 36 |
|
32 | | - it('accepts telegram dmPolicy="pairing" without allowFrom', () => { |
| 37 | + it('rejects whatsapp dmPolicy="allowlist" without allowFrom', () => { |
33 | 38 | const res = validateConfigObject({ |
34 | | - channels: { telegram: { dmPolicy: "pairing", botToken: "fake" } }, |
| 39 | + channels: { whatsapp: { dmPolicy: "allowlist" } }, |
35 | 40 | }); |
36 | | - expect(res.ok).toBe(true); |
| 41 | + expect(res.ok).toBe(false); |
| 42 | + if (!res.ok) { |
| 43 | + expect(res.issues.some((i) => i.path.includes("channels.whatsapp.allowFrom"))).toBe(true); |
| 44 | + } |
37 | 45 | }); |
38 | 46 |
|
39 | | - it('rejects signal dmPolicy="allowlist" without allowFrom', () => { |
| 47 | + it('accepts dmPolicy="pairing" without allowFrom', () => { |
40 | 48 | const res = validateConfigObject({ |
41 | | - channels: { signal: { dmPolicy: "allowlist" } }, |
| 49 | + channels: { telegram: { dmPolicy: "pairing", botToken: "fake" } }, |
42 | 50 | }); |
43 | | - expect(res.ok).toBe(false); |
44 | | - if (!res.ok) { |
45 | | - expect(res.issues.some((i) => i.path.includes("allowFrom"))).toBe(true); |
46 | | - } |
| 51 | + expect(res.ok).toBe(true); |
47 | 52 | }); |
| 53 | +}); |
48 | 54 |
|
49 | | - it('accepts signal dmPolicy="allowlist" with allowFrom entries', () => { |
| 55 | +describe('account dmPolicy="allowlist" uses inherited allowFrom', () => { |
| 56 | + it("accepts telegram account allowlist when parent allowFrom exists", () => { |
50 | 57 | const res = validateConfigObject({ |
51 | | - channels: { signal: { dmPolicy: "allowlist", allowFrom: ["+1234567890"] } }, |
| 58 | + channels: { |
| 59 | + telegram: { |
| 60 | + allowFrom: ["12345"], |
| 61 | + accounts: { bot1: { dmPolicy: "allowlist", botToken: "fake" } }, |
| 62 | + }, |
| 63 | + }, |
52 | 64 | }); |
53 | 65 | expect(res.ok).toBe(true); |
54 | 66 | }); |
55 | 67 |
|
56 | | - it('rejects discord dmPolicy="allowlist" without allowFrom', () => { |
| 68 | + it("rejects telegram account allowlist when neither account nor parent has allowFrom", () => { |
57 | 69 | const res = validateConfigObject({ |
58 | | - channels: { discord: { dmPolicy: "allowlist" } }, |
| 70 | + channels: { telegram: { accounts: { bot1: { dmPolicy: "allowlist", botToken: "fake" } } } }, |
59 | 71 | }); |
60 | 72 | expect(res.ok).toBe(false); |
61 | 73 | if (!res.ok) { |
62 | | - expect(res.issues.some((i) => i.path.includes("allowFrom"))).toBe(true); |
| 74 | + expect( |
| 75 | + res.issues.some((i) => i.path.includes("channels.telegram.accounts.bot1.allowFrom")), |
| 76 | + ).toBe(true); |
63 | 77 | } |
64 | 78 | }); |
65 | 79 |
|
66 | | - it('accepts discord dmPolicy="allowlist" with allowFrom entries', () => { |
| 80 | + it("accepts signal account allowlist when parent allowFrom exists", () => { |
67 | 81 | const res = validateConfigObject({ |
68 | | - channels: { discord: { dmPolicy: "allowlist", allowFrom: ["123456789"] } }, |
| 82 | + channels: { |
| 83 | + signal: { allowFrom: ["+15550001111"], accounts: { work: { dmPolicy: "allowlist" } } }, |
| 84 | + }, |
69 | 85 | }); |
70 | 86 | expect(res.ok).toBe(true); |
71 | 87 | }); |
72 | 88 |
|
73 | | - it('rejects whatsapp dmPolicy="allowlist" without allowFrom', () => { |
| 89 | + it("accepts discord account allowlist when parent allowFrom exists", () => { |
74 | 90 | const res = validateConfigObject({ |
75 | | - channels: { whatsapp: { dmPolicy: "allowlist" } }, |
| 91 | + channels: { |
| 92 | + discord: { allowFrom: ["123456789"], accounts: { work: { dmPolicy: "allowlist" } } }, |
| 93 | + }, |
76 | 94 | }); |
77 | | - expect(res.ok).toBe(false); |
78 | | - if (!res.ok) { |
79 | | - expect(res.issues.some((i) => i.path.includes("allowFrom"))).toBe(true); |
80 | | - } |
| 95 | + expect(res.ok).toBe(true); |
81 | 96 | }); |
82 | 97 |
|
83 | | - it('accepts whatsapp dmPolicy="allowlist" with allowFrom entries', () => { |
| 98 | + it("accepts slack account allowlist when parent allowFrom exists", () => { |
84 | 99 | const res = validateConfigObject({ |
85 | | - channels: { whatsapp: { dmPolicy: "allowlist", allowFrom: ["+1234567890"] } }, |
| 100 | + channels: { |
| 101 | + slack: { |
| 102 | + allowFrom: ["U123"], |
| 103 | + botToken: "xoxb-top", |
| 104 | + appToken: "xapp-top", |
| 105 | + accounts: { |
| 106 | + work: { dmPolicy: "allowlist", botToken: "xoxb-work", appToken: "xapp-work" }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
86 | 110 | }); |
87 | 111 | expect(res.ok).toBe(true); |
88 | 112 | }); |
89 | 113 |
|
90 | | - it('accepts telegram account dmPolicy="allowlist" without own allowFrom (inherits from parent)', () => { |
91 | | - // Account-level schemas skip allowFrom validation because accounts inherit |
92 | | - // allowFrom from the parent channel config at runtime. |
| 114 | + it("accepts whatsapp account allowlist when parent allowFrom exists", () => { |
93 | 115 | const res = validateConfigObject({ |
94 | 116 | channels: { |
95 | | - telegram: { |
96 | | - accounts: { |
97 | | - bot1: { dmPolicy: "allowlist", botToken: "fake" }, |
98 | | - }, |
99 | | - }, |
| 117 | + whatsapp: { allowFrom: ["+15550001111"], accounts: { work: { dmPolicy: "allowlist" } } }, |
100 | 118 | }, |
101 | 119 | }); |
102 | 120 | expect(res.ok).toBe(true); |
103 | 121 | }); |
104 | 122 |
|
105 | | - it('accepts telegram account dmPolicy="allowlist" with allowFrom entries', () => { |
| 123 | + it("accepts imessage account allowlist when parent allowFrom exists", () => { |
106 | 124 | const res = validateConfigObject({ |
107 | 125 | channels: { |
108 | | - telegram: { |
109 | | - accounts: { |
110 | | - bot1: { dmPolicy: "allowlist", allowFrom: ["12345"], botToken: "fake" }, |
111 | | - }, |
112 | | - }, |
| 126 | + imessage: { allowFrom: ["alice"], accounts: { work: { dmPolicy: "allowlist" } } }, |
| 127 | + }, |
| 128 | + }); |
| 129 | + expect(res.ok).toBe(true); |
| 130 | + }); |
| 131 | + |
| 132 | + it("accepts irc account allowlist when parent allowFrom exists", () => { |
| 133 | + const res = validateConfigObject({ |
| 134 | + channels: { irc: { allowFrom: ["nick"], accounts: { work: { dmPolicy: "allowlist" } } } }, |
| 135 | + }); |
| 136 | + expect(res.ok).toBe(true); |
| 137 | + }); |
| 138 | + |
| 139 | + it("accepts bluebubbles account allowlist when parent allowFrom exists", () => { |
| 140 | + const res = validateConfigObject({ |
| 141 | + channels: { |
| 142 | + bluebubbles: { allowFrom: ["sender"], accounts: { work: { dmPolicy: "allowlist" } } }, |
113 | 143 | }, |
114 | 144 | }); |
115 | 145 | expect(res.ok).toBe(true); |
|
0 commit comments