Skip to content

Commit aa227cc

Browse files
committed
test(signature-v4-multi-region): initial browser test
1 parent 3dfab74 commit aa227cc

File tree

3 files changed

+176
-1
lines changed

3 files changed

+176
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const webpack = require("webpack");
2+
3+
module.exports = function (config) {
4+
config.set({
5+
basePath: "",
6+
frameworks: ["mocha", "chai", "webpack"],
7+
files: ["src/**/*.browser.spec.ts"],
8+
processKillTimeout: 5000,
9+
preprocessors: {
10+
"src/**/*.browser.spec.ts": ["webpack", "sourcemap", "credentials", "env"],
11+
},
12+
webpackMiddleware: {
13+
stats: "minimal",
14+
},
15+
webpack: {
16+
resolve: {
17+
extensions: [".ts", ".js"],
18+
fallback: {
19+
stream: false,
20+
},
21+
},
22+
mode: "development",
23+
module: {
24+
rules: [
25+
{
26+
test: /\.tsx?$/,
27+
use: [
28+
{
29+
loader: "ts-loader",
30+
options: {
31+
configFile: "tsconfig.json",
32+
compilerOptions: {
33+
rootDir: "./",
34+
},
35+
},
36+
},
37+
],
38+
exclude: /node_modules/,
39+
},
40+
],
41+
},
42+
plugins: [new webpack.NormalModuleReplacementPlugin(/\.\/runtimeConfig$/, "./runtimeConfig.browser")],
43+
devtool: "inline-source-map",
44+
},
45+
envPreprocessor: ["AWS_REGION", "AWS_SMOKE_TEST_MRAP_ARN", "AWS_SMOKE_TEST_CF_KVS_ARN"],
46+
plugins: [
47+
"@aws-sdk/karma-credential-loader",
48+
"karma-chrome-launcher",
49+
"karma-mocha",
50+
"karma-chai",
51+
"karma-webpack",
52+
"karma-coverage",
53+
"karma-sourcemap-loader",
54+
"karma-env-preprocessor",
55+
],
56+
reporters: ["progress"],
57+
port: 9876,
58+
colors: true,
59+
logLevel: config.LOG_WARN,
60+
autoWatch: false,
61+
browsers: ["ChromeHeadlessNoSandbox"],
62+
customLaunchers: {
63+
ChromeHeadlessNoSandbox: {
64+
base: "ChromeHeadless",
65+
flags: ["--no-sandbox"],
66+
},
67+
},
68+
singleRun: true,
69+
concurrency: Infinity,
70+
exclude: ["**/*.d.ts"],
71+
});
72+
};

packages/signature-v4-multi-region/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1212
"test": "jest",
13-
"test:e2e": "jest -c jest.config.e2e.js"
13+
"test:e2e": "jest -c jest.config.e2e.js",
14+
"test:browser": "karma start karma.conf.js"
1415
},
1516
"main": "./dist-cjs/index.js",
1617
"module": "./dist-es/index.js",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { Sha256 } from "@aws-crypto/sha256-js";
2+
import { CloudFrontKeyValueStoreClient, DescribeKeyValueStoreCommand } from "@aws-sdk/client-cloudfront-keyvaluestore";
3+
import { EventBridgeClient, ListRulesCommand } from "@aws-sdk/client-eventbridge";
4+
import { ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
5+
import { SignatureV4MultiRegion } from "@aws-sdk/signature-v4-multi-region";
6+
import { HttpRequest } from "@smithy/protocol-http";
7+
import chai from "chai";
8+
import chaiAsPromised from "chai-as-promised";
9+
10+
chai.use(chaiAsPromised);
11+
const { expect } = chai;
12+
13+
const region = "*";
14+
const credentials = {
15+
accessKeyId: (window as any).__env__.AWS_ACCESS_KEY_ID,
16+
secretAccessKey: (window as any).__env__.AWS_SECRET_ACCESS_KEY,
17+
sessionToken: (window as any).__env__.AWS_SESSION_TOKEN,
18+
};
19+
20+
const s3MrapArn = (window as any).__env__.AWS_SMOKE_TEST_MRAP_ARN;
21+
const cfKvsArn = (window as any).__env__.AWS_SMOKE_TEST_CF_KVS_ARN;
22+
23+
describe("SignatureV4a Browser Tests", function () {
24+
this.timeout(30000); // Set timeout to 30 seconds
25+
26+
const signer = new SignatureV4MultiRegion({
27+
credentials,
28+
sha256: Sha256,
29+
region: region,
30+
service: "s3",
31+
});
32+
33+
describe("S3 Multi-Region Access Point", () => {
34+
const s3Client = new S3Client({
35+
region: region,
36+
credentials,
37+
signer,
38+
});
39+
40+
it("should successfully list objects using MRAP", async () => {
41+
const command = new ListObjectsV2Command({
42+
Bucket: s3MrapArn,
43+
});
44+
45+
const response = await s3Client.send(command);
46+
expect(response.$metadata.httpStatusCode).to.equal(200);
47+
expect(response.Contents).to.be.an("array");
48+
});
49+
});
50+
51+
describe("EventBridge Global Endpoint", () => {
52+
const ebClient = new EventBridgeClient({
53+
region: region,
54+
credentials,
55+
signer,
56+
});
57+
58+
it("should successfully list rules using global endpoint", async () => {
59+
const command = new ListRulesCommand({});
60+
61+
const response = await ebClient.send(command);
62+
expect(response.$metadata.httpStatusCode).to.equal(200);
63+
expect(response.Rules).to.be.an("array");
64+
});
65+
});
66+
67+
describe("CloudFront Key-Value Store", () => {
68+
const cfKvsClient = new CloudFrontKeyValueStoreClient({
69+
region: region,
70+
credentials,
71+
signer,
72+
});
73+
74+
it("should successfully describe a key-value store", async () => {
75+
const command = new DescribeKeyValueStoreCommand({
76+
KvsARN: cfKvsArn,
77+
});
78+
79+
const response = await cfKvsClient.send(command);
80+
expect(response.$metadata.httpStatusCode).to.equal(200);
81+
expect(response.KvsARN).to.equal(cfKvsArn);
82+
});
83+
});
84+
85+
describe("SignatureV4MultiRegion", () => {
86+
it("should use SignatureV4a for '*' region", async () => {
87+
const mockRequest = new HttpRequest({
88+
method: "GET",
89+
protocol: "https:",
90+
hostname: "s3-global.amazonaws.com",
91+
headers: {
92+
host: "s3-global.amazonaws.com",
93+
},
94+
path: "/",
95+
});
96+
97+
const signedRequest = await signer.sign(mockRequest, { signingRegion: "*" });
98+
expect(signedRequest.headers["x-amz-region-set"]).to.equal("*");
99+
expect(signedRequest.headers["authorization"]).to.include("AWS4-ECDSA-P256-SHA256");
100+
});
101+
});
102+
});

0 commit comments

Comments
 (0)