Skip to content

Commit 25af672

Browse files
authored
fix(endpoint): test fixes for s3-control related to endpoints 2.0 (#4065)
1 parent 0090e1c commit 25af672

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

clients/client-s3-control/test/S3Control.spec.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("S3Control Client", () => {
88
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
99
// and return them in the Metadata.
1010
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
11-
return Promise.resolve({ output: { $metadata: { request: args.request } }, response: "" as any });
11+
return Promise.resolve({ output: { $metadata: { request: args.request, context } }, response: "" as any });
1212
};
1313
const region = "us-east-1";
1414
const credentials = { accessKeyId: "AKID", secretAccessKey: "SECRET" };
@@ -30,14 +30,14 @@ describe("S3Control Client", () => {
3030
);
3131
});
3232

33-
// TODO(endpointsv2)
34-
it.skip("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
33+
it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
3534
const OutpostId = "123456789012";
3635
const {
3736
// @ts-ignore request is set in $metadata by interception middleware.
3837
$metadata: { request },
3938
} = await s3Control.createBucket({ Bucket: "Bucket", OutpostId });
4039
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
40+
4141
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
4242
expect(request.headers["authorization"]).contains(
4343
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
@@ -58,14 +58,13 @@ describe("S3Control Client", () => {
5858
);
5959
});
6060

61-
// TODO(endpointsv2)
62-
it.skip("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
61+
it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
6362
const OutpostId = "123456789012";
6463
const {
6564
// @ts-ignore request is set in $metadata by interception middleware.
6665
$metadata: { request },
6766
} = await s3Control.listRegionalBuckets({ AccountId, OutpostId });
68-
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
67+
expect(request.hostname).contains(`s3-outposts.${region}.amazonaws.com`);
6968
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
7069
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
7170
expect(request.headers["authorization"]).contains(
@@ -90,17 +89,17 @@ describe("S3Control Client", () => {
9089
);
9190
});
9291

93-
// TODO(endpointsv2)
94-
it.skip("should populate correct endpoint and signing region if Access Point name is ARN", async () => {
92+
it("should populate correct endpoint and signing region if Access Point name is ARN", async () => {
9593
const {
9694
// @ts-ignore request is set in $metadata by interception middleware.
9795
$metadata: { request },
98-
} = await s3Control.getAccessPoint({ Name: accesspointArn });
96+
} = await s3Control.getAccessPoint({ Name: accesspointArn, AccountId });
97+
9998
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
10099
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
101100
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
102101
expect(request.headers["authorization"]).contains(
103-
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
102+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
104103
);
105104
});
106105
});
@@ -121,17 +120,17 @@ describe("S3Control Client", () => {
121120
);
122121
});
123122

124-
// TODO(endpointsv2)
125-
it.skip("should populate correct endpoint and signing region if Bucket name is ARN", async () => {
123+
it("should populate correct endpoint and signing region if Bucket name is ARN", async () => {
126124
const {
127125
// @ts-ignore request is set in $metadata by interception middleware.
128126
$metadata: { request },
129127
} = await s3Control.getBucket({ Bucket: bucketArn });
128+
130129
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
131130
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
132131
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
133132
expect(request.headers["authorization"]).contains(
134-
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
133+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
135134
);
136135
});
137136
});

packages/middleware-endpoint/src/endpointMiddleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const endpointMiddleware = <T extends EndpointParameters>({
4444
context.endpointV2 = endpoint;
4545
context.authSchemes = endpoint.properties?.authSchemes;
4646

47-
const authScheme: AuthScheme = context.authSchemes?.[0];
47+
const authScheme: AuthScheme | undefined = context.authSchemes?.[0];
4848
if (authScheme) {
4949
context["signing_region"] = authScheme.signingRegion;
5050
context["signing_service"] = authScheme.signingName;

packages/middleware-sdk-s3-control/src/process-arnables-plugin/getOutpostEndpoint.ts

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export const getOutpostEndpoint = (
1414
return hostname;
1515
}
1616

17+
const match = hostname.match(REGEX_S3CONTROL_HOSTNAME);
18+
19+
if (!match) {
20+
// outposts hostname was already set by endpoints ruleset.
21+
return hostname;
22+
}
23+
1724
const [matched, prefix, fips, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME)!;
1825
// hostname prefix will be ignored even if it is present
1926
return [

packages/types/src/middleware.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AuthScheme } from "./auth";
12
import { EndpointV2 } from "./endpoint";
23
import { Logger } from "./logger";
34
import { UserAgent } from "./util";
@@ -401,6 +402,11 @@ export interface HandlerExecutionContext {
401402
*/
402403
endpointV2?: EndpointV2;
403404

405+
/**
406+
* Set at the same time as endpointV2.
407+
*/
408+
authSchemes?: AuthScheme[];
409+
404410
[key: string]: any;
405411
}
406412

tests/endpoints-2.0/endpoints-integration.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ async function runTestCase(
7373
) {
7474
const { documentation, params = {}, expect: expectation, operationInputs } = testCase;
7575

76+
for (const key of Object.keys(params)) {
77+
// e.g. S3Control::UseArnRegion as a param key indicates
78+
// an error with the test case, it will be ignored.
79+
if (key.includes(":")) {
80+
delete params[key];
81+
}
82+
}
83+
7684
if (params.UseGlobalEndpoint || params.Region === "aws-global") {
7785
it.skip(documentation || "undocumented testcase", () => {});
7886
return;

0 commit comments

Comments
 (0)