From 25d96ecd4b802adf8f2817e0761fc36f92221114 Mon Sep 17 00:00:00 2001 From: "A. Volgin" Date: Sat, 21 Dec 2019 00:22:15 +0300 Subject: [PATCH] dgram: test to add and to drop specific membership Test of addSourceSpecificMembership and dropSourceSpecificMembership for correct arguments with sourceAddress, groupAddress. PR-URL: https://github.com/nodejs/node/pull/31047 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- lib/dgram.js | 12 ++-- test/parallel/test-dgram-membership.js | 76 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index b17def6cec9d1c..26d1e1d11a0e76 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -856,13 +856,11 @@ Socket.prototype.addSourceSpecificMembership = function(sourceAddress, healthCheck(this); if (typeof sourceAddress !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress', - 'string'); + throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress); } if (typeof groupAddress !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress', - 'string'); + throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress); } const err = @@ -881,13 +879,11 @@ Socket.prototype.dropSourceSpecificMembership = function(sourceAddress, healthCheck(this); if (typeof sourceAddress !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress', - 'string'); + throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress); } if (typeof groupAddress !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress', - 'string'); + throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress); } const err = diff --git a/test/parallel/test-dgram-membership.js b/test/parallel/test-dgram-membership.js index 47704e90b7ce13..a852d618c78897 100644 --- a/test/parallel/test-dgram-membership.js +++ b/test/parallel/test-dgram-membership.js @@ -76,3 +76,79 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true }); /^Error: dropMembership EINVAL$/); socket.close(); } + +// addSourceSpecificMembership with invalid sourceAddress should throw +{ + const socket = setup(); + assert.throws(() => { + socket.addSourceSpecificMembership(0, multicastAddress); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "sourceAddress" argument must be of type string. ' + + 'Received type number (0)' + }); + socket.close(); +} + +// addSourceSpecificMembership with invalid sourceAddress should throw +{ + const socket = setup(); + assert.throws(() => { + socket.addSourceSpecificMembership(multicastAddress, 0); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "groupAddress" argument must be of type string. ' + + 'Received type number (0)' + }); + socket.close(); +} + +// addSourceSpecificMembership with invalid groupAddress should throw +{ + const socket = setup(); + assert.throws(() => { + socket.addSourceSpecificMembership(multicastAddress, '0'); + }, { + code: 'EINVAL', + message: 'addSourceSpecificMembership EINVAL' + }); + socket.close(); +} + +// dropSourceSpecificMembership with invalid sourceAddress should throw +{ + const socket = setup(); + assert.throws(() => { + socket.dropSourceSpecificMembership(0, multicastAddress); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "sourceAddress" argument must be of type string. ' + + 'Received type number (0)' + }); + socket.close(); +} + +// dropSourceSpecificMembership with invalid groupAddress should throw +{ + const socket = setup(); + assert.throws(() => { + socket.dropSourceSpecificMembership(multicastAddress, 0); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "groupAddress" argument must be of type string. ' + + 'Received type number (0)' + }); + socket.close(); +} + +// dropSourceSpecificMembership with invalid UDP should throw +{ + const socket = setup(); + assert.throws(() => { + socket.dropSourceSpecificMembership(multicastAddress, '0'); + }, { + code: 'EINVAL', + message: 'dropSourceSpecificMembership EINVAL' + }); + socket.close(); +}