|
| 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