Skip to content

Commit 12ac1b0

Browse files
committed
test(signature-v4-multi-region): some error messages updates in test
1 parent 241086e commit 12ac1b0

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

packages/signature-v4-multi-region/src/SignatureV4MultiRegion.spec.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe("SignatureV4MultiRegion", () => {
4747

4848
beforeEach(() => {
4949
signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4 as any;
50+
signatureV4aContainer.SignatureV4a = SignatureV4a as any;
5051
vi.clearAllMocks();
5152
});
5253

@@ -66,13 +67,6 @@ describe("SignatureV4MultiRegion", () => {
6667
expect(SignatureV4S3Express.mock.instances[0].presign).toBeCalledTimes(1);
6768
});
6869

69-
it("should sign with SigV4a signer if mult_region option is set", async () => {
70-
const signer = new SignatureV4MultiRegion(params);
71-
await signer.presign(minimalRequest, { signingRegion: "*" });
72-
//@ts-ignore
73-
expect(CrtSignerV4.mock.instances[0].presign).toBeCalledTimes(1);
74-
});
75-
7670
it("should presign with SigV4 signer", async () => {
7771
const signer = new SignatureV4MultiRegion(params);
7872
await signer.presign(minimalRequest, { signingRegion: "*" });
@@ -83,15 +77,9 @@ describe("SignatureV4MultiRegion", () => {
8377
it("should sign with SigV4a signer if signingRegion is '*'", async () => {
8478
const signer = new SignatureV4MultiRegion(params);
8579
await signer.sign(minimalRequest, { signingRegion: "*" });
86-
expect(SignatureV4a.prototype.sign).toBeCalledTimes(1);
87-
});
88-
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-
);
80+
//@ts-ignore Check the CrtSignerV4 mock instance instead
81+
expect(CrtSignerV4.mock.instances[0].sign).toBeCalledTimes(1);
82+
expect(SignatureV4a.prototype.sign).toBeCalledTimes(0); // Ensure JS signer was not called
9583
});
9684

9785
it("should use SignatureV4a if CrtSignerV4 is not available", async () => {
@@ -149,7 +137,8 @@ describe("SignatureV4MultiRegion", () => {
149137
signatureV4CrtContainer.CrtSignerV4 = null;
150138
expect.assertions(1);
151139
const signer = new SignatureV4MultiRegion({ ...params });
152-
await expect(async () => await signer.sign(minimalRequest, { signingRegion: "*" })).rejects.toThrow(
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(
153142
"\n" +
154143
`Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n` +
155144
`You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +

packages/signature-v4-multi-region/src/SignatureV4MultiRegion.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ export class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
6060

6161
public async presign(originalRequest: HttpRequest, options: RequestPresigningArguments = {}): Promise<HttpRequest> {
6262
if (options.signingRegion === "*") {
63+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
64+
if (!CrtSignerV4 || typeof CrtSignerV4 !== "function") {
65+
throw new Error(
66+
"\n" +
67+
`Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n` +
68+
`You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +
69+
`or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. \n` +
70+
"For more information please go to " +
71+
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
72+
);
73+
}
6374
return this.getSigv4aSigner().presign(originalRequest, options);
6475
}
6576
return this.sigv4Signer.presign(originalRequest, options);

0 commit comments

Comments
 (0)