@@ -22,43 +22,44 @@ test('checkData', t => {
2222 algorithm : 'sha512' ,
2323 digest : hash ( TEST_DATA , 'sha512' )
2424 } )
25- t . equal (
25+ const meta = sri [ 'sha512' ] [ 0 ]
26+ t . deepEqual (
2627 ssri . checkData ( TEST_DATA , sri ) ,
27- 'sha512' ,
28+ meta ,
2829 'Buffer data successfully verified'
2930 )
30- t . equal (
31+ t . deepEqual (
3132 ssri . checkData ( TEST_DATA , `sha512-${ hash ( TEST_DATA , 'sha512' ) } ` ) ,
32- 'sha512' ,
33+ meta ,
3334 'Accepts string SRI'
3435 )
35- t . equal (
36+ t . deepEqual (
3637 ssri . checkData ( TEST_DATA , {
3738 algorithm : 'sha512' ,
3839 digest : hash ( TEST_DATA , 'sha512' )
3940 } ) ,
40- 'sha512' ,
41+ meta ,
4142 'Accepts IntegrityMetadata-like SRI'
4243 )
43- t . equal (
44+ t . deepEqual (
4445 ssri . checkData ( TEST_DATA . toString ( 'utf8' ) , sri ) ,
45- 'sha512' ,
46+ meta ,
4647 'String data successfully verified'
4748 )
48- t . equal (
49+ t . deepEqual (
4950 ssri . checkData (
5051 TEST_DATA ,
5152 `sha512-nope sha512-${ hash ( TEST_DATA , 'sha512' ) } `
5253 ) ,
53- 'sha512' ,
54+ meta ,
5455 'succeeds if any of the hashes under the chosen algorithm match'
5556 )
5657 t . equal (
5758 ssri . checkData ( 'nope' , sri ) ,
5859 false ,
5960 'returns false when verification fails'
6061 )
61- t . equal (
62+ t . deepEqual (
6263 ssri . checkData ( TEST_DATA , [
6364 'sha512-nope' ,
6465 `sha1-${ hash ( TEST_DATA , 'sha1' ) } ` ,
@@ -68,16 +69,20 @@ test('checkData', t => {
6869 if ( a === 'sha1' || b === 'sha1' ) { return 'sha1' }
6970 }
7071 } ) ,
71- 'sha1' ,
72+ ssri . parse ( {
73+ algorithm : 'sha1' , digest : hash ( TEST_DATA , 'sha1' )
74+ } ) [ 'sha1' ] [ 0 ] ,
7275 'opts.pickAlgorithm can be used to customize which one is used.'
7376 )
74- t . equal (
77+ t . deepEqual (
7578 ssri . checkData ( TEST_DATA , [
7679 `sha1-${ hash ( TEST_DATA , 'sha1' ) } ` ,
7780 `sha384-${ hash ( TEST_DATA , 'sha384' ) } ` ,
7881 `sha256-${ hash ( TEST_DATA , 'sha256' ) } `
7982 ] . join ( ' ' ) ) ,
80- 'sha384' ,
83+ ssri . parse ( {
84+ algorithm : 'sha384' , digest : hash ( TEST_DATA , 'sha384' )
85+ } ) [ 'sha384' ] [ 0 ] ,
8186 'picks the "strongest" available algorithm, by default'
8287 )
8388 t . done ( )
@@ -88,31 +93,32 @@ test('checkStream', t => {
8893 algorithm : 'sha512' ,
8994 digest : hash ( TEST_DATA , 'sha512' )
9095 } )
96+ const meta = sri [ 'sha512' ] [ 0 ]
9197 let streamEnded
9298 const stream = fileStream ( ) . on ( 'end' , ( ) => { streamEnded = true } )
93- return ssri . checkStream ( stream , sri ) . then ( algo => {
94- t . equal ( algo , 'sha512' , 'Stream data successfully verified' )
99+ return ssri . checkStream ( stream , sri ) . then ( res => {
100+ t . deepEqual ( res , meta , 'Stream data successfully verified' )
95101 t . ok ( streamEnded , 'source stream ended' )
96102 return ssri . checkStream (
97103 fileStream ( ) ,
98104 `sha512-${ hash ( TEST_DATA , 'sha512' ) } `
99105 )
100- } ) . then ( algo => {
101- t . equal ( algo , 'sha512' , 'Accepts string SRI' )
106+ } ) . then ( res => {
107+ t . deepEqual ( res , meta , 'Accepts string SRI' )
102108 return ssri . checkStream ( fileStream ( ) , {
103109 algorithm : 'sha512' ,
104110 digest : hash ( TEST_DATA , 'sha512' )
105111 } )
106- } ) . then ( algo => {
107- t . equal ( algo , 'sha512' , 'Accepts IntegrityMetadata-like SRI' )
112+ } ) . then ( res => {
113+ t . deepEqual ( res , meta , 'Accepts IntegrityMetadata-like SRI' )
108114 return ssri . checkStream (
109115 fileStream ( ) ,
110116 `sha512-nope sha512-${ hash ( TEST_DATA , 'sha512' ) } `
111117 )
112- } ) . then ( algo => {
113- t . equal (
114- algo ,
115- 'sha512' ,
118+ } ) . then ( res => {
119+ t . deepEqual (
120+ res ,
121+ meta ,
116122 'succeeds if any of the hashes under the chosen algorithm match'
117123 )
118124 return ssri . checkStream (
@@ -133,21 +139,25 @@ test('checkStream', t => {
133139 if ( a === 'sha1' || b === 'sha1' ) { return 'sha1' }
134140 }
135141 } )
136- } ) . then ( algo => {
137- t . equal (
138- algo ,
139- 'sha1' ,
142+ } ) . then ( res => {
143+ t . deepEqual (
144+ res ,
145+ ssri . parse ( {
146+ algorithm : 'sha1' , digest : hash ( TEST_DATA , 'sha1' )
147+ } ) [ 'sha1' ] [ 0 ] ,
140148 'opts.pickAlgorithm can be used to customize which one is used.'
141149 )
142150 return ssri . checkStream ( fileStream ( ) , [
143151 `sha1-${ hash ( TEST_DATA , 'sha1' ) } ` ,
144152 `sha384-${ hash ( TEST_DATA , 'sha384' ) } ` ,
145153 `sha256-${ hash ( TEST_DATA , 'sha256' ) } `
146154 ] . join ( ' ' ) )
147- } ) . then ( algo => {
148- t . equal (
149- algo ,
150- 'sha384' ,
155+ } ) . then ( res => {
156+ t . deepEqual (
157+ res ,
158+ ssri . parse ( {
159+ algorithm : 'sha384' , digest : hash ( TEST_DATA , 'sha384' )
160+ } ) [ 'sha384' ] [ 0 ] ,
151161 'picks the "strongest" available algorithm, by default'
152162 )
153163 } )
0 commit comments