Skip to content

Commit

Permalink
add tests for allowedHosts
Browse files Browse the repository at this point in the history
  • Loading branch information
orteth01 committed May 3, 2017
1 parent 3eaa26e commit 5327cd8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
});
});
})
});

0 comments on commit 5327cd8

Please sign in to comment.