@@ -165,12 +165,13 @@ func TestS3Getter_ClientMode_collision(t *testing.T) {
165
165
166
166
func TestS3Getter_Url (t * testing.T ) {
167
167
var s3tests = []struct {
168
- name string
169
- url string
170
- region string
171
- bucket string
172
- path string
173
- version string
168
+ name string
169
+ url string
170
+ region string
171
+ bucket string
172
+ path string
173
+ version string
174
+ expectedErr string
174
175
}{
175
176
{
176
177
name : "AWSv1234" ,
@@ -220,6 +221,11 @@ func TestS3Getter_Url(t *testing.T) {
220
221
path : "hello.txt" ,
221
222
version : "" ,
222
223
},
224
+ {
225
+ name : "malformed s3 url" ,
226
+ url : "s3::https://s3.amazonaws.com/bucket" ,
227
+ expectedErr : "URL is not a valid S3 URL" ,
228
+ },
223
229
}
224
230
225
231
for i , pt := range s3tests {
@@ -238,7 +244,15 @@ func TestS3Getter_Url(t *testing.T) {
238
244
region , bucket , path , version , creds , err := g .parseUrl (u )
239
245
240
246
if err != nil {
241
- t .Fatalf ("err: %s" , err )
247
+ if pt .expectedErr == "" {
248
+ t .Fatalf ("err: %s" , err )
249
+ }
250
+ if err .Error () != pt .expectedErr {
251
+ t .Fatalf ("expected %s, got %s" , pt .expectedErr , err .Error ())
252
+ }
253
+ return
254
+ } else if pt .expectedErr != "" {
255
+ t .Fatalf ("expected error, got none" )
242
256
}
243
257
if region != pt .region {
244
258
t .Fatalf ("expected %s, got %s" , pt .region , region )
@@ -258,3 +272,40 @@ func TestS3Getter_Url(t *testing.T) {
258
272
})
259
273
}
260
274
}
275
+
276
+ func Test_S3Getter_ParseUrl_Malformed (t * testing.T ) {
277
+ tests := []struct {
278
+ name string
279
+ url string
280
+ }{
281
+ {
282
+ name : "path style" ,
283
+ url : "https://s3.amazonaws.com/bucket" ,
284
+ },
285
+ {
286
+ name : "vhost-style, dash region indication" ,
287
+ url : "https://bucket.s3-us-east-1.amazonaws.com" ,
288
+ },
289
+ {
290
+ name : "vhost-style, dot region indication" ,
291
+ url : "https://bucket.s3.us-east-1.amazonaws.com" ,
292
+ },
293
+ }
294
+ for _ , tt := range tests {
295
+ t .Run (tt .name , func (t * testing.T ) {
296
+ g := new (S3Getter )
297
+ u , err := url .Parse (tt .url )
298
+ if err != nil {
299
+ t .Fatalf ("unexpected error: %s" , err )
300
+ }
301
+ _ , _ , _ , _ , _ , err = g .parseUrl (u )
302
+ if err == nil {
303
+ t .Fatalf ("expected error, got none" )
304
+ }
305
+ if err .Error () != "URL is not a valid S3 URL" {
306
+ t .Fatalf ("expected error 'URL is not a valid S3 URL', got %s" , err .Error ())
307
+ }
308
+ })
309
+ }
310
+
311
+ }
0 commit comments