|
1 | 1 | /// <reference types="mocha" /> |
2 | 2 | import { expect } from "chai"; |
3 | 3 | import { S3 } from "./S3"; |
4 | | -import { SerializeMiddleware } from "@aws-sdk/types"; |
| 4 | +import { SerializeMiddleware, BuildMiddleware } from "@aws-sdk/types"; |
5 | 5 | import { HttpRequest } from "@aws-sdk/protocol-http"; |
6 | 6 |
|
7 | 7 | describe("endpoint", () => { |
@@ -31,3 +31,42 @@ describe("endpoint", () => { |
31 | 31 | }); |
32 | 32 | }); |
33 | 33 | }); |
| 34 | + |
| 35 | +describe("Accesspoint ARN", async () => { |
| 36 | + const endpointValidator: BuildMiddleware<any, any> = (next, context) => (args) => { |
| 37 | + // middleware intercept the request and return it early |
| 38 | + const request = args.request as HttpRequest; |
| 39 | + return Promise.resolve({ |
| 40 | + output: { |
| 41 | + $metadata: { attempts: 0, httpStatusCode: 200 }, |
| 42 | + request, |
| 43 | + context, |
| 44 | + } as any, |
| 45 | + response: {} as any, |
| 46 | + }); |
| 47 | + }; |
| 48 | + |
| 49 | + it("should succeed with access point ARN", async () => { |
| 50 | + const client = new S3({}); |
| 51 | + client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" }); |
| 52 | + const result: any = await client.putObject({ |
| 53 | + Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint", |
| 54 | + Key: "key", |
| 55 | + Body: "body", |
| 56 | + }); |
| 57 | + expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should sign request with region from ARN is useArnRegion is set", async () => { |
| 61 | + const client = new S3({ region: "us-east-1", useArnRegion: true }); |
| 62 | + client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" }); |
| 63 | + const result: any = await client.putObject({ |
| 64 | + Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint", |
| 65 | + Key: "key", |
| 66 | + Body: "body", |
| 67 | + }); |
| 68 | + expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"); |
| 69 | + // Sign request with us-west-2 region from bucket access point ARN |
| 70 | + expect(result.request.headers.authorization).to.contain("/us-west-2/s3/aws4_request, SignedHeaders="); |
| 71 | + }); |
| 72 | +}); |
0 commit comments