Skip to content

Commit 7da42ca

Browse files
authored
refactor: deduplicate SSL-Bump fixture in squid-config-security tests (#3480)
* Initial plan * refactor: deduplicate sslBumpBase fixture in security tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 4d096dc commit 7da42ca

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

src/squid-config-security.test.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { SquidConfig } from './types';
44
describe('defense-in-depth: rejects injected values', () => {
55
const defaultPort = 3128;
66

7+
const sslBumpBase = {
8+
domains: ['evil.com'],
9+
port: defaultPort,
10+
sslBump: true as const,
11+
caFiles: { certPath: '/tmp/cert.pem', keyPath: '/tmp/key.pem' },
12+
sslDbPath: '/tmp/ssl_db',
13+
} satisfies Partial<Parameters<typeof generateSquidConfig>[0]>;
14+
715
it('should reject newline in domain via validateDomainOrPattern', () => {
816
expect(() => {
917
generateSquidConfig({
@@ -18,42 +26,21 @@ describe('defense-in-depth: rejects injected values', () => {
1826
// The assertSafeForSquidConfig guard should catch this.
1927
const maliciousPattern = 'https://evil.com/path\nhttp_access allow all';
2028
expect(() => {
21-
generateSquidConfig({
22-
domains: ['evil.com'],
23-
port: defaultPort,
24-
sslBump: true,
25-
caFiles: { certPath: '/tmp/cert.pem', keyPath: '/tmp/key.pem' },
26-
sslDbPath: '/tmp/ssl_db',
27-
urlPatterns: [maliciousPattern],
28-
});
29+
generateSquidConfig({ ...sslBumpBase, urlPatterns: [maliciousPattern] });
2930
}).toThrow(/SECURITY/);
3031
});
3132

3233
it('should reject hash character in URL pattern (Squid comment injection)', () => {
3334
const maliciousPattern = 'https://evil.com/path#http_access allow all';
3435
expect(() => {
35-
generateSquidConfig({
36-
domains: ['evil.com'],
37-
port: defaultPort,
38-
sslBump: true,
39-
caFiles: { certPath: '/tmp/cert.pem', keyPath: '/tmp/key.pem' },
40-
sslDbPath: '/tmp/ssl_db',
41-
urlPatterns: [maliciousPattern],
42-
});
36+
generateSquidConfig({ ...sslBumpBase, urlPatterns: [maliciousPattern] });
4337
}).toThrow(/SECURITY/);
4438
});
4539

4640
it('should reject semicolon in URL pattern (Squid token injection)', () => {
4741
const maliciousPattern = 'https://evil.com/path;injected';
4842
expect(() => {
49-
generateSquidConfig({
50-
domains: ['evil.com'],
51-
port: defaultPort,
52-
sslBump: true,
53-
caFiles: { certPath: '/tmp/cert.pem', keyPath: '/tmp/key.pem' },
54-
sslDbPath: '/tmp/ssl_db',
55-
urlPatterns: [maliciousPattern],
56-
});
43+
generateSquidConfig({ ...sslBumpBase, urlPatterns: [maliciousPattern] });
5744
}).toThrow(/SECURITY/);
5845
});
5946

0 commit comments

Comments
 (0)