summaryrefslogtreecommitdiffstats
path: root/net/adblock-fast/tests/01_pipeline/03_subdomain_dedup
blob: b0fde8790ddf26de07c65cbdaba137a398ba574b (plain)
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
Test that subdomain dedup removes child domains when parent exists.
Parent domains are in domains.txt, children are in hosts.txt.

-- Testcase --
import adb from 'adblock-fast';
import { readfile } from 'fs';
let ti = adb._test_internals;

adb.env.load_config();
ti.set_cfg('dns', 'dnsmasq.servers');
ti.set_cfg('dnsmasq_sanity_check', false);
ti.set_cfg('dnsmasq_validity_check', false);
ti.set_cfg('heartbeat_domain', null);
ti.set_cfg('config_update_enabled', false);
ti.set_cfg('update_config_sizes', false);
ti.env.dns_set_output_values('dnsmasq.servers');
ti.append_urls();

let ok = ti.download_lists();
if (!ok) {
	print('download_lists failed\n');
} else {
	let content = readfile(ti.dns_output.file) || '';

	// Parents must exist
	let parents = [
		'parent-dedup-1.test.example.com',
		'parent-dedup-2.test.example.com',
		'parent-dedup-3.test.example.com',
	];
	// Children must be removed
	let children = [
		'child.parent-dedup-1.test.example.com',
		'sub.child.parent-dedup-2.test.example.com',
		'deep.sub.parent-dedup-3.test.example.com',
	];

	let results = [];
	for (let p in parents) {
		let found = index(content, 'server=/' + p + '/') >= 0;
		push(results, sprintf('parent %s: %s', p, found ? 'PRESENT' : 'MISSING'));
	}
	for (let c in children) {
		let found = index(content, 'server=/' + c + '/') >= 0;
		push(results, sprintf('child %s: %s', c, found ? 'PRESENT (BAD)' : 'REMOVED'));
	}
	print(join('\n', results) + '\n');
}
-- End --

-- Expect stdout --
parent parent-dedup-1.test.example.com: PRESENT
parent parent-dedup-2.test.example.com: PRESENT
parent parent-dedup-3.test.example.com: PRESENT
child child.parent-dedup-1.test.example.com: REMOVED
child sub.child.parent-dedup-2.test.example.com: REMOVED
child deep.sub.parent-dedup-3.test.example.com: REMOVED
-- End --