11import "@aws-sdk/signature-v4-crt" ;
22
3- import { S3 , SelectObjectContentEventStream } from "@aws-sdk/client-s3" ;
3+ import { ChecksumAlgorithm , S3 , SelectObjectContentEventStream } from "@aws-sdk/client-s3" ;
44import { afterAll , afterEach , beforeAll , describe , expect , test as it } from "vitest" ;
55
66import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources" ;
@@ -24,9 +24,7 @@ describe("@aws-sdk/client-s3", () => {
2424
2525 Key = `` ;
2626
27- client = new S3 ( {
28- region,
29- } ) ;
27+ client = new S3 ( { region } ) ;
3028 } ) ;
3129
3230 describe ( "PutObject" , ( ) => {
@@ -74,26 +72,43 @@ describe("@aws-sdk/client-s3", () => {
7472 await client . deleteObject ( { Bucket, Key } ) ;
7573 } ) ;
7674
77- it ( "should succeed with valid body payload" , async ( ) => {
75+ it ( "should succeed with valid body payload with checksums " , async ( ) => {
7876 // prepare the object.
7977 const body = createBuffer ( "1MB" ) ;
78+ let bodyChecksum = "" ;
79+
80+ const bodyChecksumReader = ( next ) => async ( args ) => {
81+ const checksumValue = args . request . headers [ "x-amz-checksum-crc32" ] ;
82+ if ( checksumValue ) {
83+ bodyChecksum = checksumValue ;
84+ }
85+ return next ( args ) ;
86+ } ;
87+ client . middlewareStack . addRelativeTo ( bodyChecksumReader , {
88+ name : "bodyChecksumReader" ,
89+ relation : "before" ,
90+ toMiddleware : "deserializerMiddleware" ,
91+ } ) ;
8092
8193 try {
82- await client . putObject ( { Bucket, Key, Body : body } ) ;
94+ await client . putObject ( { Bucket, Key, Body : body , ChecksumAlgorithm : ChecksumAlgorithm . CRC32 } ) ;
8395 } catch ( e ) {
8496 console . error ( "failed to put" ) ;
8597 throw e ;
8698 }
8799
100+ expect ( bodyChecksum ) . not . toEqual ( "" ) ;
101+
88102 try {
89103 // eslint-disable-next-line no-var
90- var result = await client . getObject ( { Bucket, Key } ) ;
104+ var result = await client . getObject ( { Bucket, Key, ChecksumMode : "ENABLED" } ) ;
91105 } catch ( e ) {
92106 console . error ( "failed to get" ) ;
93107 throw e ;
94108 }
95109
96110 expect ( result . $metadata . httpStatusCode ) . toEqual ( 200 ) ;
111+ expect ( result . ChecksumCRC32 ) . toEqual ( bodyChecksum ) ;
97112 const { Readable } = require ( "stream" ) ;
98113 expect ( result . Body ) . toBeInstanceOf ( Readable ) ;
99114 } ) ;
0 commit comments