Skip to content

Commit 3715802

Browse files
Mossakaclaude
andauthored
test: add --block-domains integration tests (#1051)
* test: add --block-domains integration tests Add blockDomains option to AwfRunner test fixture and integration tests for the --block-domains deny-list feature: - Block specific subdomain while allowing parent domain - Block takes precedence over allow - Wildcard blocking patterns (*.github.com) - Multiple blocked domains - Debug output verification Closes #1041 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: verify both blocked domains in multiple-domains test Address Copilot review: test both api.github.com and raw.githubusercontent.com are blocked, and add githubusercontent.com to allowDomains so the blocklist (not the allowlist) is what blocks them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c2ebc6d commit 3715802

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

tests/fixtures/awf-runner.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type ExecaReturnValue = execa.ExecaReturnValue<string>;
55

66
export interface AwfOptions {
77
allowDomains?: string[];
8+
blockDomains?: string[];
89
keepContainers?: boolean;
910
logLevel?: 'debug' | 'info' | 'warn' | 'error';
1011
buildLocal?: boolean;
@@ -52,6 +53,11 @@ export class AwfRunner {
5253
args.push('--allow-domains', options.allowDomains.join(','));
5354
}
5455

56+
// Add block-domains
57+
if (options.blockDomains && options.blockDomains.length > 0) {
58+
args.push('--block-domains', options.blockDomains.join(','));
59+
}
60+
5561
// Add other flags
5662
if (options.keepContainers) {
5763
args.push('--keep-containers');
@@ -206,6 +212,11 @@ export class AwfRunner {
206212
args.push('--allow-domains', options.allowDomains.join(','));
207213
}
208214

215+
// Add block-domains
216+
if (options.blockDomains && options.blockDomains.length > 0) {
217+
args.push('--block-domains', options.blockDomains.join(','));
218+
}
219+
209220
// Add other flags
210221
if (options.keepContainers) {
211222
args.push('--keep-containers');

tests/integration/blocked-domains.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,100 @@ describe('Domain Allowlist Edge Cases', () => {
183183
expect(result.stdout).toMatch(/blocked|error|fail/i);
184184
}, 120000);
185185
});
186+
187+
describe('Block Domains Deny-List (--block-domains)', () => {
188+
let runner: AwfRunner;
189+
190+
beforeAll(async () => {
191+
await cleanup(false);
192+
runner = createRunner();
193+
});
194+
195+
afterAll(async () => {
196+
await cleanup(false);
197+
});
198+
199+
test('should block specific subdomain while allowing parent domain', async () => {
200+
const result = await runner.runWithSudo(
201+
'curl -f --max-time 10 https://api.github.com/zen',
202+
{
203+
allowDomains: ['github.com'],
204+
blockDomains: ['api.github.com'],
205+
logLevel: 'debug',
206+
timeout: 60000,
207+
}
208+
);
209+
expect(result).toFail();
210+
}, 120000);
211+
212+
test('should still allow non-blocked subdomains when parent is allowed', async () => {
213+
const result = await runner.runWithSudo(
214+
'curl -f --max-time 10 https://github.com',
215+
{
216+
allowDomains: ['github.com'],
217+
blockDomains: ['api.github.com'],
218+
logLevel: 'debug',
219+
timeout: 60000,
220+
}
221+
);
222+
expect(result).toSucceed();
223+
}, 120000);
224+
225+
test('should block domain that is also in the allow list (block takes precedence)', async () => {
226+
const result = await runner.runWithSudo(
227+
'curl -f --max-time 5 https://example.com',
228+
{
229+
allowDomains: ['example.com'],
230+
blockDomains: ['example.com'],
231+
logLevel: 'debug',
232+
timeout: 60000,
233+
}
234+
);
235+
expect(result).toFail();
236+
}, 120000);
237+
238+
test('should block wildcard pattern while allowing parent domain', async () => {
239+
const result = await runner.runWithSudo(
240+
'curl -f --max-time 10 https://api.github.com/zen',
241+
{
242+
allowDomains: ['github.com'],
243+
blockDomains: ['*.github.com'],
244+
logLevel: 'debug',
245+
timeout: 60000,
246+
}
247+
);
248+
expect(result).toFail();
249+
}, 120000);
250+
251+
test('should handle multiple blocked domains', async () => {
252+
const result = await runner.runWithSudo(
253+
'bash -c "' +
254+
'curl -f --max-time 10 https://api.github.com/zen 2>&1; api_exit=$?; ' +
255+
'curl -f --max-time 10 https://raw.githubusercontent.com 2>&1; raw_exit=$?; ' +
256+
'echo api_exit=$api_exit raw_exit=$raw_exit"',
257+
{
258+
allowDomains: ['github.com', 'githubusercontent.com'],
259+
blockDomains: ['api.github.com', 'raw.githubusercontent.com'],
260+
logLevel: 'debug',
261+
timeout: 60000,
262+
}
263+
);
264+
// Both blocked domains should fail even though their parent domains are allowed
265+
expect(result.stdout).not.toContain('api_exit=0');
266+
expect(result.stdout).not.toContain('raw_exit=0');
267+
}, 120000);
268+
269+
test('should show blocked domains in debug output', async () => {
270+
const result = await runner.runWithSudo(
271+
'echo "test"',
272+
{
273+
allowDomains: ['github.com'],
274+
blockDomains: ['api.github.com'],
275+
logLevel: 'debug',
276+
timeout: 60000,
277+
}
278+
);
279+
expect(result).toSucceed();
280+
expect(result.stderr).toMatch(/[Bb]locked domains:/i);
281+
}, 120000);
282+
});

0 commit comments

Comments
 (0)