@@ -7,9 +7,11 @@ import (
77 "fmt"
88 "net/http"
99 "net/http/httptest"
10+ "os"
1011 "testing"
1112 "time"
1213
14+ "github.com/bradleyfalzon/ghinstallation"
1315 "github.com/hashicorp/vault/sdk/logical"
1416 "gotest.tools/assert"
1517
@@ -541,3 +543,35 @@ func TestClient_RevokeToken(t *testing.T) {
541543 })
542544 }
543545}
546+
547+ func TestNewClient_WithProxy (t * testing.T ) {
548+ t .Parallel ()
549+
550+ proxyURL := "http://proxy.example.com:8080"
551+ os .Setenv ("HTTP_PROXY" , proxyURL )
552+ os .Setenv ("HTTPS_PROXY" , proxyURL )
553+ os .Setenv ("NO_PROXY" , "localhost,127.0.0.1" )
554+ defer os .Unsetenv ("HTTP_PROXY" )
555+ defer os .Unsetenv ("HTTPS_PROXY" )
556+ defer os .Unsetenv ("NO_PROXY" )
557+
558+ conf := & Config {
559+ AppID : testAppID1 ,
560+ PrvKey : testPrvKeyValid ,
561+ BaseURL : testBaseURLValid ,
562+ }
563+
564+ client , err := NewClient (conf )
565+ assert .NilError (t , err )
566+
567+ // checks that the Transport wrapped by the client with a AppsTransport handles Proxy properly
568+ appTransport , ok := client .installationsClient .Transport .(* ghinstallation.AppsTransport )
569+ transport := appTransport .Client .(* http.Client ).Transport .(* http.Transport )
570+ assert .Assert (t , ok )
571+ assert .Assert (t , appTransport != nil )
572+
573+ req , _ := http .NewRequest ("GET" , "http://example.com" , nil )
574+ proxy , err := transport .Proxy (req )
575+ assert .NilError (t , err )
576+ assert .Equal (t , proxy .String (), proxyURL )
577+ }
0 commit comments