Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2017-12-29 03:16:44 +0300
committerRebecca Turner <me@re-becca.org>2018-02-07 02:14:24 +0300
commita66e0cd0314893b745e6b9f6ca1708019b1d7aa3 (patch)
treeb83ad6ba52692abc06d05d92fe1015b27686718c /test
parentcec5be5427f7f5106a905de8630e1243e9b36ef4 (diff)
token: Fix CIDR list processing to handle comma separated items correctly
This got broken by having the config-type set to Array. When it was a String, it worked correctly.
Diffstat (limited to 'test')
-rw-r--r--test/tap/unit-token-validate-cidr.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/tap/unit-token-validate-cidr.js b/test/tap/unit-token-validate-cidr.js
new file mode 100644
index 000000000..db963c31f
--- /dev/null
+++ b/test/tap/unit-token-validate-cidr.js
@@ -0,0 +1,19 @@
+'use strict'
+const test = require('tap').test
+const requireInject = require('require-inject')
+const validateCIDRList = requireInject('../../lib/token.js', {'../../lib/npm.js': {}})._validateCIDRList
+
+test('validateCIDRList', (t) => {
+ t.plan(10)
+ const single = ['127.0.0.0/24']
+ const double = ['127.0.0.0/24', '192.168.0.0/16']
+ const ipv6 = '2620:0:2d0:200::7/32'
+ const ipv6Mixed = ['127.0.0/24', '2620:0:2d0:200::7/32', '192.168.0.0/16']
+ t.doesNotThrow(() => t.isDeeply(validateCIDRList(single.join(',')), single), 'single string ipv4')
+ t.doesNotThrow(() => t.isDeeply(validateCIDRList(single), single), 'single array ipv4')
+ t.doesNotThrow(() => t.isDeeply(validateCIDRList(double.join(',')), double), 'double string ipv4')
+ t.doesNotThrow(() => t.isDeeply(validateCIDRList(double), double), 'double array ipv4')
+ t.throws(() => validateCIDRList(ipv6))
+ t.throws(() => validateCIDRList(ipv6Mixed))
+ t.done()
+})