@@ -24,7 +24,7 @@ describe('validateChecksumsNoChunking MD5', () => {
2424 describe ( 'with MD5 mismatch' , ( ) => {
2525 it ( 'should return MD5Mismatch error when checksums do not match' , async ( ) => {
2626 const body = 'Hello, World!' ;
27- const wrongMd5 = 'wrongchecksum123 =' ;
27+ const wrongMd5 = '1B2M2Y8AsgTpgAmY7PhCfg= =' ;
2828 const expectedMd5 = crypto . createHash ( 'md5' ) . update ( body , 'utf8' ) . digest ( 'base64' ) ;
2929 const headers = {
3030 'content-md5' : wrongMd5
@@ -56,45 +56,39 @@ describe('validateChecksumsNoChunking MD5', () => {
5656 assert . strictEqual ( result . details , null ) ;
5757 } ) ;
5858
59- it ( 'should return MD5Mismatch error when content-md5 header is undefined' , async ( ) => {
59+ it ( 'should return MD5Invalid error when content-md5 header is undefined' , async ( ) => {
6060 const body = 'Hello, World!' ;
6161 const headers = {
6262 'content-type' : 'application/json' ,
6363 'content-md5' : undefined
6464 } ;
65- const calculatedMD5 = crypto . createHash ( 'md5' ) . update ( body , 'utf8' ) . digest ( 'base64' ) ;
6665
6766 const result = await validateChecksumsNoChunking ( headers , body ) ;
68- assert . strictEqual ( result . error , ChecksumError . MD5Mismatch ) ;
69- assert . strictEqual ( result . details . calculated , calculatedMD5 ) ;
67+ assert . strictEqual ( result . error , ChecksumError . MD5Invalid ) ;
7068 assert . strictEqual ( result . details . expected , undefined ) ;
7169 } ) ;
7270
73- it ( 'should return MD5Mismatch error when content-md5 header is null' , async ( ) => {
71+ it ( 'should return MD5Invalid error when content-md5 header is null' , async ( ) => {
7472 const body = 'Hello, World!' ;
7573 const headers = {
7674 'content-type' : 'application/json' ,
7775 'content-md5' : null
7876 } ;
79- const calculatedMD5 = crypto . createHash ( 'md5' ) . update ( body , 'utf8' ) . digest ( 'base64' ) ;
8077
8178 const result = await validateChecksumsNoChunking ( headers , body ) ;
82- assert . strictEqual ( result . error , ChecksumError . MD5Mismatch ) ;
83- assert . strictEqual ( result . details . calculated , calculatedMD5 ) ;
79+ assert . strictEqual ( result . error , ChecksumError . MD5Invalid ) ;
8480 assert . strictEqual ( result . details . expected , null ) ;
8581 } ) ;
8682
87- it ( 'should return MD5Mismatch error when content-md5 header is empty string' , async ( ) => {
83+ it ( 'should return MD5Invalid error when content-md5 header is empty string' , async ( ) => {
8884 const body = 'Hello, World!' ;
8985 const headers = {
9086 'content-type' : 'application/json' ,
9187 'content-md5' : ''
9288 } ;
93- const calculatedMD5 = crypto . createHash ( 'md5' ) . update ( body , 'utf8' ) . digest ( 'base64' ) ;
9489
9590 const result = await validateChecksumsNoChunking ( headers , body ) ;
96- assert . strictEqual ( result . error , ChecksumError . MD5Mismatch ) ;
97- assert . strictEqual ( result . details . calculated , calculatedMD5 ) ;
91+ assert . strictEqual ( result . error , ChecksumError . MD5Invalid ) ;
9892 assert . strictEqual ( result . details . expected , '' ) ;
9993 } ) ;
10094 } ) ;
@@ -318,7 +312,7 @@ describe('validateMethodChecksumNoChunking', () => {
318312 config . integrityChecks [ method ] = true ;
319313
320314 const body = 'Hello, World!' ;
321- const wrongMd5 = 'wrongchecksum123 =' ;
315+ const wrongMd5 = '1B2M2Y8AsgTpgAmY7PhCfg= =' ;
322316 const request = {
323317 apiMethod : method ,
324318 headers : {
@@ -335,6 +329,29 @@ describe('validateMethodChecksumNoChunking', () => {
335329 } ) ;
336330 } ) ;
337331
332+ describe ( 'when checksum mismatches' , ( ) => {
333+ supportedMethods . forEach ( method => {
334+ it ( `should return InvalidDigest error for ${ method } when checksum mismatch` , async ( ) => {
335+ config . integrityChecks [ method ] = true ;
336+
337+ const body = 'Hello, World!' ;
338+ const wrongMd5 = 'wrongchecksum123=' ;
339+ const request = {
340+ apiMethod : method ,
341+ headers : {
342+ 'content-md5' : wrongMd5
343+ }
344+ } ;
345+ const log = { debug : sandbox . stub ( ) } ;
346+
347+ const result = await validateMethodChecksumNoChunking ( request , body , log ) ;
348+
349+ assert . deepStrictEqual ( result , ArsenalErrors . InvalidDigest , 'Expected BadDigest error' ) ;
350+ assert ( log . debug . calledOnce ) ;
351+ } ) ;
352+ } ) ;
353+ } ) ;
354+
338355 describe ( 'when no checksum is provided' , ( ) => {
339356 supportedMethods . forEach ( method => {
340357 it ( `should return null for ${ method } when no checksum is provided` , async ( ) => {
0 commit comments