Skip to content

Commit 83f8939

Browse files
universePrisonertargos
authored andcommitted
dgram: test to add and to drop specific membership
Test of addSourceSpecificMembership and dropSourceSpecificMembership for correct arguments with sourceAddress, groupAddress. PR-URL: #31047 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent ee9e817 commit 83f8939

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

lib/dgram.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,11 @@ Socket.prototype.addSourceSpecificMembership = function(sourceAddress,
856856
healthCheck(this);
857857

858858
if (typeof sourceAddress !== 'string') {
859-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress',
860-
'string');
859+
throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress);
861860
}
862861

863862
if (typeof groupAddress !== 'string') {
864-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress',
865-
'string');
863+
throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress);
866864
}
867865

868866
const err =
@@ -881,13 +879,11 @@ Socket.prototype.dropSourceSpecificMembership = function(sourceAddress,
881879
healthCheck(this);
882880

883881
if (typeof sourceAddress !== 'string') {
884-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress',
885-
'string');
882+
throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress);
886883
}
887884

888885
if (typeof groupAddress !== 'string') {
889-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress',
890-
'string');
886+
throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress);
891887
}
892888

893889
const err =

test/parallel/test-dgram-membership.js

+76
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,79 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
7676
/^Error: dropMembership EINVAL$/);
7777
socket.close();
7878
}
79+
80+
// addSourceSpecificMembership with invalid sourceAddress should throw
81+
{
82+
const socket = setup();
83+
assert.throws(() => {
84+
socket.addSourceSpecificMembership(0, multicastAddress);
85+
}, {
86+
code: 'ERR_INVALID_ARG_TYPE',
87+
message: 'The "sourceAddress" argument must be of type string. ' +
88+
'Received type number (0)'
89+
});
90+
socket.close();
91+
}
92+
93+
// addSourceSpecificMembership with invalid sourceAddress should throw
94+
{
95+
const socket = setup();
96+
assert.throws(() => {
97+
socket.addSourceSpecificMembership(multicastAddress, 0);
98+
}, {
99+
code: 'ERR_INVALID_ARG_TYPE',
100+
message: 'The "groupAddress" argument must be of type string. ' +
101+
'Received type number (0)'
102+
});
103+
socket.close();
104+
}
105+
106+
// addSourceSpecificMembership with invalid groupAddress should throw
107+
{
108+
const socket = setup();
109+
assert.throws(() => {
110+
socket.addSourceSpecificMembership(multicastAddress, '0');
111+
}, {
112+
code: 'EINVAL',
113+
message: 'addSourceSpecificMembership EINVAL'
114+
});
115+
socket.close();
116+
}
117+
118+
// dropSourceSpecificMembership with invalid sourceAddress should throw
119+
{
120+
const socket = setup();
121+
assert.throws(() => {
122+
socket.dropSourceSpecificMembership(0, multicastAddress);
123+
}, {
124+
code: 'ERR_INVALID_ARG_TYPE',
125+
message: 'The "sourceAddress" argument must be of type string. ' +
126+
'Received type number (0)'
127+
});
128+
socket.close();
129+
}
130+
131+
// dropSourceSpecificMembership with invalid groupAddress should throw
132+
{
133+
const socket = setup();
134+
assert.throws(() => {
135+
socket.dropSourceSpecificMembership(multicastAddress, 0);
136+
}, {
137+
code: 'ERR_INVALID_ARG_TYPE',
138+
message: 'The "groupAddress" argument must be of type string. ' +
139+
'Received type number (0)'
140+
});
141+
socket.close();
142+
}
143+
144+
// dropSourceSpecificMembership with invalid UDP should throw
145+
{
146+
const socket = setup();
147+
assert.throws(() => {
148+
socket.dropSourceSpecificMembership(multicastAddress, '0');
149+
}, {
150+
code: 'EINVAL',
151+
message: 'dropSourceSpecificMembership EINVAL'
152+
});
153+
socket.close();
154+
}

0 commit comments

Comments
 (0)