@@ -5,18 +5,37 @@ describe('commands', function () {
5
5
describe ( 'Response' , function ( ) {
6
6
describe ( '#parse' , function ( ) {
7
7
context ( 'when the message body is invalid' , function ( ) {
8
- const message = Buffer . from ( [ ] ) ;
9
- const header = {
10
- length : 0 ,
11
- requestId : 0 ,
12
- responseTo : 0 ,
13
- opCode : 0
14
- } ;
15
- const body = Buffer . from ( [ ] ) ;
8
+ context ( 'when the buffer is empty' , function ( ) {
9
+ const message = Buffer . from ( [ ] ) ;
10
+ const header = {
11
+ length : 0 ,
12
+ requestId : 0 ,
13
+ responseTo : 0 ,
14
+ opCode : 0
15
+ } ;
16
+ const body = Buffer . from ( [ ] ) ;
16
17
17
- it ( 'throws an exception' , function ( ) {
18
- const response = new Response ( message , header , body ) ;
19
- expect ( ( ) => response . parse ( ) ) . to . throw ( ) ;
18
+ it ( 'throws an exception' , function ( ) {
19
+ const response = new Response ( message , header , body ) ;
20
+ expect ( ( ) => response . parse ( ) ) . to . throw ( RangeError , / o u t s i d e b u f f e r b o u n d s / ) ;
21
+ } ) ;
22
+ } ) ;
23
+
24
+ context ( 'when numReturned is invalid' , function ( ) {
25
+ const message = Buffer . from ( [ ] ) ;
26
+ const header = {
27
+ length : 0 ,
28
+ requestId : 0 ,
29
+ responseTo : 0 ,
30
+ opCode : 0
31
+ } ;
32
+ const body = Buffer . alloc ( 5 * 4 ) ;
33
+ body . writeInt32LE ( - 1 , 16 ) ;
34
+
35
+ it ( 'throws an exception' , function ( ) {
36
+ const response = new Response ( message , header , body ) ;
37
+ expect ( ( ) => response . parse ( ) ) . to . throw ( RangeError , / I n v a l i d a r r a y l e n g t h / ) ;
38
+ } ) ;
20
39
} ) ;
21
40
} ) ;
22
41
} ) ;
0 commit comments