@@ -3,7 +3,7 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
3
3
import { BuildMiddleware , FinalizeRequestMiddleware , SerializeMiddleware } from "@aws-sdk/types" ;
4
4
import chai from "chai" ;
5
5
import chaiAsPromised from "chai-as-promised" ;
6
- import { PassThrough } from "stream" ;
6
+ import { PassThrough , Readable } from "stream" ;
7
7
8
8
import { S3 } from "../src/S3" ;
9
9
@@ -38,7 +38,7 @@ describe("endpoint", () => {
38
38
} ) ;
39
39
} ) ;
40
40
41
- describe ( "Accesspoint ARN" , async ( ) => {
41
+ describe ( "Endpoints from ARN" , ( ) => {
42
42
const endpointValidator : BuildMiddleware < any , any > = ( next , context ) => ( args ) => {
43
43
// middleware intercept the request and return it early
44
44
const request = args . request as HttpRequest ;
@@ -52,51 +52,93 @@ describe("Accesspoint ARN", async () => {
52
52
} ) ;
53
53
} ;
54
54
55
- it ( "should succeed with access point ARN" , async ( ) => {
56
- const client = new S3 ( { region : "us-west-2" } ) ;
57
- client . middlewareStack . add ( endpointValidator , { step : "build" , priority : "low" } ) ;
58
- const result : any = await client . putObject ( {
59
- Bucket : "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" ,
60
- Key : "key" ,
61
- Body : "body" ,
55
+ describe ( "Accesspoint ARN" , async ( ) => {
56
+ it ( "should succeed with access point ARN" , async ( ) => {
57
+ const client = new S3 ( { region : "us-west-2" } ) ;
58
+ client . middlewareStack . add ( endpointValidator , { step : "build" , priority : "low" } ) ;
59
+ const result : any = await client . putObject ( {
60
+ Bucket : "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" ,
61
+ Key : "key" ,
62
+ Body : "body" ,
63
+ } ) ;
64
+ expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
62
65
} ) ;
63
- expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
64
- } ) ;
65
66
66
- it ( "should sign request with region from ARN is useArnRegion is set" , async ( ) => {
67
- const client = new S3 ( {
68
- region : "us-east-1" ,
69
- useArnRegion : true ,
70
- credentials : { accessKeyId : "key" , secretAccessKey : "secret" } ,
67
+ it ( "should sign request with region from ARN is useArnRegion is set" , async ( ) => {
68
+ const client = new S3 ( {
69
+ region : "us-east-1" ,
70
+ useArnRegion : true ,
71
+ credentials : { accessKeyId : "key" , secretAccessKey : "secret" } ,
72
+ } ) ;
73
+ client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
74
+ const result : any = await client . putObject ( {
75
+ Bucket : "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" ,
76
+ Key : "key" ,
77
+ Body : "body" ,
78
+ } ) ;
79
+ expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
80
+ // Sign request with us-west-2 region from bucket access point ARN
81
+ expect ( result . request . headers . authorization ) . to . contain ( "/us-west-2/s3/aws4_request, SignedHeaders=" ) ;
71
82
} ) ;
72
- client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
73
- const result : any = await client . putObject ( {
74
- Bucket : "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" ,
75
- Key : "key" ,
76
- Body : "body" ,
83
+ } ) ;
84
+
85
+ describe ( "Outposts ARN" , ( ) => {
86
+ it ( "should succeed with outposts ARN" , async ( ) => {
87
+ const OutpostId = "op-01234567890123456" ;
88
+ const AccountId = "123456789012" ;
89
+ const region = "us-west-2" ;
90
+ const credentials = { accessKeyId : "key" , secretAccessKey : "secret" } ;
91
+ const client = new S3 ( { region : "us-east-1" , credentials, useArnRegion : true } ) ;
92
+ client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
93
+ const result : any = await client . putObject ( {
94
+ Bucket : `arn:aws:s3-outposts:${ region } :${ AccountId } :outpost/${ OutpostId } /accesspoint/abc-111` ,
95
+ Key : "key" ,
96
+ Body : "body" ,
97
+ } ) ;
98
+ expect ( result . request . hostname ) . to . eql ( `abc-111-${ AccountId } .${ OutpostId } .s3-outposts.us-west-2.amazonaws.com` ) ;
99
+ const date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) . replace ( / - / g, "" ) ; //20201029
100
+ expect ( result . request . headers [ "authorization" ] ) . contains (
101
+ `Credential=${ credentials . accessKeyId } /${ date } /${ region } /s3-outposts/aws4_request`
102
+ ) ;
77
103
} ) ;
78
- expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
79
- // Sign request with us-west-2 region from bucket access point ARN
80
- expect ( result . request . headers . authorization ) . to . contain ( "/us-west-2/s3/aws4_request, SignedHeaders=" ) ;
81
104
} ) ;
82
105
83
- it ( "should succeed with outposts ARN" , async ( ) => {
84
- const OutpostId = "op-01234567890123456" ;
85
- const AccountId = "123456789012" ;
86
- const region = "us-west-2" ;
87
- const credentials = { accessKeyId : "key" , secretAccessKey : "secret" } ;
88
- const client = new S3 ( { region : "us-east-1" , credentials, useArnRegion : true } ) ;
89
- client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
90
- const result : any = await client . putObject ( {
91
- Bucket : `arn:aws:s3-outposts:${ region } :${ AccountId } :outpost/${ OutpostId } /accesspoint/abc-111` ,
92
- Key : "key" ,
93
- Body : "body" ,
106
+ describe ( "Object Lambda ARN" , ( ) => {
107
+ it ( "should succeed with Object Lambda ARN" , async ( ) => {
108
+ const region = "us-east-1" ;
109
+ const credentials = { accessKeyId : "key" , secretAccessKey : "secret" } ;
110
+ const client = new S3 ( { region, credentials } ) ;
111
+ client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
112
+ const result : any = await client . putObject ( {
113
+ Bucket : "arn:aws:s3-object-lambda:us-east-1:123456789012:accesspoint/mybanner" ,
114
+ Key : "key" ,
115
+ Body : "body" ,
116
+ } ) ;
117
+ const date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) . replace ( / - / g, "" ) ; //20201029
118
+ expect ( result . request . hostname ) . to . eql ( "mybanner-123456789012.s3-object-lambda.us-east-1.amazonaws.com" ) ;
119
+ expect ( result . request . headers [ "authorization" ] ) . contains (
120
+ `Credential=${ credentials . accessKeyId } /${ date } /${ region } /s3-object-lambda/aws4_request`
121
+ ) ;
122
+ } ) ;
123
+
124
+ it ( "should update endpoint of WriteGetObjectResponse command" , async ( ) => {
125
+ const region = "us-east-1" ;
126
+ const credentials = { accessKeyId : "key" , secretAccessKey : "secret" } ;
127
+ const client = new S3 ( { region, credentials } ) ;
128
+ client . middlewareStack . add ( endpointValidator , { step : "finalizeRequest" , priority : "low" } ) ;
129
+ const requestRoute = "route123" ;
130
+ const result : any = await client . writeGetObjectResponse ( {
131
+ RequestRoute : requestRoute ,
132
+ RequestToken : "token" ,
133
+ Body : new Readable ( ) ,
134
+ } ) ;
135
+ const date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) . replace ( / - / g, "" ) ; //20201029
136
+ expect ( result . request . hostname ) . to . eql ( `${ requestRoute } .s3-object-lambda.us-east-1.amazonaws.com` ) ;
137
+ expect ( result . request . headers [ "authorization" ] ) . contains (
138
+ `Credential=${ credentials . accessKeyId } /${ date } /${ region } /s3-object-lambda/aws4_request`
139
+ ) ;
140
+ expect ( result . request . headers [ "transfer-encoding" ] ) . to . equal ( "chunked" ) ;
94
141
} ) ;
95
- expect ( result . request . hostname ) . to . eql ( `abc-111-${ AccountId } .${ OutpostId } .s3-outposts.us-west-2.amazonaws.com` ) ;
96
- const date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) . replace ( / - / g, "" ) ; //20201029
97
- expect ( result . request . headers [ "authorization" ] ) . contains (
98
- `Credential=${ credentials . accessKeyId } /${ date } /${ region } /s3-outposts/aws4_request`
99
- ) ;
100
142
} ) ;
101
143
} ) ;
102
144
0 commit comments