From 1ff67960833b0c1d7d80834256a9c9c91efa9f40 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 00:39:37 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/11873 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Evan Lucas Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung --- test/parallel/test-net-options-lookup.js | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/parallel/test-net-options-lookup.js diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js new file mode 100644 index 00000000000000..da23830b12ac30 --- /dev/null +++ b/test/parallel/test-net-options-lookup.js @@ -0,0 +1,34 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +const expectedError = /^TypeError: "lookup" option should be a function$/; + +['foobar', 1, {}, []].forEach((input) => connectThrows(input)); + +function connectThrows(input) { + const opts = { + host: 'localhost', + port: common.PORT, + lookup: input + }; + + assert.throws(function() { + net.connect(opts); + }, expectedError); +} + +[() => {}].forEach((input) => connectDoesNotThrow(input)); + +function connectDoesNotThrow(input) { + const opts = { + host: 'localhost', + port: common.PORT, + lookup: input + }; + + assert.doesNotThrow(function() { + net.connect(opts); + }); +}