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 <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>
1 parent ee9e817 commit 83f8939

2 files changed

Lines changed: 80 additions & 8 deletions

File tree

‎lib/dgram.js‎

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

858858
if(typeofsourceAddress!=='string'){
859-
thrownewerrors.TypeError('ERR_INVALID_ARG_TYPE','sourceAddress',
860-
'string');
859+
thrownewERR_INVALID_ARG_TYPE('sourceAddress','string',sourceAddress);
861860
}
862861

863862
if(typeofgroupAddress!=='string'){
864-
thrownewerrors.TypeError('ERR_INVALID_ARG_TYPE','groupAddress',
865-
'string');
863+
thrownewERR_INVALID_ARG_TYPE('groupAddress','string',groupAddress);
866864
}
867865

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

883881
if(typeofsourceAddress!=='string'){
884-
thrownewerrors.TypeError('ERR_INVALID_ARG_TYPE','sourceAddress',
885-
'string');
882+
thrownewERR_INVALID_ARG_TYPE('sourceAddress','string',sourceAddress);
886883
}
887884

888885
if(typeofgroupAddress!=='string'){
889-
thrownewerrors.TypeError('ERR_INVALID_ARG_TYPE','groupAddress',
890-
'string');
886+
thrownewERR_INVALID_ARG_TYPE('groupAddress','string',groupAddress);
891887
}
892888

893889
consterr=

‎test/parallel/test-dgram-membership.js‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,79 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
7676
/^Error:dropMembershipEINVAL$/);
7777
socket.close();
7878
}
79+
80+
// addSourceSpecificMembership with invalid sourceAddress should throw
81+
{
82+
constsocket=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+
constsocket=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+
constsocket=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+
constsocket=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+
constsocket=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+
constsocket=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)