@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"crypto/tls"
22
22
"crypto/x509"
23
+ "encoding/json"
23
24
"encoding/xml"
24
25
"errors"
25
26
"fmt"
@@ -249,8 +250,8 @@ func TestNewClientAWSProvider(t *testing.T) {
249
250
t .Run ("without secret" , func (t * testing.T ) {
250
251
bucket := bucketStub (bucketAwsProvider , testMinioAddress )
251
252
minioClient , err := NewClient (ctx , bucket )
252
- assert .ErrorContains (t , err , "AWS authentication failed" )
253
- assert .Assert (t , minioClient = = nil )
253
+ assert .NilError (t , err )
254
+ assert .Assert (t , minioClient ! = nil )
254
255
})
255
256
}
256
257
@@ -274,8 +275,43 @@ func TestFGetObject(t *testing.T) {
274
275
}
275
276
276
277
func TestNewClientAndFGetObjectWithSTSEndpoint (t * testing.T ) {
278
+ // start a mock AWS STS server
279
+ awsSTSListener , awsSTSAddr , awsSTSPort := testlistener .New (t )
280
+ awsSTSEndpoint := fmt .Sprintf ("http://%s" , awsSTSAddr )
281
+ awsSTSHandler := http .NewServeMux ()
282
+ awsSTSHandler .HandleFunc ("PUT " + credentials .TokenPath ,
283
+ func (w http.ResponseWriter , r * http.Request ) {
284
+ _ , err := w .Write ([]byte ("mock-token" ))
285
+ assert .NilError (t , err )
286
+ })
287
+ awsSTSHandler .HandleFunc ("GET " + credentials .DefaultIAMSecurityCredsPath ,
288
+ func (w http.ResponseWriter , r * http.Request ) {
289
+ token := r .Header .Get (credentials .TokenRequestHeader )
290
+ assert .Equal (t , token , "mock-token" )
291
+ _ , err := w .Write ([]byte ("mock-role" ))
292
+ assert .NilError (t , err )
293
+ })
277
294
var credsRetrieved bool
278
295
296
+ awsSTSHandler .HandleFunc ("GET " + credentials .DefaultIAMSecurityCredsPath + "mock-role" ,
297
+ func (w http.ResponseWriter , r * http.Request ) {
298
+ token := r .Header .Get (credentials .TokenRequestHeader )
299
+ assert .Equal (t , token , "mock-token" )
300
+ err := json .NewEncoder (w ).Encode (map [string ]any {
301
+ "Code" : "Success" ,
302
+ "AccessKeyID" : testMinioRootUser ,
303
+ "SecretAccessKey" : testMinioRootPassword ,
304
+ })
305
+ assert .NilError (t , err )
306
+ credsRetrieved = true
307
+ })
308
+ awsSTSServer := & http.Server {
309
+ Addr : awsSTSAddr ,
310
+ Handler : awsSTSHandler ,
311
+ }
312
+ go awsSTSServer .Serve (awsSTSListener )
313
+ defer awsSTSServer .Shutdown (context .Background ())
314
+
279
315
// start a mock LDAP STS server
280
316
ldapSTSListener , ldapSTSAddr , ldapSTSPort := testlistener .New (t )
281
317
ldapSTSEndpoint := fmt .Sprintf ("https://%s" , ldapSTSAddr )
@@ -315,6 +351,42 @@ func TestNewClientAndFGetObjectWithSTSEndpoint(t *testing.T) {
315
351
ldapPassword string
316
352
err string
317
353
}{
354
+ {
355
+ name : "with correct aws endpoint" ,
356
+ provider : "aws" ,
357
+ stsSpec : & sourcev1.BucketSTSSpec {
358
+ Provider : "aws" ,
359
+ Endpoint : awsSTSEndpoint ,
360
+ },
361
+ },
362
+ {
363
+ name : "with incorrect aws endpoint" ,
364
+ provider : "aws" ,
365
+ stsSpec : & sourcev1.BucketSTSSpec {
366
+ Provider : "aws" ,
367
+ Endpoint : fmt .Sprintf ("http://localhost:%d" , awsSTSPort + 1 ),
368
+ },
369
+ err : "connection refused" ,
370
+ },
371
+ {
372
+ name : "with correct aws endpoint and proxy" ,
373
+ provider : "aws" ,
374
+ stsSpec : & sourcev1.BucketSTSSpec {
375
+ Provider : "aws" ,
376
+ Endpoint : awsSTSEndpoint ,
377
+ },
378
+ opts : []Option {WithProxyURL (& url.URL {Scheme : "http" , Host : proxyAddr })},
379
+ },
380
+ {
381
+ name : "with correct aws endpoint and incorrect proxy" ,
382
+ provider : "aws" ,
383
+ stsSpec : & sourcev1.BucketSTSSpec {
384
+ Provider : "aws" ,
385
+ Endpoint : awsSTSEndpoint ,
386
+ },
387
+ opts : []Option {WithProxyURL (& url.URL {Scheme : "http" , Host : fmt .Sprintf ("localhost:%d" , proxyPort + 1 )})},
388
+ err : "connection refused" ,
389
+ },
318
390
{
319
391
name : "with correct ldap endpoint" ,
320
392
provider : "generic" ,
0 commit comments