@@ -330,3 +330,119 @@ test('jws.isValid', function (t) {
330330 t . same ( jws . isValid ( valid ) , true ) ;
331331 t . end ( ) ;
332332} ) ;
333+
334+ test ( 'Streaming sign: HMAC with empty secret buffer' , function ( t ) {
335+ const dataStream = readstream ( 'data.txt' ) ;
336+ const secret = Buffer . alloc ( 0 ) ;
337+ const sig = jws . createSign ( {
338+ header : { alg : 'HS256' } ,
339+ secret : secret
340+ } ) ;
341+ dataStream . pipe ( sig . payload ) ;
342+ sig . on ( 'done' , function ( signature ) {
343+ t . ok ( jws . verify ( signature , 'HS256' , secret ) , 'should verify' ) ;
344+ t . end ( ) ;
345+ } ) . sign ( ) ;
346+ } ) ;
347+
348+ test ( 'Streaming sign: HMAC with empty secret string' , function ( t ) {
349+ const dataStream = readstream ( 'data.txt' ) ;
350+ const secret = '' ;
351+ const sig = jws . createSign ( {
352+ header : { alg : 'HS256' } ,
353+ secret : secret
354+ } ) ;
355+ dataStream . pipe ( sig . payload ) ;
356+ sig . on ( 'done' , function ( signature ) {
357+ t . ok ( jws . verify ( signature , 'HS256' , secret ) , 'should verify' ) ;
358+ t . end ( ) ;
359+ } ) . sign ( ) ;
360+ } ) ;
361+
362+ test ( 'Streaming sign: HMAC with undefined secret' , function ( t ) {
363+ try {
364+ jws . createSign ( {
365+ header : { alg : 'HS256' } ,
366+ secret : undefined
367+ } ) ;
368+ t . fail ( 'should have errored' ) ;
369+ t . end ( ) ;
370+ } catch ( error ) {
371+ t . equal ( error . name , 'TypeError' ) ;
372+ t . equal ( error . message , 'secret must be a string or buffer or a KeyObject' ) ;
373+ t . end ( ) ;
374+ }
375+ } ) ;
376+
377+ test ( 'Streaming sign: HMAC with null secret' , function ( t ) {
378+ try {
379+ jws . createSign ( {
380+ header : { alg : 'HS256' } ,
381+ secret : null
382+ } ) ;
383+ t . fail ( 'should have errored' ) ;
384+ t . end ( ) ;
385+ } catch ( error ) {
386+ t . equal ( error . name , 'TypeError' ) ;
387+ t . equal ( error . message , 'secret must be a string or buffer or a KeyObject' ) ;
388+ t . end ( ) ;
389+ }
390+ } ) ;
391+
392+ test ( 'Streaming verify: HMAC with empty secret buffer' , function ( t ) {
393+ const secret = Buffer . alloc ( 0 ) ;
394+ jws . createVerify ( {
395+ signature : 'eyJhbGciOiJIUzI1NiJ9.b25lLCB0d28sIHRocmVlCg.V1oQ0aq6FgAoe7C2TORtYpQAbYzJoFNFZlJkTlF1e60' ,
396+ algorithm : 'HS256' ,
397+ secret : secret
398+ } ) . on ( 'done' , function ( valid , decoded ) {
399+ t . true ( valid ) ;
400+ t . same ( decoded . payload , readfile ( 'data.txt' ) ) ;
401+ t . end ( ) ;
402+ } ) . verify ( ) ;
403+ } ) ;
404+
405+ test ( 'Streaming verify: HMAC with empty secret string' , function ( t ) {
406+ const secret = '' ;
407+ jws . createVerify ( {
408+ signature : 'eyJhbGciOiJIUzI1NiJ9.b25lLCB0d28sIHRocmVlCg.V1oQ0aq6FgAoe7C2TORtYpQAbYzJoFNFZlJkTlF1e60' ,
409+ algorithm : 'HS256' ,
410+ secret : secret
411+ } ) . on ( 'done' , function ( valid , decoded ) {
412+ t . true ( valid ) ;
413+ t . same ( decoded . payload , readfile ( 'data.txt' ) ) ;
414+ t . end ( ) ;
415+ } ) . verify ( ) ;
416+ } ) ;
417+
418+ test ( 'Streaming verify: HMAC with undefined secret' , function ( t ) {
419+ try {
420+ jws . createVerify ( {
421+ signature : 'eyJhbGciOiJIUzI1NiJ9.b25lLCB0d28sIHRocmVlCg.V1oQ0aq6FgAoe7C2TORtYpQAbYzJoFNFZlJkTlF1e60' ,
422+ algorithm : 'HS256' ,
423+ secret : undefined
424+ } ) ;
425+ t . fail ( 'should have errored' ) ;
426+ t . end ( ) ;
427+ } catch ( error ) {
428+ t . equal ( error . name , 'TypeError' ) ;
429+ t . equal ( error . message , 'secret must be a string or buffer or a KeyObject' ) ;
430+ t . end ( ) ;
431+ }
432+ } ) ;
433+
434+ test ( 'Streaming verify: HMAC with null secret' , function ( t ) {
435+ try {
436+ jws . createVerify ( {
437+ signature : 'eyJhbGciOiJIUzI1NiJ9.b25lLCB0d28sIHRocmVlCg.V1oQ0aq6FgAoe7C2TORtYpQAbYzJoFNFZlJkTlF1e60' ,
438+ algorithm : 'HS256' ,
439+ secret : null
440+ } ) ;
441+ t . fail ( 'should have errored' ) ;
442+ t . end ( ) ;
443+ } catch ( error ) {
444+ t . equal ( error . name , 'TypeError' ) ;
445+ t . equal ( error . message , 'secret must be a string or buffer or a KeyObject' ) ;
446+ t . end ( ) ;
447+ }
448+ } ) ;
0 commit comments