Skip to content

Commit

Permalink
Ensure http client Transport is defined before trying to set Insecure…
Browse files Browse the repository at this point in the history
…SkipVerify

The http client we get from the oci-go-sdk lets it default to
http.DefaultTransport, but this isn't set at the time we try and
configure the TLSClientConfig to set InsecureSkipVerify to true
(when the provider has disable-certs set).
  • Loading branch information
George Jensen authored and gcjensen committed Mar 4, 2021
1 parent 8b18fab commit 513b92c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions provider/oracle/oracle_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ func (t ociSigningRoundTripper) intercept(request *http.Request) (err error) {

// Skip verification of insecure certs
func InsecureRoundTripper(roundTripper http.RoundTripper) http.RoundTripper {
transport := roundTripper.(*http.Transport)
if transport != nil {
if roundTripper == nil {
roundTripper = http.DefaultTransport
}

if transport, ok := roundTripper.(*http.Transport); ok {
if transport.TLSClientConfig != nil {
transport.TLSClientConfig.InsecureSkipVerify = true
} else {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
return transport
}

return transport
return nil
}

//-- Provider interface impl ----------------------------------------------------------------------------------
Expand Down
26 changes: 26 additions & 0 deletions provider/oracle/oracle_common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package oracle

import (
"net/http"
"testing"
)

func TestInsecureRoundTripper(t *testing.T) {
testCases := []http.RoundTripper{
http.DefaultTransport, // Normal case
nil, // Ensure it creates a DefaultTransport in the nil case
}

for _, transport := range testCases {
roundTripper := InsecureRoundTripper(transport)
transport, ok := roundTripper.(*http.Transport)

if !ok {
t.Fatal("Transport not correctly returned")
}

if transport.TLSClientConfig == nil || !transport.TLSClientConfig.InsecureSkipVerify {
t.Fatal("InsecureSkipVerify not correctly set on transport")
}
}
}

0 comments on commit 513b92c

Please sign in to comment.