From dad21f0ef90c39e2df011174bdffdbd336f7e91c Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 00:39:37 +0100 Subject: [PATCH 1/4] test: added net.connect lookup type check Check the options passed to the connect function of Socket to validate the type of the lookupmproperty. It must be strictly a function. --- 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..a4ab1f2620cee3 --- /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) { + var opts = { + host: 'localhost', + port: common.PORT, + lookup: input, + }; + + assert.throws(function() { + net.connect(opts); + }, expectedError); +} + +[() => {}].forEach((input => { connectDoesNotThrow(input); })) + +function connectDoesNotThrow(input) { + var opts = { + host: 'localhost', + port: common.PORT, + lookup: input, + }; + + assert.doesNotThrow(function() { + net.connect(opts); + }); +} From 1177ae7d77510cfab0fb35b66e63ab232a7293f1 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 01:03:26 +0100 Subject: [PATCH 2/4] Added @jasnell feedbacks --- test/parallel/test-net-options-lookup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js index a4ab1f2620cee3..2eac60cbf15d30 100644 --- a/test/parallel/test-net-options-lookup.js +++ b/test/parallel/test-net-options-lookup.js @@ -5,10 +5,10 @@ const net = require('net'); const expectedError = /^TypeError: "lookup" option should be a function$/; -['foobar', 1, {}, []].forEach((input => { connectThrows(input); })) +['foobar', 1, {}, []].forEach((input => connectThrows(input) )); function connectThrows(input) { - var opts = { + const opts = { host: 'localhost', port: common.PORT, lookup: input, @@ -19,10 +19,10 @@ function connectThrows(input) { }, expectedError); } -[() => {}].forEach((input => { connectDoesNotThrow(input); })) +[() => {}].forEach((input => connectDoesNotThrow(input) )); function connectDoesNotThrow(input) { - var opts = { + const opts = { host: 'localhost', port: common.PORT, lookup: input, From e3504323b991da608faf9d6ab7a172039d56cdb0 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 01:23:22 +0100 Subject: [PATCH 3/4] Removed parenthesis @cjihrig --- test/parallel/test-net-options-lookup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js index 2eac60cbf15d30..94d1475cc08bdf 100644 --- a/test/parallel/test-net-options-lookup.js +++ b/test/parallel/test-net-options-lookup.js @@ -5,7 +5,7 @@ const net = require('net'); const expectedError = /^TypeError: "lookup" option should be a function$/; -['foobar', 1, {}, []].forEach((input => connectThrows(input) )); +['foobar', 1, {}, []].forEach(input => connectThrows(input)); function connectThrows(input) { const opts = { @@ -19,7 +19,7 @@ function connectThrows(input) { }, expectedError); } -[() => {}].forEach((input => connectDoesNotThrow(input) )); +[() => {}].forEach(input => connectDoesNotThrow(input)); function connectDoesNotThrow(input) { const opts = { From b143d6fd2439eae4f2b5b81a3d1344af4efc3c50 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 09:42:45 +0100 Subject: [PATCH 4/4] Fixed linting --- test/parallel/test-net-options-lookup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js index 94d1475cc08bdf..da23830b12ac30 100644 --- a/test/parallel/test-net-options-lookup.js +++ b/test/parallel/test-net-options-lookup.js @@ -5,13 +5,13 @@ const net = require('net'); const expectedError = /^TypeError: "lookup" option should be a function$/; -['foobar', 1, {}, []].forEach(input => connectThrows(input)); +['foobar', 1, {}, []].forEach((input) => connectThrows(input)); function connectThrows(input) { const opts = { host: 'localhost', port: common.PORT, - lookup: input, + lookup: input }; assert.throws(function() { @@ -19,13 +19,13 @@ function connectThrows(input) { }, expectedError); } -[() => {}].forEach(input => connectDoesNotThrow(input)); +[() => {}].forEach((input) => connectDoesNotThrow(input)); function connectDoesNotThrow(input) { const opts = { host: 'localhost', port: common.PORT, - lookup: input, + lookup: input }; assert.doesNotThrow(function() {