Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dgram: test to add and to drop specific membership #31047

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/dgram.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}