11import  {  HttpResponse  }  from  "@smithy/protocol-http" ; 
2+ import  {  Logger  }  from  "@smithy/types" ; 
23import  {  createChecksumStream  }  from  "@smithy/util-stream" ; 
34import  {  afterEach ,  beforeEach ,  describe ,  expect ,  test  as  it ,  vi  }  from  "vitest" ; 
45
@@ -32,11 +33,13 @@ describe(validateChecksumFromResponse.name, () => {
3233  }  as  HttpResponse ; 
3334
3435  const  mockChecksum  =  "mockChecksum" ; 
35-   const  mockResponseAlgorithms  =  [ ChecksumAlgorithm . CRC32 ,  ChecksumAlgorithm . CRC32C ] ; 
36+   const  mockResponseAlgorithms  =  [ ChecksumAlgorithm . CRC32 ,  ChecksumAlgorithm . CRC32C ,  ChecksumAlgorithm . CRC64NVME ] ; 
37+   const  mockLogger  =  {  warn : vi . fn ( )  }  as  unknown  as  Logger ; 
3638
3739  const  mockOptions  =  { 
3840    config : mockConfig , 
3941    responseAlgorithms : mockResponseAlgorithms , 
42+     logger : mockLogger , 
4043  } ; 
4144
4245  const  mockChecksumAlgorithmFn  =  vi . fn ( ) ; 
@@ -66,7 +69,6 @@ describe(validateChecksumFromResponse.name, () => {
6669
6770  describe ( "skip validation" ,  ( )  =>  { 
6871    afterEach ( ( )  =>  { 
69-       expect ( selectChecksumAlgorithmFunction ) . not . toHaveBeenCalled ( ) ; 
7072      expect ( getChecksum ) . not . toHaveBeenCalled ( ) ; 
7173    } ) ; 
7274
@@ -75,19 +77,38 @@ describe(validateChecksumFromResponse.name, () => {
7577      await  validateChecksumFromResponse ( mockResponse ,  {  ...mockOptions ,  responseAlgorithms : emptyAlgorithmsList  } ) ; 
7678      expect ( getChecksumAlgorithmListForResponse ) . toHaveBeenCalledWith ( emptyAlgorithmsList ) ; 
7779      expect ( getChecksumLocationName ) . not . toHaveBeenCalled ( ) ; 
80+       expect ( selectChecksumAlgorithmFunction ) . not . toHaveBeenCalled ( ) ; 
7881    } ) ; 
7982
8083    it ( "if updated algorithm list from response is empty" ,  async  ( )  =>  { 
8184      vi . mocked ( getChecksumAlgorithmListForResponse ) . mockImplementation ( ( )  =>  [ ] ) ; 
8285      await  validateChecksumFromResponse ( mockResponse ,  mockOptions ) ; 
8386      expect ( getChecksumAlgorithmListForResponse ) . toHaveBeenCalledWith ( mockResponseAlgorithms ) ; 
8487      expect ( getChecksumLocationName ) . not . toHaveBeenCalled ( ) ; 
88+       expect ( selectChecksumAlgorithmFunction ) . not . toHaveBeenCalled ( ) ; 
8589    } ) ; 
8690
8791    it ( "if checksum is not present in header" ,  async  ( )  =>  { 
8892      await  validateChecksumFromResponse ( mockResponse ,  mockOptions ) ; 
8993      expect ( getChecksumAlgorithmListForResponse ) . toHaveBeenCalledWith ( mockResponseAlgorithms ) ; 
9094      expect ( getChecksumLocationName ) . toHaveBeenCalledTimes ( mockResponseAlgorithms . length ) ; 
95+       expect ( selectChecksumAlgorithmFunction ) . not . toHaveBeenCalled ( ) ; 
96+     } ) ; 
97+ 
98+     it ( `if checksum algorithm is ${ ChecksumAlgorithm . CRC64NVME }  ,  async  ( )  =>  { 
99+       const  dependencyErrorMsg  =  "Dependency not available" ; 
100+       vi . mocked ( selectChecksumAlgorithmFunction ) . mockImplementation ( ( )  =>  { 
101+         throw  new  Error ( dependencyErrorMsg ) ; 
102+       } ) ; 
103+       const  responseWithChecksum  =  getMockResponseWithHeader ( ChecksumAlgorithm . CRC64NVME ,  mockChecksum ) ; 
104+       await  validateChecksumFromResponse ( responseWithChecksum ,  mockOptions ) ; 
105+       expect ( getChecksumAlgorithmListForResponse ) . toHaveBeenCalledWith ( mockResponseAlgorithms ) ; 
106+       expect ( getChecksumLocationName ) . toHaveBeenCalledTimes ( mockResponseAlgorithms . length ) ; 
107+       expect ( selectChecksumAlgorithmFunction ) . toHaveBeenCalledTimes ( 1 ) ; 
108+       expect ( mockLogger . warn ) . toHaveBeenCalledTimes ( 1 ) ; 
109+       expect ( mockLogger . warn ) . toHaveBeenCalledWith ( 
110+         `Skipping ${ ChecksumAlgorithm . CRC64NVME } ${ dependencyErrorMsg }  
111+       ) ; 
91112    } ) ; 
92113  } ) ; 
93114
@@ -134,6 +155,17 @@ describe(validateChecksumFromResponse.name, () => {
134155      expect ( getChecksumLocationName ) . toHaveBeenNthCalledWith ( 2 ,  mockResponseAlgorithms [ 1 ] ) ; 
135156      validateCalls ( isStream ,  mockResponseAlgorithms [ 1 ] ) ; 
136157    } ) ; 
158+ 
159+     it . each ( [ false ,  true ] ) ( "when checksum is populated for third algorithm when streaming: %s" ,  async  ( isStream )  =>  { 
160+       vi . mocked ( isStreaming ) . mockReturnValue ( isStream ) ; 
161+       const  responseWithChecksum  =  getMockResponseWithHeader ( mockResponseAlgorithms [ 2 ] ,  mockChecksum ) ; 
162+       await  validateChecksumFromResponse ( responseWithChecksum ,  mockOptions ) ; 
163+       expect ( getChecksumLocationName ) . toHaveBeenCalledTimes ( 3 ) ; 
164+       expect ( getChecksumLocationName ) . toHaveBeenNthCalledWith ( 1 ,  mockResponseAlgorithms [ 0 ] ) ; 
165+       expect ( getChecksumLocationName ) . toHaveBeenNthCalledWith ( 2 ,  mockResponseAlgorithms [ 1 ] ) ; 
166+       expect ( getChecksumLocationName ) . toHaveBeenNthCalledWith ( 3 ,  mockResponseAlgorithms [ 2 ] ) ; 
167+       validateCalls ( isStream ,  mockResponseAlgorithms [ 2 ] ) ; 
168+     } ) ; 
137169  } ) ; 
138170
139171  it ( "throw error if checksum value is not accurate when not streaming" ,  async  ( )  =>  { 
0 commit comments