@@ -2,13 +2,12 @@ import { HttpRequest } from "@smithy/protocol-http";
22import  {  beforeEach ,  describe ,  expect ,  test  as  it ,  vi  }  from  "vitest" ; 
33
44vi . mock ( "@smithy/signature-v4" ) ; 
5+ vi . mock ( "@smithy/signature-v4a" ) ; 
56vi . mock ( "@aws-sdk/middleware-sdk-s3" ) ; 
67vi . mock ( "@aws-sdk/signature-v4-crt" ) ; 
7- vi . mock ( "@smithy/signature-v4a" ) ; 
88
99import  {  SignatureV4S3Express  }  from  "@aws-sdk/middleware-sdk-s3" ; 
1010import  {  CrtSignerV4  }  from  "@aws-sdk/signature-v4-crt" ; 
11- import  {  SignatureV4  }  from  "@smithy/signature-v4" ; 
1211import  {  SignatureV4a  }  from  "@smithy/signature-v4a" ; 
1312import  {  Checksum  }  from  "@smithy/types" ; 
1413
@@ -48,38 +47,37 @@ describe("SignatureV4MultiRegion", () => {
4847
4948  beforeEach ( ( )  =>  { 
5049    signatureV4CrtContainer . CrtSignerV4  =  CrtSignerV4  as  any ; 
51-     signatureV4aContainer . SignatureV4a  =  SignatureV4a  as  any ; 
5250    vi . clearAllMocks ( ) ; 
5351  } ) ; 
5452
5553  it ( "should sign with SigV4 signer" ,  async  ( )  =>  { 
5654    const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
5755    await  signer . sign ( minimalRequest ) ; 
58-     expect ( SignatureV4 . prototype . sign ) . toBeCalledTimes ( 1 ) ; 
56+ 
57+     //@ts -ignore 
58+     expect ( SignatureV4S3Express . mock . instances [ 0 ] . sign ) . toBeCalledTimes ( 1 ) ; 
5959  } ) ; 
6060
6161  it ( "should presign with SigV4 signer" ,  async  ( )  =>  { 
6262    const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
6363    await  signer . presign ( minimalRequest ) ; 
64-     expect ( SignatureV4 . prototype . presign ) . toBeCalledTimes ( 1 ) ; 
64+ 
65+     //@ts -ignore 
66+     expect ( SignatureV4S3Express . mock . instances [ 0 ] . presign ) . toBeCalledTimes ( 1 ) ; 
6567  } ) ; 
6668
6769  it ( "should sign with SigV4a signer if mult_region option is set" ,  async  ( )  =>  { 
6870    const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
6971    await  signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
70-     expect ( CrtSignerV4 . prototype . presign ) . toBeCalledTimes ( 1 ) ; 
72+     //@ts -ignore 
73+     expect ( CrtSignerV4 . mock . instances [ 0 ] . presign ) . toBeCalledTimes ( 1 ) ; 
7174  } ) ; 
7275
7376  it ( "should presign with SigV4 signer" ,  async  ( )  =>  { 
7477    const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
7578    await  signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
76-     expect ( CrtSignerV4 . prototype . presign ) . toBeCalledTimes ( 1 ) ; 
77-   } ) ; 
78- 
79-   it ( "should presign with SigV4a signer if signingRegion is '*'" ,  async  ( )  =>  { 
80-     const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
81-     await  signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
82-     expect ( SignatureV4a . prototype . presign ) . toBeCalledTimes ( 1 ) ; 
79+     //@ts -ignore 
80+     expect ( CrtSignerV4 . mock . instances [ 0 ] . presign ) . toBeCalledTimes ( 1 ) ; 
8381  } ) ; 
8482
8583  it ( "should sign with SigV4a signer if signingRegion is '*'" ,  async  ( )  =>  { 
@@ -88,10 +86,12 @@ describe("SignatureV4MultiRegion", () => {
8886    expect ( SignatureV4a . prototype . sign ) . toBeCalledTimes ( 1 ) ; 
8987  } ) ; 
9088
91-   it ( "should use CrtSignerV4 if available" ,  async  ( )  =>  { 
92-     const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
93-     await  signer . sign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
94-     expect ( CrtSignerV4 ) . toHaveBeenCalledTimes ( 1 ) ; 
89+   it ( "should throw if sign with SigV4a in unsupported runtime" ,  async  ( )  =>  { 
90+     expect . assertions ( 1 ) ; 
91+     const  signer  =  new  SignatureV4MultiRegion ( {  ...params ,  runtime : "browser"  } ) ; 
92+     await  expect ( async  ( )  =>  await  signer . sign ( minimalRequest ,  {  signingRegion : "*"  } ) ) . rejects . toThrow ( 
93+       "This request requires signing with SigV4Asymmetric algorithm. It's only available in Node.js" 
94+     ) ; 
9595  } ) ; 
9696
9797  it ( "should use SignatureV4a if CrtSignerV4 is not available" ,  async  ( )  =>  { 
@@ -144,4 +144,18 @@ describe("SignatureV4MultiRegion", () => {
144144    await  signer . sign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
145145    expect ( SignatureV4a ) . toHaveBeenCalledTimes ( 1 ) ; 
146146  } ) ; 
147+ 
148+   it ( "should throw if sign with SigV4a and signature-v4-crt is not installed" ,  async  ( )  =>  { 
149+     signatureV4CrtContainer . CrtSignerV4  =  null ; 
150+     expect . assertions ( 1 ) ; 
151+     const  signer  =  new  SignatureV4MultiRegion ( {  ...params  } ) ; 
152+     await  expect ( async  ( )  =>  await  signer . sign ( minimalRequest ,  {  signingRegion : "*"  } ) ) . rejects . toThrow ( 
153+       "\n"  + 
154+         `Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n`  + 
155+         `You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] `  + 
156+         `or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. \n`  + 
157+         "For more information please go to "  + 
158+         "https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt" 
159+     ) ; 
160+   } ) ; 
147161} ) ; 
0 commit comments