@@ -73,16 +73,24 @@ describe("Flexible Checksums", () => {
73
73
} ) ;
74
74
} ) ;
75
75
76
- it ( `when body is sent as a stream` , async ( ) => {
76
+ it ( `when body is sent as a stream` , ( done ) => {
77
77
const requestChecksumValidator : BuildMiddleware < any , any > = ( next ) => async ( args ) => {
78
78
// middleware intercept the request and return it early
79
79
const request = args . request as HttpRequest ;
80
- const { headers } = request ;
80
+ const { headers, body } = request ;
81
81
expect ( headers [ "content-length" ] ) . to . be . undefined ;
82
82
expect ( headers [ "content-encoding" ] ) . to . equal ( "aws-chunked" ) ;
83
83
expect ( headers [ "transfer-encoding" ] ) . to . equal ( "chunked" ) ;
84
84
expect ( headers [ "x-amz-content-sha256" ] ) . to . equal ( "STREAMING-UNSIGNED-PAYLOAD-TRAILER" ) ;
85
85
expect ( headers [ "x-amz-trailer" ] ) . to . equal ( checksumHeader ) ;
86
+ body . on ( "data" , ( data ) => {
87
+ const stringValue = data . toString ( ) ;
88
+ if ( stringValue . startsWith ( checksumHeader ) ) {
89
+ const receivedChecksum = stringValue . replace ( "\r\n" , "" ) . split ( ":" ) [ 1 ] ;
90
+ expect ( receivedChecksum ) . to . equal ( checksumValue ) ;
91
+ done ( ) ;
92
+ }
93
+ } ) ;
86
94
return { output : { } as any , response : { } as any } ;
87
95
} ;
88
96
@@ -93,7 +101,7 @@ describe("Flexible Checksums", () => {
93
101
} ) ;
94
102
95
103
const bodyStream = getBodyAsReadableStream ( body ) ;
96
- return await client . putObject ( {
104
+ client . putObject ( {
97
105
Bucket : "bucket" ,
98
106
Key : "key" ,
99
107
Body : bodyStream ,
0 commit comments