summaryrefslogtreecommitdiffstats
path: root/net/adblock-fast/tests/01_pipeline/08_ipv6_nftset
blob: 1c36d1786f7897ed422425355109049ff6394360 (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
Test that dnsmasq.nftset with ipv6_enabled includes IPv6 set reference.

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

adb.env.load_config();
ti.set_cfg('dns', 'dnsmasq.nftset');
ti.set_cfg('ipv6_enabled', true);
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.nftset');
ti.append_urls();

let ok = ti.download_lists();
if (!ok) {
	print('download_lists failed\n');
} else {
	let content = readfile(ti.dns_output.file) || '';
	let lines = filter(split(content, '\n'), l => length(l) > 0);

	// With IPv6 enabled, nftset format should include ,6#inet#fw4#adb6
	let ipv6_lines = filter(lines, l => match(l, /6#inet#fw4#adb6/));
	let ipv4_only = filter(lines, l => match(l, /4#inet#fw4#adb4/) && !match(l, /6#inet#fw4#adb6/));

	let results = [];
	push(results, sprintf('total_lines: %d', length(lines)));
	push(results, sprintf('with_ipv6_set: %d', length(ipv6_lines)));
	push(results, sprintf('ipv4_only: %d', length(ipv4_only)));

	// All lines should have both IPv4 and IPv6 set references
	push(results, sprintf('all_dual_stack: %s', (length(ipv6_lines) == length(lines)) ? 'YES' : 'NO'));

	// Spot-check format
	let test_domain = 'ad.doubleclick.test.example.com';
	let expected = 'nftset=/' + test_domain + '/4#inet#fw4#adb4,6#inet#fw4#adb6';
	let has_entry = index(content, expected) >= 0;
	push(results, sprintf('correct_format: %s', has_entry ? 'YES' : 'NO'));

	print(join('\n', results) + '\n');
}
-- End --

-- Expect stdout --
total_lines: 162
with_ipv6_set: 162
ipv4_only: 0
all_dual_stack: YES
correct_format: YES
-- End --