Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/vatican.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Vatican.prototype.parseHandlers = function(cb) {
Makes sure that the required options are there
*/
Vatican.prototype.checkOptions = function() {
if( !this.options.port ) {
logger.error("Port not specified, throwing error!");
throw new Error("Port not specified");
if( !(typeof this.options.port == 'number' && this.options.port >= 0 && this.options.port <= 65535)) {
logger.error("Port must be a number from the range [0, 65535], throwing error!");
throw new Error("Port must be a number from the range [0, 65535]");
}

if( !this.options.handlers ) {
Expand Down
31 changes: 30 additions & 1 deletion test/vatican.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,40 @@ describe("Vatican methods", function() {
var matchFound = null

describe("@checkOptions", function(){
var portErrorMessage = "Port must be a number from the range [0, 65535]";

it("should throw an error if no port is specified", function() {
(function() {
v = new Vatican({handlers: ''})
}).should.throw("Port not specified")
}).should.throw(portErrorMessage)
})

it("should throw an error if port is not a number", function() {
(function() {
v = new Vatican({handlers: '', port: '88'})
}).should.throw(portErrorMessage)
});

it("should throw an error if port is a negative number", function() {
(function() {
v = new Vatican({handlers: '', port: -1})
}).should.throw(portErrorMessage)
});

it("should throw an error if port is greater than 65535", function() {
(function() {
v = new Vatican({handlers: '', port: 65536})
}).should.throw(portErrorMessage)
});

it("should be ok for a port number from range [0, 65536]", function() {
(function() {
v = new Vatican({handlers: '', port: 65536})
}).should.throw(portErrorMessage)
});



it("should throw an error if no handlers folder is specified", function() {
(function() {
v = new Vatican({port: 123})
Expand Down