Skip to content

Commit

Permalink
add validation for port values to server (fix #3227)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Jul 28, 2014
1 parent afe7ad6 commit c495594
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion lib/server/helpers.js
Expand Up @@ -47,7 +47,7 @@ module.exports.catchAllHandler = function (e, req, res, next) {
next(e);
};

module.exports.checkArgs = function (args) {
module.exports.checkArgs = function (parser, args) {
var exclusives = [
['noReset', 'fullReset']
, ['ipa', 'safari']
Expand All @@ -69,6 +69,34 @@ module.exports.checkArgs = function (args) {
process.exit(1);
}
});

var checkValidPort = function (port) {
if (port > 0 && port < 65536) return true;
console.error("Port must be greater than 0 and less than 65536");
return false;
};

var validations = {
port: checkValidPort
, callbackPort: checkValidPort
, bootstrapPort: checkValidPort
, selendroidPort: checkValidPort
, chromedriverPort: checkValidPort
, robotPort: checkValidPort
, backendRetries: function (r) { return r >= 0; }
};

var nonDefaultArgs = getNonDefaultArgs(parser, args);

_.each(validations, function (validator, arg) {
if (_.has(nonDefaultArgs, arg)) {
if (!validator(args[arg])) {
console.error("Invalid argument for param " + arg + ": " + args[arg]);
process.exit(1);
}
}
});

};

module.exports.noColorLogger = function (tokens, req, res) {
Expand Down
2 changes: 1 addition & 1 deletion lib/server/main.js
Expand Up @@ -81,7 +81,7 @@ var main = function (args, readyCb, doneCb) {
process.exit(0);
}

checkArgs(args);
checkArgs(parser, args);
if (typeof doneCb === "undefined") {
doneCb = function () {};
}
Expand Down

0 comments on commit c495594

Please sign in to comment.