File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
__tests__/clients/middleware/signing/signer/signatureV4/utils
src/clients/middleware/signing/signer/signatureV4/utils Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 22// SPDX-License-Identifier: Apache-2.0
33
44import { getHashedPayload } from '../../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload' ;
5+ import { UNSIGNED_PAYLOAD } from '../../../../../../../src/clients/middleware/signing/signer/signatureV4/constants' ;
56
67describe ( 'getHashedPayload' , ( ) => {
78 test ( 'returns empty hash if nullish' , ( ) => {
@@ -34,4 +35,13 @@ describe('getHashedPayload', () => {
3435 expect ( getHashedPayload ( scalar as any ) ) . toStrictEqual ( 'UNSIGNED-PAYLOAD' ) ;
3536 }
3637 } ) ;
38+
39+ test ( 'returns UNSIGNED_PAYLOAD constant without hashing when passed as body' , ( ) => {
40+ expect ( getHashedPayload ( UNSIGNED_PAYLOAD as any ) ) . toStrictEqual (
41+ 'UNSIGNED-PAYLOAD' ,
42+ ) ;
43+ expect ( getHashedPayload ( UNSIGNED_PAYLOAD as any ) ) . not . toStrictEqual (
44+ '438d4109ef0d676b8c2c7ed13cdfcb418e494d53b843d4634ce3b1085f07bb96' ,
45+ ) ;
46+ } ) ;
3747} ) ;
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ export const getHashedPayload = (body: HttpRequest['body']): string => {
3434} ;
3535
3636const isSourceData = ( body : HttpRequest [ 'body' ] ) : body is SourceData =>
37- typeof body === 'string' || ArrayBuffer . isView ( body ) || isArrayBuffer ( body ) ;
37+ // Exclude UNSIGNED_PAYLOAD constant to prevent it from being hashed as a string
38+ body !== UNSIGNED_PAYLOAD &&
39+ ( typeof body === 'string' || ArrayBuffer . isView ( body ) || isArrayBuffer ( body ) ) ;
3840
3941const isArrayBuffer = ( arg : any ) : arg is ArrayBuffer =>
4042 ( typeof ArrayBuffer === 'function' && arg instanceof ArrayBuffer ) ||
You can’t perform that action at this time.
0 commit comments