1
- import {
2
- BucketEndpointAwareInput ,
3
- bucketEndpointMiddleware
4
- } from "./bucketEndpointMiddleware" ;
5
- import { HttpRequest } from "@aws-sdk/types" ;
1
+ import { bucketEndpointMiddleware } from "./bucketEndpointMiddleware" ;
2
+ import { HttpRequest } from "@aws-sdk/protocol-http" ;
3
+ import { resolveBucketEndpointConfig } from "./configurations" ;
6
4
7
5
describe ( "bucketEndpointMiddleware" , ( ) => {
8
- const input : BucketEndpointAwareInput = { Bucket : "bucket" } ;
9
- const request : HttpRequest < never > = {
6
+ const input = { Bucket : "bucket" } ;
7
+ const requestInput = {
10
8
method : "GET" ,
11
9
headers : { } ,
12
10
protocol : "https:" ,
@@ -20,7 +18,11 @@ describe("bucketEndpointMiddleware", () => {
20
18
} ) ;
21
19
22
20
it ( "should convert the request provided into one directed to a virtual hosted-style endpoint" , async ( ) => {
23
- const handler = bucketEndpointMiddleware ( ) ( next , { } as any ) ;
21
+ const request = new HttpRequest ( requestInput ) ;
22
+ const handler = bucketEndpointMiddleware ( resolveBucketEndpointConfig ( { } ) ) (
23
+ next ,
24
+ { } as any
25
+ ) ;
24
26
await handler ( { input, request } ) ;
25
27
26
28
const {
@@ -34,9 +36,12 @@ describe("bucketEndpointMiddleware", () => {
34
36
} ) ;
35
37
36
38
it ( "should not convert the request provided into one directed to a virtual hosted-style endpoint if so configured" , async ( ) => {
37
- const handler = bucketEndpointMiddleware ( {
38
- forcePathStyle : true
39
- } ) ( next , { } as any ) ;
39
+ const request = new HttpRequest ( requestInput ) ;
40
+ const handler = bucketEndpointMiddleware (
41
+ resolveBucketEndpointConfig ( {
42
+ forcePathStyle : true
43
+ } )
44
+ ) ( next , { } as any ) ;
40
45
await handler ( { input, request } ) ;
41
46
42
47
const {
@@ -50,7 +55,11 @@ describe("bucketEndpointMiddleware", () => {
50
55
} ) ;
51
56
52
57
it ( "should not convert the request provided into one directed to a virtual hosted-style endpoint if so directed on the input" , async ( ) => {
53
- const handler = bucketEndpointMiddleware ( ) ( next , { } as any ) ;
58
+ const request = new HttpRequest ( requestInput ) ;
59
+ const handler = bucketEndpointMiddleware ( resolveBucketEndpointConfig ( { } ) ) (
60
+ next ,
61
+ { } as any
62
+ ) ;
54
63
await handler ( { input : { ...input , $forcePathStyle : true } , request } ) ;
55
64
56
65
const {
@@ -62,9 +71,12 @@ describe("bucketEndpointMiddleware", () => {
62
71
} ) ;
63
72
64
73
it ( "should convert the request provided into one directed to a virtual hosted-style endpoint if path-style is disabled on the input" , async ( ) => {
65
- const handler = bucketEndpointMiddleware ( {
66
- forcePathStyle : true
67
- } ) ( next , { } as any ) ;
74
+ const request = new HttpRequest ( requestInput ) ;
75
+ const handler = bucketEndpointMiddleware (
76
+ resolveBucketEndpointConfig ( {
77
+ forcePathStyle : true
78
+ } )
79
+ ) ( next , { } as any ) ;
68
80
await handler ( { input : { ...input , $forcePathStyle : false } , request } ) ;
69
81
70
82
const {
@@ -76,9 +88,12 @@ describe("bucketEndpointMiddleware", () => {
76
88
} ) ;
77
89
78
90
it ( "should not convert the request provided into one without the bucket in the path if so configured" , async ( ) => {
79
- const handler = bucketEndpointMiddleware ( {
80
- preformedBucketEndpoint : true
81
- } ) ( next , { } as any ) ;
91
+ const request = new HttpRequest ( requestInput ) ;
92
+ const handler = bucketEndpointMiddleware (
93
+ resolveBucketEndpointConfig ( {
94
+ preformedBucketEndpoint : true
95
+ } )
96
+ ) ( next , { } as any ) ;
82
97
await handler ( {
83
98
input,
84
99
request : { ...request , hostname : "example.com" }
@@ -94,8 +109,12 @@ describe("bucketEndpointMiddleware", () => {
94
109
expect ( path ) . toBe ( "/" ) ;
95
110
} ) ;
96
111
97
- it ( "should use the bucket name as a virtual hosted-style endpoint if so configured on the input" , async ( ) => {
98
- const handler = bucketEndpointMiddleware ( ) ( next , { } as any ) ;
112
+ it ( "should use the bucket name as a virtual hosted-style endpoint if so configured" , async ( ) => {
113
+ const request = new HttpRequest ( requestInput ) ;
114
+ const handler = bucketEndpointMiddleware ( resolveBucketEndpointConfig ( { } ) ) (
115
+ next ,
116
+ { } as any
117
+ ) ;
99
118
await handler ( {
100
119
input : { Bucket : "files.domain.com" , $bucketEndpoint : true } ,
101
120
request : { ...request , path : "/files.domain.com/path/to/key.ext" }
@@ -110,9 +129,12 @@ describe("bucketEndpointMiddleware", () => {
110
129
} ) ;
111
130
112
131
it ( "should use a transfer acceleration endpoint if so configured" , async ( ) => {
113
- const handler = bucketEndpointMiddleware ( {
114
- useAccelerateEndpoint : true
115
- } ) ( next , { } as any ) ;
132
+ const request = new HttpRequest ( requestInput ) ;
133
+ const handler = bucketEndpointMiddleware (
134
+ resolveBucketEndpointConfig ( {
135
+ useAccelerateEndpoint : true
136
+ } )
137
+ ) ( next , { } as any ) ;
116
138
await handler ( { input, request } ) ;
117
139
118
140
const {
@@ -126,7 +148,11 @@ describe("bucketEndpointMiddleware", () => {
126
148
} ) ;
127
149
128
150
it ( "should use a transfer acceleration endpoint if so directed on the input" , async ( ) => {
129
- const handler = bucketEndpointMiddleware ( ) ( next , { } as any ) ;
151
+ const request = new HttpRequest ( requestInput ) ;
152
+ const handler = bucketEndpointMiddleware ( resolveBucketEndpointConfig ( { } ) ) (
153
+ next ,
154
+ { } as any
155
+ ) ;
130
156
await handler ( {
131
157
input : { ...input , $useAccelerateEndpoint : true } ,
132
158
request
@@ -141,9 +167,12 @@ describe("bucketEndpointMiddleware", () => {
141
167
} ) ;
142
168
143
169
it ( "should not use a transfer acceleration endpoint if disabled on the input" , async ( ) => {
144
- const handler = bucketEndpointMiddleware ( {
145
- useAccelerateEndpoint : true
146
- } ) ( next , { } as any ) ;
170
+ const request = new HttpRequest ( requestInput ) ;
171
+ const handler = bucketEndpointMiddleware (
172
+ resolveBucketEndpointConfig ( {
173
+ useAccelerateEndpoint : true
174
+ } )
175
+ ) ( next , { } as any ) ;
147
176
await handler ( {
148
177
input : { ...input , $useAccelerateEndpoint : false } ,
149
178
request
@@ -158,9 +187,12 @@ describe("bucketEndpointMiddleware", () => {
158
187
} ) ;
159
188
160
189
it ( "should use a dualstack endpoint if so configured" , async ( ) => {
161
- const handler = bucketEndpointMiddleware ( {
162
- useDualstackEndpoint : true
163
- } ) ( next , { } as any ) ;
190
+ const request = new HttpRequest ( requestInput ) ;
191
+ const handler = bucketEndpointMiddleware (
192
+ resolveBucketEndpointConfig ( {
193
+ useDualstackEndpoint : true
194
+ } )
195
+ ) ( next , { } as any ) ;
164
196
await handler ( { input, request } ) ;
165
197
166
198
const {
@@ -174,7 +206,11 @@ describe("bucketEndpointMiddleware", () => {
174
206
} ) ;
175
207
176
208
it ( "should use a dualstack endpoint if so directed on the input" , async ( ) => {
177
- const handler = bucketEndpointMiddleware ( ) ( next , { } as any ) ;
209
+ const request = new HttpRequest ( requestInput ) ;
210
+ const handler = bucketEndpointMiddleware ( resolveBucketEndpointConfig ( { } ) ) (
211
+ next ,
212
+ { } as any
213
+ ) ;
178
214
await handler ( {
179
215
input : { ...input , $useDualstackEndpoint : true } ,
180
216
request
@@ -189,9 +225,12 @@ describe("bucketEndpointMiddleware", () => {
189
225
} ) ;
190
226
191
227
it ( "should not use a dualstack endpoint if disabled on the input" , async ( ) => {
192
- const handler = bucketEndpointMiddleware ( {
193
- useDualstackEndpoint : true
194
- } ) ( next , { } as any ) ;
228
+ const request = new HttpRequest ( requestInput ) ;
229
+ const handler = bucketEndpointMiddleware (
230
+ resolveBucketEndpointConfig ( {
231
+ useDualstackEndpoint : true
232
+ } )
233
+ ) ( next , { } as any ) ;
195
234
await handler ( {
196
235
input : { ...input , $useDualstackEndpoint : false } ,
197
236
request
@@ -205,11 +244,14 @@ describe("bucketEndpointMiddleware", () => {
205
244
expect ( path ) . toBe ( "/" ) ;
206
245
} ) ;
207
246
208
- it ( "should use an accelerate dualstack endpoint if so directed on the input" , async ( ) => {
209
- const handler = bucketEndpointMiddleware ( {
210
- useAccelerateEndpoint : true ,
211
- useDualstackEndpoint : true
212
- } ) ( next , { } as any ) ;
247
+ it ( "should use an accelerate dualstack endpoint if configured" , async ( ) => {
248
+ const request = new HttpRequest ( requestInput ) ;
249
+ const handler = bucketEndpointMiddleware (
250
+ resolveBucketEndpointConfig ( {
251
+ useAccelerateEndpoint : true ,
252
+ useDualstackEndpoint : true
253
+ } )
254
+ ) ( next , { } as any ) ;
213
255
await handler ( { input, request } ) ;
214
256
215
257
const {
0 commit comments