@@ -2,6 +2,8 @@ import { after, before, describe, it } from "node:test";
22import assert from "node:assert" ;
33import { createHash } from "crypto" ;
44import { Readable } from "stream" ;
5+ import { PutObjectCommand , S3Client } from "@aws-sdk/client-s3" ;
6+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner" ;
57import { UpdateCommand , type DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb" ;
68import { handler } from "../src/handler" ;
79import { getClient } from "../src/db/client" ;
@@ -20,6 +22,7 @@ describe("atomic bookkeeping document API", () => {
2022 let client : DynamoDBDocumentClient ;
2123 const deletedVersions : string [ ] = [ ] ;
2224 const signedInputs : Record < string , unknown > [ ] = [ ] ;
25+ const signingOptions : Parameters < typeof getSignedUrl > [ 2 ] [ ] = [ ] ;
2326 let verifiedDocumentId = "" ;
2427 let objectBytes = pdf ;
2528 before ( async ( ) => {
@@ -45,8 +48,9 @@ describe("atomic bookkeeping document API", () => {
4548 return { } ;
4649 } ,
4750 } as any ,
48- async ( _client , command : any ) => {
51+ async ( _client , command : any , options ) => {
4952 signedInputs . push ( command . input ) ;
53+ signingOptions . push ( options ) ;
5054 return "https://upload.invalid/signed" ;
5155 } ,
5256 ) ;
@@ -70,6 +74,15 @@ describe("atomic bookkeeping document API", () => {
7074 assert . equal ( signedInputs . at ( - 1 ) ?. IfNoneMatch , "*" ) ;
7175 const winner = prepared . find ( ( response ) => response . statusCode === 201 ) ! ;
7276 const body = JSON . parse ( winner . body ) ;
77+ const options = signingOptions . at ( - 1 ) ! ;
78+ assert . ok ( options . unhoistableHeaders ?. has ( "x-amz-checksum-sha256" ) ) ;
79+ const signingClient = new S3Client ( { region : "eu-west-1" , credentials : { accessKeyId : "synthetic" , secretAccessKey : "synthetic" } } ) ;
80+ try {
81+ const url = new URL ( await getSignedUrl ( signingClient , new PutObjectCommand ( signedInputs . at ( - 1 ) as any ) , { ...options , expiresIn : 300 } ) ) ;
82+ assert . ok ( url . searchParams . get ( "X-Amz-SignedHeaders" ) ?. split ( ";" ) . includes ( "x-amz-checksum-sha256" ) ) ;
83+ assert . equal ( url . searchParams . has ( "x-amz-checksum-sha256" ) , false ) ;
84+ assert . equal ( body . uploadHeaders [ "x-amz-checksum-sha256" ] , Buffer . from ( sha256 , "hex" ) . toString ( "base64" ) ) ;
85+ } finally { signingClient . destroy ( ) ; }
7386 const requestId = prepared [ 0 ] === winner ? "concurrent-a" : "concurrent-b" ;
7487 const ownership = { idempotencyKey : `${ requestId } -owner` } ;
7588 const completed = await Promise . all ( [
0 commit comments