Index: test/url.js |
=================================================================== |
rename from test/domain.js |
rename to test/url.js |
--- a/test/domain.js |
+++ b/test/url.js |
@@ -20,28 +20,28 @@ |
// Only starting NodeJS 10 that URL is in the global space. |
const {URL} = require("url"); |
const {createSandbox} = require("./_common"); |
const publicSuffixes = require("../data/publicSuffixList.json"); |
let normalizeHostname = null; |
let isThirdParty = null; |
-let getDomain = null; |
+let getBaseDomain = null; |
exports.setUp = function(callback) |
{ |
let sandboxedRequire = createSandbox({ |
extraExports: { |
- domain: ["getDomain"] |
+ domain: ["getBaseDomain"] |
} |
}); |
( |
{normalizeHostname, isThirdParty, |
- getDomain} = sandboxedRequire("../lib/domain") |
+ getBaseDomain} = sandboxedRequire("../lib/url") |
); |
callback(); |
}; |
function hostnameToURL(hostname) |
{ |
return new URL("http://" + hostname); |
@@ -151,17 +151,17 @@ |
testThirdParty(test, "xn--f-1gaa.com", "f\u00f6\u00f6.com", false, |
"same IDN isn't third-party"); |
testThirdParty(test, "example.com..", "example.com....", false, |
"traling dots are ignored"); |
test.done(); |
}; |
-exports.testGetDomain = function(test) |
+exports.testGetBaseDomain = function(test) |
{ |
let parts = ["aaa", "bbb", "ccc", "ddd", "eee"]; |
let levels = 3; |
for (let suffix in publicSuffixes) |
{ |
let offset = publicSuffixes[suffix]; |
@@ -172,40 +172,43 @@ |
for (let i = 0; i < offset + levels; i++) |
{ |
let hostname = parts.slice(0, i).join("."); |
hostname += (hostname ? "." : "") + suffix; |
let expected = parts.slice(Math.max(0, i - offset), i).join("."); |
expected += (expected ? "." : "") + suffix; |
- test.equal(getDomain(hostname), expected, |
- `getDomain("${hostname}") == "${expected}"` + |
+ test.equal(getBaseDomain(hostname), expected, |
+ `getBaseDomain("${hostname}") == "${expected}"` + |
` with {suffix: "${suffix}", offset: ${offset}}`); |
} |
} |
// Unknown suffixes. |
test.equal(typeof publicSuffixes["localhost"], "undefined"); |
test.equal(typeof publicSuffixes["localhost.localdomain"], "undefined"); |
- test.equal(getDomain("localhost"), "localhost"); |
- test.equal(getDomain("localhost.localdomain"), "localhost.localdomain"); |
- test.equal(getDomain("mail.localhost.localdomain"), "localhost.localdomain"); |
- test.equal(getDomain("www.example.localhost.localdomain"), |
+ test.equal(getBaseDomain("localhost"), "localhost"); |
+ test.equal(getBaseDomain("localhost.localdomain"), "localhost.localdomain"); |
+ test.equal( |
+ getBaseDomain("mail.localhost.localdomain"), |
+ "localhost.localdomain" |
+ ); |
+ test.equal(getBaseDomain("www.example.localhost.localdomain"), |
"localhost.localdomain"); |
// Unknown suffixes that overlap partly with known suffixes. |
test.equal(typeof publicSuffixes["example.com"], "undefined"); |
test.equal(typeof publicSuffixes["africa.com"], "number"); |
test.equal(typeof publicSuffixes["compute.amazonaws.com"], "number"); |
- test.equal(getDomain("example.com"), "example.com"); |
- test.equal(getDomain("mail.example.com"), "example.com"); |
- test.equal(getDomain("secure.mail.example.com"), "example.com"); |
+ test.equal(getBaseDomain("example.com"), "example.com"); |
+ test.equal(getBaseDomain("mail.example.com"), "example.com"); |
+ test.equal(getBaseDomain("secure.mail.example.com"), "example.com"); |
// Cascading offsets. |
// If these sanity checks fail, look for other examles of cascading offsets |
// from the public suffix list. |
test.equal( |
typeof publicSuffixes[ |
"images.example.s3.dualstack.us-east-1.amazonaws.com" |
@@ -220,27 +223,32 @@ |
test.equal(typeof publicSuffixes["dualstack.us-east-1.amazonaws.com"], |
"undefined"); |
test.equal(typeof publicSuffixes["example.us-east-1.amazonaws.com"], |
"undefined"); |
test.equal(publicSuffixes["us-east-1.amazonaws.com"], 1); |
test.equal(typeof publicSuffixes["example.amazonaws.com"], "undefined"); |
test.equal(typeof publicSuffixes["amazonaws.com"], "undefined"); |
- test.equal(getDomain("images.example.s3.dualstack.us-east-1.amazonaws.com"), |
+ test.equal( |
+ getBaseDomain("images.example.s3.dualstack.us-east-1.amazonaws.com"), |
+ "example.s3.dualstack.us-east-1.amazonaws.com" |
+ ); |
+ test.equal(getBaseDomain("example.s3.dualstack.us-east-1.amazonaws.com"), |
"example.s3.dualstack.us-east-1.amazonaws.com"); |
- test.equal(getDomain("example.s3.dualstack.us-east-1.amazonaws.com"), |
- "example.s3.dualstack.us-east-1.amazonaws.com"); |
- test.equal(getDomain("s3.dualstack.us-east-1.amazonaws.com"), |
+ test.equal(getBaseDomain("s3.dualstack.us-east-1.amazonaws.com"), |
"s3.dualstack.us-east-1.amazonaws.com"); |
- test.equal(getDomain("dualstack.us-east-1.amazonaws.com"), |
+ test.equal(getBaseDomain("dualstack.us-east-1.amazonaws.com"), |
"dualstack.us-east-1.amazonaws.com"); |
- test.equal(getDomain("example.us-east-1.amazonaws.com"), |
+ test.equal(getBaseDomain("example.us-east-1.amazonaws.com"), |
"example.us-east-1.amazonaws.com"); |
- test.equal(getDomain("us-east-1.amazonaws.com"), "us-east-1.amazonaws.com"); |
- test.equal(getDomain("example.amazonaws.com"), "amazonaws.com"); |
- test.equal(getDomain("amazonaws.com"), "amazonaws.com"); |
+ test.equal( |
+ getBaseDomain("us-east-1.amazonaws.com"), |
+ "us-east-1.amazonaws.com" |
+ ); |
+ test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com"); |
+ test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com"); |
// Edge case. |
- test.equal(getDomain(""), ""); |
+ test.equal(getBaseDomain(""), ""); |
test.done(); |
}; |