haraka-net-utils
Advanced tools
Comparing version 1.2.4 to 1.3.0
20
index.js
@@ -375,8 +375,20 @@ 'use strict'; | ||
if (!net.isIP(ip)) return (ip in list); // domain | ||
const isHostname = !net.isIP(ip); | ||
const isArray = Array.isArray(list); | ||
for (const string in list) { | ||
if (string === ip) return true; // exact match | ||
// Quick lookup | ||
if (!isArray) { | ||
if (ip in list) return true; // domain or literal IP | ||
if (isHostname) return false; // skip CIDR match | ||
} | ||
const cidr = string.split('/'); | ||
// Iterate: arrays and CIDR matches | ||
for (let item in list) { | ||
if (isArray) { | ||
item = list[item]; // item is index | ||
if (item === ip) return true; // exact match | ||
} | ||
if (isHostname) continue; // skip CIDR match | ||
const cidr = item.split('/'); | ||
const c_net = cidr[0]; | ||
@@ -383,0 +395,0 @@ |
{ | ||
"name": "haraka-net-utils", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"description": "haraka network utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,5 +70,6 @@ ![CI Linux][ci-img] | ||
// searches for 'ip' as a hash key in the list object | ||
// searches for 'ip' as a hash key in the list object or array | ||
// ip can be a host, an IP, or an IPv4 or IPv6 range | ||
net_utils.ip_in_list(object, ip); | ||
net_utils.ip_in_list(array, ip); | ||
net_utils.ip_in_list(tls.no_tls_hosts, '127.0.0.5'); | ||
@@ -75,0 +76,0 @@ |
@@ -988,3 +988,4 @@ | ||
function _check_list (done, list, ip, res) { | ||
assert.equal(net_utils.ip_in_list(list, ip), res); | ||
assert.equal(net_utils.ip_in_list(list, ip), res); // keys of object | ||
assert.equal(net_utils.ip_in_list(Object.keys(list), ip), res); // array | ||
done(); | ||
@@ -991,0 +992,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80316
1397
94