Skip to content

Commit ae5a513

Browse files
zxc111gopherbot
authored andcommitted
net/http: add test for proxyAuth
Change-Id: Ib4edae749ce8da433e992e08a90c9cf3d4357081 GitHub-Last-Rev: 19d87d1 GitHub-Pull-Request: #46102 Reviewed-on: https://go-review.googlesource.com/c/go/+/318690 Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Sean Liao <[email protected]> Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 548dcfe commit ae5a513

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/net/http/proxy_test.go

+39-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import (
1010
"testing"
1111
)
1212

13-
// TODO(mattn):
14-
// test ProxyAuth
15-
1613
var cacheKeysTests = []struct {
1714
proxy string
1815
scheme string
@@ -48,3 +45,42 @@ func ResetProxyEnv() {
4845
}
4946
ResetCachedEnvironment()
5047
}
48+
49+
var proxyAuthTests = []struct {
50+
proxy string
51+
key string
52+
}{
53+
{
54+
"",
55+
"",
56+
},
57+
{
58+
"http://bar.com",
59+
"",
60+
},
61+
{
62+
63+
"Basic Zm9vOg==",
64+
},
65+
{
66+
"http://foo:[email protected]",
67+
"Basic Zm9vOmJhcg==",
68+
},
69+
}
70+
71+
func TestProxyAuthKeys(t *testing.T) {
72+
for _, tt := range proxyAuthTests {
73+
var proxy *url.URL
74+
if tt.proxy != "" {
75+
u, err := url.Parse(tt.proxy)
76+
if err != nil {
77+
t.Fatal(err)
78+
}
79+
proxy = u
80+
}
81+
cm := connectMethod{proxyURL: proxy}
82+
if got := cm.proxyAuth(); got != tt.key {
83+
t.Fatalf("{%q} proxyAuth key = %q; want %q", tt.proxy, got, tt.key)
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)