fix: use http.DefaultTransport in S3 client (#4190)
This commit is contained in:
commit
dfeaad7e3b
2 changed files with 52 additions and 3 deletions
|
@ -560,9 +560,8 @@ func New(ctx context.Context, params DriverParameters) (*Driver, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.SkipVerify {
|
if params.SkipVerify {
|
||||||
httpTransport := &http.Transport{
|
httpTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
httpTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
}
|
|
||||||
awsConfig.WithHTTPClient(&http.Client{
|
awsConfig.WithHTTPClient(&http.Client{
|
||||||
Transport: httpTransport,
|
Transport: httpTransport,
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -211,6 +212,55 @@ func TestEmptyRootList(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClientTransport(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
skipverify bool
|
||||||
|
}{
|
||||||
|
{true},
|
||||||
|
{false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
// NOTE(milosgajdos): we cannot simply reuse s3DriverConstructor
|
||||||
|
// because s3DriverConstructor is initialized in init() using the process
|
||||||
|
// env vars: we can not override S3_SKIP_VERIFY env var with t.Setenv
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"region": os.Getenv("AWS_REGION"),
|
||||||
|
"bucket": os.Getenv("S3_BUCKET"),
|
||||||
|
"skipverify": tc.skipverify,
|
||||||
|
}
|
||||||
|
t.Run(fmt.Sprintf("SkipVerify %v", tc.skipverify), func(t *testing.T) {
|
||||||
|
drv, err := FromParameters(context.TODO(), params)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create driver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s3drv := drv.baseEmbed.Base.StorageDriver.(*driver)
|
||||||
|
if tc.skipverify {
|
||||||
|
tr, ok := s3drv.S3.Client.Config.HTTPClient.Transport.(*http.Transport)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("unexpected driver transport")
|
||||||
|
}
|
||||||
|
if !tr.TLSClientConfig.InsecureSkipVerify {
|
||||||
|
t.Errorf("unexpected TLS Config. Expected InsecureSkipVerify: %v, got %v",
|
||||||
|
tc.skipverify,
|
||||||
|
tr.TLSClientConfig.InsecureSkipVerify)
|
||||||
|
}
|
||||||
|
// make sure the proxy is always set
|
||||||
|
if tr.Proxy == nil {
|
||||||
|
t.Fatal("missing HTTP transport proxy config")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// if tc.skipverify is false we do not override the driver
|
||||||
|
// HTTP clien transport and leave it to the AWS SDK.
|
||||||
|
if s3drv.S3.Client.Config.HTTPClient.Transport != nil {
|
||||||
|
t.Errorf("unexpected S3 driver client transport")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStorageClass(t *testing.T) {
|
func TestStorageClass(t *testing.T) {
|
||||||
skipCheck(t)
|
skipCheck(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue