Merge pull request #3240 from jlipps/master

add validation for port values to server (fix #3227)
This commit is contained in:
Jonathan Lipps
2014-07-28 11:52:05 -07:00
2 changed files with 30 additions and 2 deletions

View File

@@ -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']
@@ -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) {

View File

@@ -81,7 +81,7 @@ var main = function (args, readyCb, doneCb) {
process.exit(0);
}
checkArgs(args);
checkArgs(parser, args);
if (typeof doneCb === "undefined") {
doneCb = function () {};
}