@@ -878,6 +878,21 @@ describe('WebSocket', () => {
878
878
} ) ;
879
879
} ) ;
880
880
} ) ;
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
+ } ) ;
881
896
} ) ;
882
897
883
898
describe ( '#pong' , ( ) => {
@@ -1019,6 +1034,21 @@ describe('WebSocket', () => {
1019
1034
} ) ;
1020
1035
} ) ;
1021
1036
} ) ;
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
+ } ) ;
1022
1052
} ) ;
1023
1053
1024
1054
describe ( '#send' , ( ) => {
@@ -1429,6 +1459,21 @@ describe('WebSocket', () => {
1429
1459
} ) ;
1430
1460
} ) ;
1431
1461
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
+
1432
1477
it ( 'sends the close status code only when necessary' , ( done ) => {
1433
1478
let sent ;
1434
1479
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
0 commit comments