Skip to content

Commit f26f985

Browse files
author
Aaron Trachtman
committed
Added tests for Server.prototype.checkHost
1 parent 9688eea commit f26f985

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/Validation.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,59 @@ describe("Validation", function() {
6161
throw new Error("Validation didn't fail");
6262
})
6363
});
64+
65+
describe("checkHost", function() {
66+
it("should always allow any host if options.disableHostCheck is set", function() {
67+
const options = {
68+
public: "test.host:80",
69+
disableHostCheck: true
70+
};
71+
const headers = {
72+
host: "bad.host"
73+
};
74+
const server = new Server(compiler, options);
75+
if(!server.checkHost(headers)) {
76+
throw new Error("Validation didn't fail");
77+
}
78+
});
79+
80+
it("should allow any valid options.public when host is localhost", function() {
81+
const options = {
82+
public: "test.host:80"
83+
};
84+
const headers = {
85+
host: "localhost"
86+
};
87+
const server = new Server(compiler, options);
88+
if(!server.checkHost(headers)) {
89+
throw new Error("Validation didn't fail");
90+
}
91+
});
92+
93+
it("should allow any valid options.public when host is 127.0.0.1", function() {
94+
const options = {
95+
public: "test.host:80"
96+
};
97+
const headers = {
98+
host: "127.0.0.1"
99+
};
100+
const server = new Server(compiler, options);
101+
if(!server.checkHost(headers)) {
102+
throw new Error("Validation didn't fail");
103+
}
104+
});
105+
106+
it("should not allow hostnames that don't match options.public", function() {
107+
const options = {
108+
public: "test.host:80",
109+
};
110+
const headers = {
111+
host: "test.hostname:80"
112+
};
113+
const server = new Server(compiler, options);
114+
if(server.checkHost(headers)) {
115+
throw new Error("Validation didn't fail");
116+
}
117+
});
118+
})
64119
});

0 commit comments

Comments
 (0)