summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorZijian Liu <Lxxyxzj@gmail.com>2020-12-06 16:06:37 +0800
committerRich Trott <rtrott@gmail.com>2020-12-14 06:03:41 -0800
commited3a4c8bca0b59a7c805e1db076d1654cf3a1ac4 (patch)
treed06d770ee2ad76dbf60818541bfd2947ceb6381b /test
parentf43d1ca3b0edf4181aaa4943e859a5875c5855a8 (diff)
downloadios-node-v8-ed3a4c8bca0b59a7c805e1db076d1654cf3a1ac4.tar.gz
ios-node-v8-ed3a4c8bca0b59a7c805e1db076d1654cf3a1ac4.tar.bz2
ios-node-v8-ed3a4c8bca0b59a7c805e1db076d1654cf3a1ac4.zip
test: increase coverage for net/blocklist
1. test new BlockList with invalid args Refs: https://coverage.nodejs.org/coverage-f7dd330ba0e7bfa9/lib/internal/blocklist.js.html#L34 2. test addRange with invalid start and end https://coverage.nodejs.org/coverage-f7dd330ba0e7bfa9/lib/internal/blocklist.js.html#L78 3. test blocklist addSubnet with invalid args Refs: https://coverage.nodejs.org/coverage-f7dd330ba0e7bfa9/lib/internal/blocklist.js.html#L81 4. test blocklist check with invalid args Refs: https://coverage.nodejs.org/coverage-f7dd330ba0e7bfa9/lib/internal/blocklist.js.html#L107 5. test util.inspect case Refs: https://coverage.nodejs.org/coverage-f7dd330ba0e7bfa9/lib/internal/blocklist.js.html#L39 PR-URL: https://github.com/nodejs/node/pull/36405 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-blocklist.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/parallel/test-blocklist.js b/test/parallel/test-blocklist.js
index 24f85e0f1b..953b26eec4 100644
--- a/test/parallel/test-blocklist.js
+++ b/test/parallel/test-blocklist.js
@@ -4,6 +4,7 @@ require('../common');
const { BlockList } = require('net');
const assert = require('assert');
+const util = require('util');
{
const blockList = new BlockList();
@@ -135,3 +136,45 @@ const assert = require('assert');
assert(blockList.check('8592:757c:efaf:1fff:ffff:ffff:ffff:ffff', 'ipv6'));
assert(!blockList.check('8592:757c:efaf:2fff:ffff:ffff:ffff:ffff', 'ipv6'));
}
+
+{
+ assert.throws(() => new BlockList('NOT BLOCK LIST HANDLE'), /ERR_INVALID_ARG_TYPE/);
+}
+
+{
+ const blockList = new BlockList();
+ assert.throws(() => blockList.addRange('1.1.1.2', '1.1.1.1'), /ERR_INVALID_ARG_VALUE/);
+}
+
+{
+ const blockList = new BlockList();
+ assert.throws(() => blockList.addSubnet(1), /ERR_INVALID_ARG_TYPE/);
+ assert.throws(() => blockList.addSubnet('', ''), /ERR_INVALID_ARG_TYPE/);
+ assert.throws(() => blockList.addSubnet('', 1, 1), /ERR_INVALID_ARG_TYPE/);
+ assert.throws(() => blockList.addSubnet('', 1, ''), /ERR_INVALID_ARG_VALUE/);
+
+ assert.throws(() => blockList.addSubnet('', -1, 'ipv4'), /ERR_OUT_OF_RANGE/);
+ assert.throws(() => blockList.addSubnet('', 33, 'ipv4'), /ERR_OUT_OF_RANGE/);
+
+ assert.throws(() => blockList.addSubnet('', -1, 'ipv6'), /ERR_OUT_OF_RANGE/);
+ assert.throws(() => blockList.addSubnet('', 129, 'ipv6'), /ERR_OUT_OF_RANGE/);
+}
+
+{
+ const blockList = new BlockList();
+ assert.throws(() => blockList.check(1), /ERR_INVALID_ARG_TYPE/);
+ assert.throws(() => blockList.check('', 1), /ERR_INVALID_ARG_TYPE/);
+ assert.throws(() => blockList.check('', ''), /ERR_INVALID_ARG_VALUE/);
+}
+
+{
+ const blockList = new BlockList();
+ const ret = util.inspect(blockList, { depth: -1 });
+ assert.strictEqual(ret, '[BlockList]');
+}
+
+{
+ const blockList = new BlockList();
+ const ret = util.inspect(blockList, { depth: null });
+ assert(ret.includes('rules: []'));
+}