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 Jun 14, 2017
1 parent 8eb8585 commit e989ccd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,43 @@ describe("Validation", function() {
throw new Error("Validation didn't fail");
}
});

describe("allowedHosts", function() {
it("should allow hosts in allowedHosts", function() {
const testHosts = [
"test.host",
"test2.host",
"test3.host"
];
const options = { allowedHosts: testHosts };
const server = new Server(compiler, options);

testHosts.forEach(function(testHost) {
const headers = { host: testHost };
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});
});
it("should allow hosts that pass a wildcard in allowedHosts", function() {
const options = { allowedHosts: [".example.com"] };
const server = new Server(compiler, options);
const testHosts = [
"www.example.com",
"subdomain.example.com",
"example.com",
"subsubcomain.subdomain.example.com",
"example.com:80",
"subdomain.example.com:80"
];

testHosts.forEach(function(testHost) {
const headers = { host: testHost };
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});
});
});
})
});

0 comments on commit e989ccd

Please sign in to comment.