Skip to content

Commit

Permalink
v0.4.13: 20180914
Browse files Browse the repository at this point in the history
 - Potential candidate for issues #53 & #54
 - Removed validation test harness
 - Moved away from .test() to .match() for opts.ports validation
  • Loading branch information
jas- committed Sep 14, 2018
1 parent 3640d0b commit 7cfcd39
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 118 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ node_js:
- "6"
- "7"
- "8"
- "9"
- "10"

install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew install nmap; npm install; node examples/discover.js; npm test; fi
Expand Down
42 changes: 29 additions & 13 deletions lib/classes/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class validation {
* Regex for matching port ranges
* @ref http://stackoverflow.com/a/21075138/901697
*/
//ports: /^(?:(?:^|[-,])(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|6(?:[0-4][0-9]{3}|5(?:[0-4][0-9]{2}|5(?:[0-2][0-9]|3[0-5])))))+$/,
ports: /\d{1,6}(?:-\d+)?/g,

/**
Expand Down Expand Up @@ -99,24 +98,25 @@ class validation {
*/
init(opts, cb) {
const scope = this;
const errors = [];
let errors = [];
let result;

scope.exists(opts.nmap, (result) => {
if (!result) {

// Try full path vs. process.env.PATH
fs.access(opts.nmap, fs.constants.F_OK|fs.constants.X_OK, e => {
fs.access(opts.nmap, fs.constants.F_OK | fs.constants.X_OK, e => {
if (e)
return cb(scope.messages.path);
});
}
});

if (opts.blocksize > 128)
return cb(scope.messages.block);
return cb(scope.messages.block);

if ((!opts.range) || (!/array|object/.test(typeof(opts.range))) ||
(opts.range.length === 0))
if ((!opts.range) || (!/array|object/.test(typeof (opts.range))) ||
(opts.range.length === 0))
return cb(scope.messages.range);

if (opts.range.length >= 1) {
Expand All @@ -131,7 +131,8 @@ class validation {
errors.push(new Error(scope.messages.port));

if (opts.ports) {
if (!scope.patterns.ports.test(opts.ports))
result = opts.ports.match(scope.patterns.ports).join(",");
if (result == "")
return cb(scope.messages.port);
}

Expand All @@ -151,13 +152,14 @@ class validation {
verify(host, cb) {

if (this.test(this.patterns.hostname, host) ||
this.test(this.patterns.IPv4, host) ||
this.test(this.patterns.IPv6, host) ||
this.test(this.patterns.IPv4CIDR, host) ||
this.test(this.patterns.IPv6CIDR, host) ||
this.test(this.patterns.IPv4Range, host)) {
this.test(this.patterns.IPv4, host) ||
this.test(this.patterns.IPv6, host) ||
this.test(this.patterns.IPv4CIDR, host) ||
this.test(this.patterns.IPv6CIDR, host) ||
this.test(this.patterns.IPv4Range, host)) {
return cb(null, true);
} else {
}
else {
return cb(`Supplied host (${host}) did not pass validation.
${this.messages.range}`);
}
Expand All @@ -178,6 +180,20 @@ class validation {
}


/**

This comment has been minimized.

Copy link
@jpstevens

jpstevens Sep 14, 2018

Does this function get used?

Was the idea to have something like:

  match(regex, str) {
    return str.match(regex);
  }
* @function match
* Match specified regex test on string and return array of results
*
* @param {Object} regex - Regex test case
* @param {String} str - String to perform test on
*
* @returns {String}
*/
match(regex, str) {
return regex.match(str);
}


/**
* @function exists
* Binary file tests
Expand Down
105 changes: 0 additions & 105 deletions test/errors.js

This file was deleted.

0 comments on commit 7cfcd39

Please sign in to comment.