Skip to content

Commit

Permalink
dgram: test to add and to drop specific membership
Browse files Browse the repository at this point in the history
Test of addSourceSpecificMembership and dropSourceSpecificMembership
for correct arguments with sourceAddress, groupAddress.

PR-URL: #31047
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
universePrisoner authored and BridgeAR committed Jan 3, 2020
1 parent ca53f02 commit 44d03e8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/dgram.js
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
76 changes: 76 additions & 0 deletions test/parallel/test-dgram-membership.js
Expand Up @@ -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();
}

0 comments on commit 44d03e8

Please sign in to comment.