Skip to content

Commit 906786f

Browse files
authored
test(client-s3): add functional test for access point (#1455)
1 parent 7f80690 commit 906786f

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

clients/client-s3/S3.spec.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference types="mocha" />
22
import { expect } from "chai";
33
import { S3 } from "./S3";
4-
import { SerializeMiddleware } from "@aws-sdk/types";
4+
import { SerializeMiddleware, BuildMiddleware } from "@aws-sdk/types";
55
import { HttpRequest } from "@aws-sdk/protocol-http";
66

77
describe("endpoint", () => {
@@ -31,3 +31,42 @@ describe("endpoint", () => {
3131
});
3232
});
3333
});
34+
35+
describe("Accesspoint ARN", async () => {
36+
const endpointValidator: BuildMiddleware<any, any> = (next, context) => (args) => {
37+
// middleware intercept the request and return it early
38+
const request = args.request as HttpRequest;
39+
return Promise.resolve({
40+
output: {
41+
$metadata: { attempts: 0, httpStatusCode: 200 },
42+
request,
43+
context,
44+
} as any,
45+
response: {} as any,
46+
});
47+
};
48+
49+
it("should succeed with access point ARN", async () => {
50+
const client = new S3({});
51+
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
52+
const result: any = await client.putObject({
53+
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",
54+
Key: "key",
55+
Body: "body",
56+
});
57+
expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
58+
});
59+
60+
it("should sign request with region from ARN is useArnRegion is set", async () => {
61+
const client = new S3({ region: "us-east-1", useArnRegion: true });
62+
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
63+
const result: any = await client.putObject({
64+
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",
65+
Key: "key",
66+
Body: "body",
67+
});
68+
expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
69+
// Sign request with us-west-2 region from bucket access point ARN
70+
expect(result.request.headers.authorization).to.contain("/us-west-2/s3/aws4_request, SignedHeaders=");
71+
});
72+
});

0 commit comments

Comments
 (0)