From 906786fc8572a8700e9d01472fbcf48b6ec2aa28 Mon Sep 17 00:00:00 2001 From: AllanFly120 Date: Fri, 21 Aug 2020 11:21:56 -0700 Subject: [PATCH] test(client-s3): add functional test for access point (#1455) --- clients/client-s3/S3.spec.ts | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/clients/client-s3/S3.spec.ts b/clients/client-s3/S3.spec.ts index a6cacac53daa..048a5b4124f9 100644 --- a/clients/client-s3/S3.spec.ts +++ b/clients/client-s3/S3.spec.ts @@ -1,7 +1,7 @@ /// import { expect } from "chai"; import { S3 } from "./S3"; -import { SerializeMiddleware } from "@aws-sdk/types"; +import { SerializeMiddleware, BuildMiddleware } from "@aws-sdk/types"; import { HttpRequest } from "@aws-sdk/protocol-http"; describe("endpoint", () => { @@ -31,3 +31,42 @@ describe("endpoint", () => { }); }); }); + +describe("Accesspoint ARN", async () => { + const endpointValidator: BuildMiddleware = (next, context) => (args) => { + // middleware intercept the request and return it early + const request = args.request as HttpRequest; + return Promise.resolve({ + output: { + $metadata: { attempts: 0, httpStatusCode: 200 }, + request, + context, + } as any, + response: {} as any, + }); + }; + + it("should succeed with access point ARN", async () => { + const client = new S3({}); + client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" }); + const result: any = await client.putObject({ + Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint", + Key: "key", + Body: "body", + }); + expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"); + }); + + it("should sign request with region from ARN is useArnRegion is set", async () => { + const client = new S3({ region: "us-east-1", useArnRegion: true }); + client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" }); + const result: any = await client.putObject({ + Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint", + Key: "key", + Body: "body", + }); + expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"); + // Sign request with us-west-2 region from bucket access point ARN + expect(result.request.headers.authorization).to.contain("/us-west-2/s3/aws4_request, SignedHeaders="); + }); +});