-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-allowlist.mjs
More file actions
88 lines (81 loc) · 2.81 KB
/
Copy pathtest-allowlist.mjs
File metadata and controls
88 lines (81 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Test the unrestricted allow-all mode.
process.chdir('C:/Users/saini/Downloads/BrowserExt');
const MOCK_PSL_TEXT = `// Mock PSL
com
net
org
io
co.uk
`;
const MOCK_DENY_CATEGORIES = {
version: '2026-06-13',
categories: {
banking: { description: 'Banking', patterns: ['chase.com'] },
identity: { description: 'Identity', patterns: ['linkedin.com', 'github.com'] }
}
};
globalThis.fetch = async (url) => {
const urlStr = String(url);
if (urlStr.includes('deny-categories')) return { ok: true, json: async () => MOCK_DENY_CATEGORIES };
if (urlStr.includes('psl')) return { ok: true, text: async () => MOCK_PSL_TEXT };
return { ok: false, status: 404 };
};
(async () => {
const { check } = await import('./lib/allowlist.js');
const { setBuiltinCategories } = await import('./lib/allowlist.js');
const { setPSLData } = await import('./lib/psl.js');
setBuiltinCategories(MOCK_DENY_CATEGORIES);
setPSLData(MOCK_PSL_TEXT);
const tests = [
{
name: 'linkedin.com blocked in default mode',
url: 'https://www.linkedin.com/in/me',
config: { mode: 'allow-all-non-blocked', allow: [], deny: [], userOverrides: {} },
expectAllow: false
},
{
name: 'linkedin.com allowed in allow-all mode',
url: 'https://www.linkedin.com/in/me',
config: { mode: 'allow-all', allow: [], deny: [], userOverrides: {} },
expectAllow: true
},
{
name: 'example.com allowed in allow-all mode',
url: 'https://example.com/foo',
config: { mode: 'allow-all', allow: [], deny: [], userOverrides: {} },
expectAllow: true
},
{
name: 'example.com blocked in allow-all mode by user deny',
url: 'https://example.com/foo',
config: { mode: 'allow-all', allow: [], deny: ['example.com'], userOverrides: {} },
expectAllow: false
},
{
name: 'github.com allowed in allow-all mode',
url: 'https://github.com/foo',
config: { mode: 'allow-all', allow: [], deny: [], userOverrides: {} },
expectAllow: true
},
{
name: 'github.com blocked in default mode',
url: 'https://github.com/foo',
config: { mode: 'allow-all-non-blocked', allow: [], deny: [], userOverrides: {} },
expectAllow: false
}
];
let pass = 0, fail = 0;
for (const t of tests) {
const r = await check(t.url, t.config);
if (r.allow === t.expectAllow) {
console.log(' PASS ' + t.name + ' (reason: ' + r.reason + ')');
pass++;
} else {
console.log(' FAIL ' + t.name + ' (expected allow=' + t.expectAllow + ', got allow=' + r.allow + ', reason=' + r.reason + ')');
fail++;
}
}
console.log('');
console.log('Results: ' + pass + ' passed, ' + fail + ' failed');
process.exit(fail > 0 ? 1 : 0);
})().catch(e => { console.error('TEST ERROR:', e); console.error(e.stack); process.exit(1); });