Skip to content

Commit c59b7f5

Browse files
test(s3): add integration test for s3 mrap (#3764)
* test(s3): add integration test for s3 mrap * fix: nits and typo Co-authored-by: Trivikram Kamat <[email protected]>
1 parent 339db59 commit c59b7f5

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

clients/client-s3/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function (config) {
4141
plugins: [new webpack.NormalModuleReplacementPlugin(/\.\/runtimeConfig$/, "./runtimeConfig.browser")],
4242
devtool: "inline-source-map",
4343
},
44-
envPreprocessor: ["AWS_SMOKE_TEST_REGION", "AWS_SMOKE_TEST_BUCKET"],
44+
envPreprocessor: ["AWS_SMOKE_TEST_REGION", "AWS_SMOKE_TEST_BUCKET", "AWS_SMOKE_TEST_MRAP_ARN"],
4545
plugins: [
4646
"@aws-sdk/karma-credential-loader",
4747
"karma-chrome-launcher",

clients/client-s3/test/e2e/S3.ispec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const region: string | undefined = (globalThis as any).defaultRegion || process?
1717
const credentials: Credentials | undefined = (globalThis as any).credentials || undefined;
1818
const isBrowser: boolean | undefined = (globalThis as any).isBrowser || false;
1919
const Bucket = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_BUCKET || process?.env?.AWS_SMOKE_TEST_BUCKET;
20+
const mrapArn = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_MRAP_ARN || process?.env?.AWS_SMOKE_TEST_MRAP_ARN;
2021

2122
let Key = `${Date.now()}`;
2223

@@ -288,4 +289,34 @@ esfuture,29`;
288289
expect(events[2].End).to.be.exist;
289290
});
290291
});
292+
293+
describe("Multi-region access point", () => {
294+
before(async () => {
295+
Key = `${Date.now()}`;
296+
await client.putObject({ Bucket, Key, Body: "foo" });
297+
});
298+
after(async () => {
299+
await client.deleteObject({ Bucket, Key });
300+
});
301+
if (isBrowser) {
302+
it("should throw for aws-crt no available in browser", async () => {
303+
try {
304+
await client.listObjects({
305+
Bucket: mrapArn,
306+
});
307+
expect.fail("MRAP call in browser should throw");
308+
} catch (e) {
309+
expect(e.message).include("only available in Node.js");
310+
}
311+
});
312+
} else {
313+
it("should succeed with valid MRAP ARN", async () => {
314+
const result = await client.listObjects({
315+
Bucket: mrapArn,
316+
});
317+
expect(result.$metadata.httpStatusCode).to.equal(200);
318+
expect(result.Contents).to.be.instanceOf(Array);
319+
});
320+
}
321+
});
291322
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build:clients:since:release": "yarn build:packages && lerna run build $(lerna changed | grep -e '@aws-sdk/[client|lib]-*' | sed 's/^/ --scope /' | tr '\n' ' ')",
1313
"build:crypto-dependencies": "lerna run --scope '@aws-sdk/{types,util-utf8-browser,util-locate-window,hash-node}' --include-dependencies build",
1414
"build:docs": "typedoc",
15-
"build:e2e": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/{client-cloudformation,karma-credential-loader}' --include-dependencies build",
15+
"build:e2e": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/{client-cloudformation,karma-credential-loader,client-s3-control,client-sts}' --include-dependencies build",
1616
"build:packages": "lerna run build --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' --ignore '@aws-sdk/lib-*' --include-dependencies",
1717
"build:protocols": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/aws-protocoltests-*' --include-dependencies build",
1818
"build:server-protocols": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/*-server' --include-dependencies build",

tests/e2e/IntegTestResourcesStack.template.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@
6969
"Metadata": {
7070
"aws:cdk:path": "IntegTestResourcesStack/IntegTestBucket/Resource"
7171
}
72+
},
73+
"MultiregionAccessPoint": {
74+
"Type": "AWS::S3::MultiRegionAccessPoint",
75+
"Properties": {
76+
"Name": "v3-sdk-integration-test-001",
77+
"Regions": [
78+
{
79+
"Bucket": { "Ref": "IntegTestBucketA93771AE" }
80+
}
81+
]
82+
}
7283
}
7384
}
7485
}

tests/e2e/get-integ-test-resources.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
const { readFileSync } = require("fs");
22
const { join } = require("path");
3+
const { STSClient, GetCallerIdentityCommand } = require("../../clients/client-sts");
34
const { CloudFormationClient, DescribeStackResourcesCommand } = require("../../clients/client-cloudformation");
5+
const { S3ControlClient, ListMultiRegionAccessPointsCommand } = require("../../clients/client-s3-control");
46
const { ensureTestStack } = require("./ensure-test-stack");
57

68
exports.getIntegTestResources = async () => {
7-
const client = new CloudFormationClient({ logger: console });
8-
const region = await client.config.region();
9+
const cloudformation = new CloudFormationClient({ logger: console });
10+
const region = await cloudformation.config.region();
911
const stackName = "SdkReleaseV3IntegTestResourcesStack";
1012

1113
await ensureTestStack(
12-
client,
14+
cloudformation,
1315
stackName,
1416
readFileSync(join(__dirname, "IntegTestResourcesStack.template.json"), { encoding: "utf-8" })
1517
);
16-
const { StackResources: stackResources } = await client.send(
18+
const { StackResources: stackResources } = await cloudformation.send(
1719
new DescribeStackResourcesCommand({ StackName: stackName })
1820
);
1921

@@ -26,9 +28,21 @@ exports.getIntegTestResources = async () => {
2628
(resource) => resource.ResourceType === "AWS::S3::Bucket" && resource.LogicalResourceId.indexOf("IntegTest") === 0
2729
)[0].PhysicalResourceId;
2830

31+
const multiRegionAccessPointName = stackResources.filter(
32+
(resource) => resource.ResourceType === "AWS::S3::MultiRegionAccessPoint"
33+
)[0].PhysicalResourceId;
34+
35+
const sts = new STSClient({ logger: console });
36+
const { Account: AccountId } = await sts.send(new GetCallerIdentityCommand({}));
37+
const s3Control = new S3ControlClient({ logger: console });
38+
const { AccessPoints } = await s3Control.send(new ListMultiRegionAccessPointsCommand({ AccountId }));
39+
const { Alias } = AccessPoints.find((accesspoint) => accesspoint.Name === multiRegionAccessPointName);
40+
const mrapArn = `arn:aws:s3::${AccountId}:accesspoint/${Alias}`;
41+
2942
return {
3043
AWS_SMOKE_TEST_REGION: region,
3144
AWS_SMOKE_TEST_IDENTITY_POOL_ID: identityPoolId,
3245
AWS_SMOKE_TEST_BUCKET: bucketName,
46+
AWS_SMOKE_TEST_MRAP_ARN: mrapArn,
3347
};
3448
};

0 commit comments

Comments
 (0)