Skip to content

Commit 1ff6796

Browse files
lucamaraschicjihrig
authored andcommitted
test: added net.connect lookup type check
Check the options passed to Socket.prototype.connect() to validate the type of the lookup property. PR-URL: #11873 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 03a6c6e commit 1ff6796

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
const expectedError = /^TypeError: "lookup" option should be a function$/;
7+
8+
['foobar', 1, {}, []].forEach((input) => connectThrows(input));
9+
10+
function connectThrows(input) {
11+
const opts = {
12+
host: 'localhost',
13+
port: common.PORT,
14+
lookup: input
15+
};
16+
17+
assert.throws(function() {
18+
net.connect(opts);
19+
}, expectedError);
20+
}
21+
22+
[() => {}].forEach((input) => connectDoesNotThrow(input));
23+
24+
function connectDoesNotThrow(input) {
25+
const opts = {
26+
host: 'localhost',
27+
port: common.PORT,
28+
lookup: input
29+
};
30+
31+
assert.doesNotThrow(function() {
32+
net.connect(opts);
33+
});
34+
}

0 commit comments

Comments
 (0)