LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 { | 20 { |
21 const {isThirdParty} = require("../../adblockpluscore/lib/domain"); | |
22 const {extractHostFromFrame} = require("../../lib/url"); | 21 const {extractHostFromFrame} = require("../../lib/url"); |
23 const {platform} = require("info"); | 22 const {platform} = require("info"); |
24 | 23 |
25 QUnit.module("URL/host tools"); | 24 QUnit.module("URL/host tools"); |
26 | 25 |
27 test("Extracting hostname from frame", () => | 26 test("Extracting hostname from frame", () => |
28 { | 27 { |
29 function testFrameHostname(hierarchy, expectedHostname, message) | 28 function testFrameHostname(hierarchy, expectedHostname, message) |
30 { | 29 { |
31 let frame = null; | 30 let frame = null; |
(...skipping 21 matching lines...) Expand all Loading... |
53 // with punycode: https://developer.microsoft.com/en-us/microsoft-edge/platf
orm/issues/18861990/ | 52 // with punycode: https://developer.microsoft.com/en-us/microsoft-edge/platf
orm/issues/18861990/ |
54 // with auth credentials: https://developer.microsoft.com/en-us/microsoft-ed
ge/platform/issues/8004284/ | 53 // with auth credentials: https://developer.microsoft.com/en-us/microsoft-ed
ge/platform/issues/8004284/ |
55 if (platform != "edgehtml") | 54 if (platform != "edgehtml") |
56 { | 55 { |
57 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", | 56 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", |
58 "with punycode"); | 57 "with punycode"); |
59 testFrameHostname(["http://user:password@example.com/"], "example.com", | 58 testFrameHostname(["http://user:password@example.com/"], "example.com", |
60 "with auth credentials"); | 59 "with auth credentials"); |
61 } | 60 } |
62 }); | 61 }); |
63 | |
64 test("Third-party checks", () => | |
65 { | |
66 function hostnameToURL(hostname) | |
67 { | |
68 return new URL("http://" + hostname); | |
69 } | |
70 | |
71 function testThirdParty(requestHost, documentHost, expected, message) | |
72 { | |
73 equal( | |
74 isThirdParty( | |
75 hostnameToURL(requestHost), | |
76 | |
77 // Chrome's URL object normalizes IP addresses. So some test | |
78 // will fail if we don't normalize the document host as well. | |
79 hostnameToURL(documentHost).hostname | |
80 ), | |
81 expected, | |
82 message | |
83 ); | |
84 } | |
85 | |
86 testThirdParty("foo", "foo", false, "same domain isn't third-party"); | |
87 testThirdParty("foo", "bar", true, "different domain is third-party"); | |
88 testThirdParty("foo.com", "foo.com", false, | |
89 "same domain with TLD (.com) isn't third-party"); | |
90 testThirdParty("foo.com", "bar.com", true, | |
91 "same TLD (.com) but different domain is third-party"); | |
92 testThirdParty("foo.com", "www.foo.com", false, | |
93 "same domain but differend subdomain isn't third-party"); | |
94 testThirdParty("foo.example.com", "bar.example.com", false, | |
95 "same basedomain (example.com) isn't third-party"); | |
96 testThirdParty("foo.uk", "bar.uk", true, | |
97 "same TLD (.uk) but different domain is third-party"); | |
98 testThirdParty("foo.co.uk", "bar.co.uk", true, | |
99 "same TLD (.co.uk) but different domain is third-party"); | |
100 testThirdParty("foo.example.co.uk", "bar.example.co.uk", false, | |
101 "same basedomain (example.co.uk) isn't third-party"); | |
102 testThirdParty("1.2.3.4", "1.2.3.4", false, | |
103 "same IPv4 address isn't third-party"); | |
104 testThirdParty("1.1.1.1", "2.1.1.1", true, | |
105 "different IPv4 address is third-party"); | |
106 testThirdParty("0x01ff0101", "0x01ff0101", false, | |
107 "same IPv4 hexadecimal address isn't third-party"); | |
108 testThirdParty("0x01ff0101", "0x01ff0102", true, | |
109 "different IPv4 hexadecimal address is third-party"); | |
110 testThirdParty( | |
111 "1.0xff.3.4", "1.0xff.3.4", false, | |
112 "same IPv4 address with hexadecimal octet isn't third-party" | |
113 ); | |
114 testThirdParty( | |
115 "1.0xff.1.1", "2.0xff.1.1", true, | |
116 "different IPv4 address with hexadecimal octet is third-party" | |
117 ); | |
118 testThirdParty( | |
119 "0xff.example.com", "example.com", false, | |
120 "domain starts like a hexadecimal IPv4 address but isn't one" | |
121 ); | |
122 testThirdParty( | |
123 "[2001:db8:85a3::8a2e:370:7334]", "[2001:db8:85a3::8a2e:370:7334]", false, | |
124 "same IPv6 address isn't third-party" | |
125 ); | |
126 testThirdParty( | |
127 "[2001:db8:85a3::8a2e:370:7334]", "[5001:db8:85a3::8a2e:370:7334]", true, | |
128 "different IPv6 address is third-party" | |
129 ); | |
130 testThirdParty( | |
131 "[::ffff:192.0.2.128]", "[::ffff:192.0.2.128]", false, | |
132 "same IPv4-mapped IPv6 address isn't third-party" | |
133 ); | |
134 testThirdParty( | |
135 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, | |
136 "different IPv4-mapped IPv6 address is third-party" | |
137 ); | |
138 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, | |
139 "same IDN isn't third-party"); | |
140 testThirdParty("example.com..", "example.com....", false, | |
141 "traling dots are ignored"); | |
142 }); | |
143 } | 62 } |
LEFT | RIGHT |