@@ -8,11 +8,11 @@ vi.mock("@aws-sdk/signature-v4-crt");
88
99import  {  SignatureV4S3Express  }  from  "@aws-sdk/middleware-sdk-s3" ; 
1010import  {  CrtSignerV4  }  from  "@aws-sdk/signature-v4-crt" ; 
11+ import  {  signatureV4aContainer  }  from  "@smithy/signature-v4" ; 
1112import  {  SignatureV4a  }  from  "@smithy/signature-v4a" ; 
1213import  {  Checksum  }  from  "@smithy/types" ; 
1314
1415import  {  signatureV4CrtContainer  }  from  "./signature-v4-crt-container" ; 
15- import  {  signatureV4aContainer  }  from  "./signature-v4a-container" ; 
1616import  {  SignatureV4MultiRegion ,  SignatureV4MultiRegionInit  }  from  "./SignatureV4MultiRegion" ; 
1717
1818describe ( "SignatureV4MultiRegion" ,  ( )  =>  { 
@@ -100,6 +100,34 @@ describe("SignatureV4MultiRegion", () => {
100100    ) . rejects . toThrow ( "Method presignWithCredentials is not supported for [signingRegion=*]." ) ; 
101101  } ) ; 
102102
103+   it ( "should THROW when presigning with signingRegion '*' if CRT is NOT available" ,  async  ( )  =>  { 
104+     signatureV4CrtContainer . CrtSignerV4  =  null ;  // Simulate CRT not being available 
105+     const  signer  =  new  SignatureV4MultiRegion ( params ) ; 
106+     // Expect the new combined error message 
107+     await  expect ( signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ) . rejects . toThrow ( 
108+       `presign with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. `  + 
109+         `Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. `  + 
110+         `You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] `  + 
111+         `or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. `  + 
112+         `For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt` 
113+     ) ; 
114+     expect ( CrtSignerV4 ) . not . toHaveBeenCalled ( ) ; 
115+   } ) ; 
116+ 
117+   it ( "should THROW when presigning with signingRegion '*' in non-node runtime (CRT unavailable)" ,  async  ( )  =>  { 
118+     const  nonNodeParams  =  {  ...params ,  runtime : "browser"  } ; 
119+     const  signer  =  new  SignatureV4MultiRegion ( nonNodeParams ) ; 
120+     // Expect the new combined error message 
121+     await  expect ( signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ) . rejects . toThrow ( 
122+       `presign with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. `  + 
123+         `Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. `  + 
124+         `You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] `  + 
125+         `or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. `  + 
126+         `For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt` 
127+     ) ; 
128+     expect ( CrtSignerV4 ) . not . toHaveBeenCalled ( ) ; 
129+   } ) ; 
130+ 
103131  it ( "should throw an error if neither CrtSignerV4 nor JsSigV4aSigner is available in node runtime" ,  async  ( )  =>  { 
104132    signatureV4CrtContainer . CrtSignerV4  =  null ; 
105133    signatureV4aContainer . SignatureV4a  =  null ; 
@@ -132,19 +160,4 @@ describe("SignatureV4MultiRegion", () => {
132160    await  signer . sign ( minimalRequest ,  {  signingRegion : "*"  } ) ; 
133161    expect ( SignatureV4a ) . toHaveBeenCalledTimes ( 1 ) ; 
134162  } ) ; 
135- 
136-   it ( "should throw if sign with SigV4a and signature-v4-crt is not installed" ,  async  ( )  =>  { 
137-     signatureV4CrtContainer . CrtSignerV4  =  null ; 
138-     expect . assertions ( 1 ) ; 
139-     const  signer  =  new  SignatureV4MultiRegion ( {  ...params  } ) ; 
140-     // // Use presign here, as presign with '*' requires CRT and has no JS fallback 
141-     await  expect ( async  ( )  =>  await  signer . presign ( minimalRequest ,  {  signingRegion : "*"  } ) ) . rejects . toThrow ( 
142-       "\n"  + 
143-         `Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n`  + 
144-         `You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] `  + 
145-         `or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. \n`  + 
146-         "For more information please go to "  + 
147-         "https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt" 
148-     ) ; 
149-   } ) ; 
150163} ) ; 
0 commit comments