From f5b46c0c53d0701069125179639c6f0b60a60a64 Mon Sep 17 00:00:00 2001 From: petea Date: Fri, 3 Oct 2014 21:34:06 +0200 Subject: [PATCH 1/2] petea - changed verification of port --- lib/vatican.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vatican.js b/lib/vatican.js index 735c9b8..a07af75 100644 --- a/lib/vatican.js +++ b/lib/vatican.js @@ -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 ) { From b54379618c278b5a526dd4f53c0dba7b2b68b3db Mon Sep 17 00:00:00 2001 From: petea Date: Fri, 3 Oct 2014 21:52:49 +0200 Subject: [PATCH 2/2] petea - tested validation process of --- lib/vatican.js | 2 +- test/vatican.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/vatican.js b/lib/vatican.js index a07af75..e0d94c3 100644 --- a/lib/vatican.js +++ b/lib/vatican.js @@ -67,7 +67,7 @@ Vatican.prototype.parseHandlers = function(cb) { Makes sure that the required options are there */ Vatican.prototype.checkOptions = function() { - if( !(typeof this.options.port == 'number' && this.options.port >= 0 && this.options.port <= 65535 ) { + 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]"); } diff --git a/test/vatican.js b/test/vatican.js index 798e3cd..fc6f9b6 100644 --- a/test/vatican.js +++ b/test/vatican.js @@ -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})