Skip to content

Commit

Permalink
Added tests for Server.prototype.checkHost
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Trachtman committed Apr 25, 2017
1 parent 9688eea commit f26f985
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/Validation.test.js
Expand Up @@ -61,4 +61,59 @@ describe("Validation", function() {
throw new Error("Validation didn't fail");
})
});

describe("checkHost", function() {
it("should always allow any host if options.disableHostCheck is set", function() {
const options = {
public: "test.host:80",
disableHostCheck: true
};
const headers = {
host: "bad.host"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should allow any valid options.public when host is localhost", function() {
const options = {
public: "test.host:80"
};
const headers = {
host: "localhost"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should allow any valid options.public when host is 127.0.0.1", function() {
const options = {
public: "test.host:80"
};
const headers = {
host: "127.0.0.1"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should not allow hostnames that don't match options.public", function() {
const options = {
public: "test.host:80",
};
const headers = {
host: "test.hostname:80"
};
const server = new Server(compiler, options);
if(server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});
})
});

0 comments on commit f26f985

Please sign in to comment.