| 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 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 let expected = parts.slice(Math.max(0, i - offset), i).join("."); | 151 let expected = parts.slice(Math.max(0, i - offset), i).join("."); |
| 152 expected += (expected ? "." : "") + suffix; | 152 expected += (expected ? "." : "") + suffix; |
| 153 | 153 |
| 154 test.equal(getDomain(hostname), expected, | 154 test.equal(getDomain(hostname), expected, |
| 155 `getDomain("${hostname}") == "${expected}"` + | 155 `getDomain("${hostname}") == "${expected}"` + |
| 156 ` with {suffix: "${suffix}", offset: ${offset}}`); | 156 ` with {suffix: "${suffix}", offset: ${offset}}`); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Test unknown suffixes. | 160 // Unknown suffixes. |
| 161 test.equal(typeof publicSuffixes["localhost"], "undefined"); | 161 test.equal(typeof publicSuffixes["localhost"], "undefined"); |
| 162 test.equal(typeof publicSuffixes["localhost.localdomain"], "undefined"); | 162 test.equal(typeof publicSuffixes["localhost.localdomain"], "undefined"); |
| 163 | 163 |
| 164 test.equal(getDomain("localhost"), "localhost"); | 164 test.equal(getDomain("localhost"), "localhost"); |
| 165 test.equal(getDomain("localhost.localdomain"), "localhost.localdomain"); | 165 test.equal(getDomain("localhost.localdomain"), "localhost.localdomain"); |
| 166 test.equal(getDomain("mail.localhost.localdomain"), "localhost.localdomain"); | 166 test.equal(getDomain("mail.localhost.localdomain"), "localhost.localdomain"); |
| 167 test.equal(getDomain("www.example.localhost.localdomain"), | 167 test.equal(getDomain("www.example.localhost.localdomain"), |
| 168 "localhost.localdomain"); | 168 "localhost.localdomain"); |
| 169 | 169 |
| 170 // Test unknown suffixes that overlap partly with known suffixes. | 170 // Unknown suffixes that overlap partly with known suffixes. |
| 171 test.equal(typeof publicSuffixes["example.com"], "undefined"); | 171 test.equal(typeof publicSuffixes["example.com"], "undefined"); |
| 172 test.equal(typeof publicSuffixes["africa.com"], "number"); | 172 test.equal(typeof publicSuffixes["africa.com"], "number"); |
| 173 test.equal(typeof publicSuffixes["compute.amazonaws.com"], "number"); | 173 test.equal(typeof publicSuffixes["compute.amazonaws.com"], "number"); |
| 174 | 174 |
| 175 test.equal(getDomain("example.com"), "example.com"); | 175 test.equal(getDomain("example.com"), "example.com"); |
| 176 test.equal(getDomain("mail.example.com"), "example.com"); | 176 test.equal(getDomain("mail.example.com"), "example.com"); |
| 177 test.equal(getDomain("secure.mail.example.com"), "example.com"); | 177 test.equal(getDomain("secure.mail.example.com"), "example.com"); |
| 178 | 178 |
| 179 // Cascading offsets. |
| 180 |
| 181 // If these sanity checks fail, look for other examles of cascading offsets |
| 182 // from the public suffix list. |
| 183 test.equal( |
| 184 typeof publicSuffixes[ |
| 185 "images.example.s3.dualstack.us-east-1.amazonaws.com" |
| 186 ], |
| 187 "undefined" |
| 188 ); |
| 189 test.equal( |
| 190 typeof publicSuffixes["example.s3.dualstack.us-east-1.amazonaws.com"], |
| 191 "undefined" |
| 192 ); |
| 193 test.equal(publicSuffixes["s3.dualstack.us-east-1.amazonaws.com"], 1); |
| 194 test.equal(typeof publicSuffixes["dualstack.us-east-1.amazonaws.com"], |
| 195 "undefined"); |
| 196 test.equal(typeof publicSuffixes["example.us-east-1.amazonaws.com"], |
| 197 "undefined"); |
| 198 test.equal(publicSuffixes["us-east-1.amazonaws.com"], 1); |
| 199 test.equal(typeof publicSuffixes["example.amazonaws.com"], "undefined"); |
| 200 test.equal(typeof publicSuffixes["amazonaws.com"], "undefined"); |
| 201 |
| 202 test.equal(getDomain("images.example.s3.dualstack.us-east-1.amazonaws.com"), |
| 203 "example.s3.dualstack.us-east-1.amazonaws.com"); |
| 204 test.equal(getDomain("example.s3.dualstack.us-east-1.amazonaws.com"), |
| 205 "example.s3.dualstack.us-east-1.amazonaws.com"); |
| 206 test.equal(getDomain("s3.dualstack.us-east-1.amazonaws.com"), |
| 207 "s3.dualstack.us-east-1.amazonaws.com"); |
| 208 test.equal(getDomain("dualstack.us-east-1.amazonaws.com"), |
| 209 "dualstack.us-east-1.amazonaws.com"); |
| 210 test.equal(getDomain("example.us-east-1.amazonaws.com"), |
| 211 "example.us-east-1.amazonaws.com"); |
| 212 test.equal(getDomain("us-east-1.amazonaws.com"), "us-east-1.amazonaws.com"); |
| 213 test.equal(getDomain("example.amazonaws.com"), "amazonaws.com"); |
| 214 test.equal(getDomain("amazonaws.com"), "amazonaws.com"); |
| 215 |
| 216 // Edge case. |
| 179 test.equal(getDomain(""), ""); | 217 test.equal(getDomain(""), ""); |
| 180 | 218 |
| 181 test.done(); | 219 test.done(); |
| 182 }; | 220 }; |
| LEFT | RIGHT |