Skip to content

Commit 5327cd8

Browse files
committed
add tests for allowedHosts
1 parent 3eaa26e commit 5327cd8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: test/Validation.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,36 @@ describe("Validation", function() {
123123
throw new Error("Validation didn't fail");
124124
}
125125
});
126+
127+
describe("allowedHosts", function() {
128+
it("should allow hosts in allowedHosts", function() {
129+
const options = { allowedHosts: ["test.host"] };
130+
const headers = { host: "test.host:80" };
131+
const server = new Server(compiler, options);
132+
if(!server.checkHost(headers)) {
133+
throw new Error("Validation didn't fail");
134+
}
135+
});
136+
it("should return true if host passes a wildcard in allowedHosts", function() {
137+
const options = { allowedHosts: [".example.com"] };
138+
const server = new Server(compiler, options);
139+
const testDomains = [
140+
"www.example.com",
141+
"subdomain.example.com",
142+
"example.com",
143+
"subsubcomain.subdomain.example.com",
144+
"example.com:80",
145+
"subdomain.example.com:80"
146+
];
147+
148+
let headers;
149+
testDomains.forEach(function(testDomain) {
150+
headers = { host: testDomain };
151+
if(!server.checkHost(headers)) {
152+
throw new Error("Validation didn't fail");
153+
}
154+
});
155+
});
156+
});
126157
})
127158
});

0 commit comments

Comments
 (0)