openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dube...@apache.org
Subject [incubator-openwhisk-client-go] branch master updated: Use a transport based on the DefaultTransport to pick up proxy support (#55)
Date Mon, 29 Jan 2018 21:16:36 GMT
This is an automated email from the ASF dual-hosted git repository.

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new f9938a3  Use a transport based on the DefaultTransport to pick up proxy support (#55)
f9938a3 is described below

commit f9938a3594f021d64657f6d04b77f0629bbffa85
Author: Mark Deuser <mdeuser@us.ibm.com>
AuthorDate: Mon Jan 29 16:16:34 2018 -0500

    Use a transport based on the DefaultTransport to pick up proxy support (#55)
---
 whisk/client.go        |  8 +++++---
 whisk/client_test.go   | 35 +++++++++++++++++++++++++++++++++++
 whisk/wskprops_test.go |  2 +-
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/whisk/client.go b/whisk/client.go
index 9734a0c..6c43cf2 100644
--- a/whisk/client.go
+++ b/whisk/client.go
@@ -196,9 +196,11 @@ func (c *Client) LoadX509KeyPair() error {
 		}
 	}
 
-	c.client.Transport = &http.Transport{
-		TLSClientConfig: tlsConfig,
-	}
+	// Use the defaultTransport as the transport basis to maintain proxy support
+	// Make a copy of the defaultTransport so that the original defaultTransport is left alone
+	defaultTransportCopy := *(http.DefaultTransport.(*http.Transport))
+	defaultTransportCopy.TLSClientConfig = tlsConfig
+	c.client.Transport = &defaultTransportCopy
 
 	return nil
 }
diff --git a/whisk/client_test.go b/whisk/client_test.go
index ff1c63d..1752b40 100644
--- a/whisk/client_test.go
+++ b/whisk/client_test.go
@@ -24,6 +24,7 @@ import (
 	"github.com/stretchr/testify/assert"
 	"net/http"
 	"net/url"
+	"os"
 	"testing"
 )
 
@@ -105,3 +106,37 @@ func TestNewClient(t *testing.T) {
 	assert.Equal(t, FakeBaseURLDiff, client.Config.BaseURL.String())
 	assert.Equal(t, FakeAuthKey, client.Config.AuthToken)
 }
+
+func TestProxyHost(t *testing.T) {
+	var proxyhost = "one.bad.url.going.nowhere.org"
+	var proxyurl = "https://" + proxyhost
+
+	config := GetValidConfigTest()
+	client, err := NewClient(nil, config)
+	assert.NotNil(t, client)
+
+	// This will update the transport
+	err = client.LoadX509KeyPair()
+	assert.Nil(t, err, "LoadX509KeyPair() failed")
+
+	req, err := client.NewRequest("GET", config.BaseURL.String(), nil, false)
+	assert.Nil(t, err, "NewRequest for proxy test failed.")
+	if err != nil {
+		fmt.Printf("NewRequest() error: %s\n", err.Error())
+	}
+
+	// Proxy is enabled by setting env
+	if priorProxyEnv, priorProxyEnvSet := os.LookupEnv("HTTPS_PROXY"); priorProxyEnvSet {
+		err = os.Unsetenv("HTTPS_PROXY")
+		assert.Nil(t, err, "Unsetenv(HTTPS_PROXY) failed: "+err.Error())
+		defer os.Setenv("HTTPS_PROXY", priorProxyEnv)
+	}
+	os.Setenv("HTTPS_PROXY", proxyurl)
+
+	// Issue request that should fail due to a bad proxy host
+	_, err = client.Do(req, nil, true)
+	assert.NotNil(t, err, "Do() did not fail with invalid proxy URL.")
+	if err != nil {
+		assert.Contains(t, err.Error(), proxyhost, "Setting HTTPS_PROXY to '"+proxyhost+"' did
not cause the CLI to use that proxy URL.")
+	}
+}
diff --git a/whisk/wskprops_test.go b/whisk/wskprops_test.go
index e702760..f598d70 100644
--- a/whisk/wskprops_test.go
+++ b/whisk/wskprops_test.go
@@ -1,4 +1,4 @@
-//// +build unit
+// +build unit
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more

-- 
To stop receiving notification emails like this one, please contact
dubeejw@apache.org.

Mime
View raw message