Skip to content

Commit

Permalink
fix(endpoint): test fixes for s3-control related to endpoints 2.0 (#4065
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kuhe authored Oct 20, 2022
1 parent 0090e1c commit 25af672
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
25 changes: 12 additions & 13 deletions clients/client-s3-control/test/S3Control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 });
return Promise.resolve({ output: { $metadata: { request: args.request, context } }, response: "" as any });
};
const region = "us-east-1";
const credentials = { accessKeyId: "AKID", secretAccessKey: "SECRET" };
Expand All @@ -30,14 +30,14 @@ describe("S3Control Client", () => {
);
});

// TODO(endpointsv2)
it.skip("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
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`
Expand All @@ -58,14 +58,13 @@ describe("S3Control Client", () => {
);
});

// TODO(endpointsv2)
it.skip("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
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.hostname).contains(`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(
Expand All @@ -90,17 +89,17 @@ describe("S3Control Client", () => {
);
});

// TODO(endpointsv2)
it.skip("should populate correct endpoint and signing region if Access Point name is ARN", async () => {
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 });
} = await s3Control.getAccessPoint({ Name: accesspointArn, AccountId });

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`
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});
});
Expand All @@ -121,17 +120,17 @@ describe("S3Control Client", () => {
);
});

// TODO(endpointsv2)
it.skip("should populate correct endpoint and signing region if Bucket name is ARN", async () => {
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`
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-endpoint/src/endpointMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const endpointMiddleware = <T extends EndpointParameters>({
context.endpointV2 = endpoint;
context.authSchemes = endpoint.properties?.authSchemes;

const authScheme: AuthScheme = context.authSchemes?.[0];
const authScheme: AuthScheme | undefined = context.authSchemes?.[0];
if (authScheme) {
context["signing_region"] = authScheme.signingRegion;
context["signing_service"] = authScheme.signingName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export const getOutpostEndpoint = (
return hostname;
}

const match = hostname.match(REGEX_S3CONTROL_HOSTNAME);

if (!match) {
// outposts hostname was already set by endpoints ruleset.
return hostname;
}

const [matched, prefix, fips, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME)!;
// hostname prefix will be ignored even if it is present
return [
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuthScheme } from "./auth";
import { EndpointV2 } from "./endpoint";
import { Logger } from "./logger";
import { UserAgent } from "./util";
Expand Down Expand Up @@ -401,6 +402,11 @@ export interface HandlerExecutionContext {
*/
endpointV2?: EndpointV2;

/**
* Set at the same time as endpointV2.
*/
authSchemes?: AuthScheme[];

[key: string]: any;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ async function runTestCase(
) {
const { documentation, params = {}, expect: expectation, operationInputs } = testCase;

for (const key of Object.keys(params)) {
// e.g. S3Control::UseArnRegion as a param key indicates
// an error with the test case, it will be ignored.
if (key.includes(":")) {
delete params[key];
}
}

if (params.UseGlobalEndpoint || params.Region === "aws-global") {
it.skip(documentation || "undocumented testcase", () => {});
return;
Expand Down

0 comments on commit 25af672

Please sign in to comment.