Skip to content
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

feat(s3-control): support S3 Outposts control plane #1553

Merged
merged 9 commits into from
Oct 7, 2020
133 changes: 133 additions & 0 deletions clients/client-s3-control/S3Control.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/// <reference types="mocha" />
import { expect } from "chai";
import { S3Control } from "./S3Control";
import { FinalizeRequestMiddleware } from "@aws-sdk/types";

describe("S3Control Client", () => {
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
// and return them in the Metadata.
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
return Promise.resolve({ output: { $metadata: { request: args.request } }, response: "" as any });
};
const region = "us-east-1";
const credentials = { accessKeyId: "AKID", secretAccessKey: "SECRET" };
const s3Control = new S3Control({ region, credentials });
s3Control.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" });
const HEADER_OUTPOST_ID = "x-amz-outpost-id";
const HEADER_ACCOUNT_ID = "x-amz-account-id";
const dateStr = new Date().toISOString().substr(0, 10).replace(/[\-:]/g, "");

describe("CreateBucket", () => {
it("should populate correct endpoint and signing region", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.createBucket({ Bucket: "Bucket" });
expect(request.hostname).eql(`s3-control.${region}.amazonaws.com`);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});

it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
const OutpostId = "123456789012";
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.createBucket({ Bucket: "Bucket", OutpostId });
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
);
});
});

describe("ListRegionalBuckets", () => {
const AccountId = "123456789012";
it("should populate correct endpoint and signing region", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.listRegionalBuckets({ AccountId });
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});

it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
const OutpostId = "123456789012";
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.listRegionalBuckets({ AccountId, OutpostId });
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
);
});
});

// Use GetAccessPointCommand to validate the customizations for Access Point ARN customizations
describe("Outposts Access Point ARN", () => {
const AccountId = "123456789012";
const OutpostId = "op-01234567890123456";
const accesspointArn = `arn:aws:s3-outposts:${region}:${AccountId}:outpost:${OutpostId}:accesspoint:myaccesspoint`;
it("should populate correct endpoint if Access Point name is non-ARN", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.getAccessPoint({ Name: "FakeAccessPoint", AccountId });
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});

it("should populate correct endpoint and signing region if Access Point name is ARN", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.getAccessPoint({ Name: accesspointArn });
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
);
});
});

// Use GetBucketCommand to validate the customizations for Bucket ARN customizations
describe("Outposts Bucket ARN", () => {
const AccountId = "123456789012";
const OutpostId = "op-01234567890123456";
const bucketArn = `arn:aws:s3-outposts:${region}:${AccountId}:outpost/${OutpostId}/bucket/bucket-id"`;
it("should populate correct endpoint if Bucket name is non-ARN", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.getBucket({ Bucket: "BucketName", AccountId });
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});

it("should populate correct endpoint and signing region if Bucket name is ARN", async () => {
const {
// @ts-ignore request is set in $metadata by interception middleware.
$metadata: { request },
} = await s3Control.getBucket({ Bucket: bucketArn });
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
);
});
});
});