Skip to content

test(client-s3): add functional test for access point #1455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion clients/client-s3/S3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="mocha" />
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", () => {
Expand Down Expand Up @@ -31,3 +31,42 @@ describe("endpoint", () => {
});
});
});

describe("Accesspoint ARN", async () => {
const endpointValidator: BuildMiddleware<any, any> = (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=");
});
});