Skip to content

Commit d299cee

Browse files
Lxxyxtargos
authored andcommitted
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: #36405 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent fa40366 commit d299cee

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/parallel/test-blocklist.js

+43
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require('../common');
44

55
const { BlockList } = require('net');
66
const assert = require('assert');
7+
const util = require('util');
78

89
{
910
const blockList = new BlockList();
@@ -135,3 +136,45 @@ const assert = require('assert');
135136
assert(blockList.check('8592:757c:efaf:1fff:ffff:ffff:ffff:ffff', 'ipv6'));
136137
assert(!blockList.check('8592:757c:efaf:2fff:ffff:ffff:ffff:ffff', 'ipv6'));
137138
}
139+
140+
{
141+
assert.throws(() => new BlockList('NOT BLOCK LIST HANDLE'), /ERR_INVALID_ARG_TYPE/);
142+
}
143+
144+
{
145+
const blockList = new BlockList();
146+
assert.throws(() => blockList.addRange('1.1.1.2', '1.1.1.1'), /ERR_INVALID_ARG_VALUE/);
147+
}
148+
149+
{
150+
const blockList = new BlockList();
151+
assert.throws(() => blockList.addSubnet(1), /ERR_INVALID_ARG_TYPE/);
152+
assert.throws(() => blockList.addSubnet('', ''), /ERR_INVALID_ARG_TYPE/);
153+
assert.throws(() => blockList.addSubnet('', 1, 1), /ERR_INVALID_ARG_TYPE/);
154+
assert.throws(() => blockList.addSubnet('', 1, ''), /ERR_INVALID_ARG_VALUE/);
155+
156+
assert.throws(() => blockList.addSubnet('', -1, 'ipv4'), /ERR_OUT_OF_RANGE/);
157+
assert.throws(() => blockList.addSubnet('', 33, 'ipv4'), /ERR_OUT_OF_RANGE/);
158+
159+
assert.throws(() => blockList.addSubnet('', -1, 'ipv6'), /ERR_OUT_OF_RANGE/);
160+
assert.throws(() => blockList.addSubnet('', 129, 'ipv6'), /ERR_OUT_OF_RANGE/);
161+
}
162+
163+
{
164+
const blockList = new BlockList();
165+
assert.throws(() => blockList.check(1), /ERR_INVALID_ARG_TYPE/);
166+
assert.throws(() => blockList.check('', 1), /ERR_INVALID_ARG_TYPE/);
167+
assert.throws(() => blockList.check('', ''), /ERR_INVALID_ARG_VALUE/);
168+
}
169+
170+
{
171+
const blockList = new BlockList();
172+
const ret = util.inspect(blockList, { depth: -1 });
173+
assert.strictEqual(ret, '[BlockList]');
174+
}
175+
176+
{
177+
const blockList = new BlockList();
178+
const ret = util.inspect(blockList, { depth: null });
179+
assert(ret.includes('rules: []'));
180+
}

0 commit comments

Comments
 (0)