diff --git a/test/Validation.test.js b/test/Validation.test.js index bf2ae96f51..fbfd9e1a01 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -123,5 +123,36 @@ describe("Validation", function() { throw new Error("Validation didn't fail"); } }); + + describe("allowedHosts", function() { + it("should allow hosts in allowedHosts", function() { + const options = { allowedHosts: ["test.host"] }; + const headers = { host: "test.host:80" }; + const server = new Server(compiler, options); + if(!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); + it("should return true if host passes a wildcard in allowedHosts", function() { + const options = { allowedHosts: [".example.com"] }; + const server = new Server(compiler, options); + const testDomains = [ + "www.example.com", + "subdomain.example.com", + "example.com", + "subsubcomain.subdomain.example.com", + "example.com:80", + "subdomain.example.com:80" + ]; + + let headers; + testDomains.forEach(function(testDomain) { + headers = { host: testDomain }; + if(!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); + }); + }); }) });