@@ -878,6 +878,21 @@ describe('WebSocket', () => {
878878 } ) ;
879879 } ) ;
880880 } ) ;
881+
882+ it ( 'throws an error if the data size is greater than 125 bytes' , ( done ) => {
883+ const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
884+ const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
885+
886+ ws . on ( 'open' , ( ) => {
887+ assert . throws (
888+ ( ) => ws . ping ( Buffer . alloc ( 126 ) ) ,
889+ / ^ R a n g e E r r o r : T h e d a t a s i z e m u s t n o t b e g r e a t e r t h a n 1 2 5 b y t e s $ /
890+ ) ;
891+
892+ wss . close ( done ) ;
893+ } ) ;
894+ } ) ;
895+ } ) ;
881896 } ) ;
882897
883898 describe ( '#pong' , ( ) => {
@@ -1019,6 +1034,21 @@ describe('WebSocket', () => {
10191034 } ) ;
10201035 } ) ;
10211036 } ) ;
1037+
1038+ it ( 'throws an error if the data size is greater than 125 bytes' , ( done ) => {
1039+ const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1040+ const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1041+
1042+ ws . on ( 'open' , ( ) => {
1043+ assert . throws (
1044+ ( ) => ws . pong ( Buffer . alloc ( 126 ) ) ,
1045+ / ^ R a n g e E r r o r : T h e d a t a s i z e m u s t n o t b e g r e a t e r t h a n 1 2 5 b y t e s $ /
1046+ ) ;
1047+
1048+ wss . close ( done ) ;
1049+ } ) ;
1050+ } ) ;
1051+ } ) ;
10221052 } ) ;
10231053
10241054 describe ( '#send' , ( ) => {
@@ -1429,6 +1459,21 @@ describe('WebSocket', () => {
14291459 } ) ;
14301460 } ) ;
14311461
1462+ it ( 'throws an error if the message is greater than 123 bytes' , ( done ) => {
1463+ const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1464+ const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1465+
1466+ ws . on ( 'open' , ( ) => {
1467+ assert . throws (
1468+ ( ) => ws . close ( 1000 , 'a' . repeat ( 124 ) ) ,
1469+ / ^ R a n g e E r r o r : T h e m e s s a g e m u s t n o t b e g r e a t e r t h a n 1 2 3 b y t e s $ /
1470+ ) ;
1471+
1472+ wss . close ( done ) ;
1473+ } ) ;
1474+ } ) ;
1475+ } ) ;
1476+
14321477 it ( 'sends the close status code only when necessary' , ( done ) => {
14331478 let sent ;
14341479 const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
0 commit comments