@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"crypto/tls"
22
22
"crypto/x509"
23
- "encoding/base64"
24
23
"io"
25
24
"net"
26
25
"net/http"
@@ -291,6 +290,16 @@ func TestRoundTripAndNewConnection(t *testing.T) {
291
290
serverStatusCode : http .StatusSwitchingProtocols ,
292
291
shouldError : false ,
293
292
},
293
+ "proxied valid https, proxy auth with chars that percent escape -> valid https" : {
294
+ serverFunc : httpsServerValidHostname (t ),
295
+ proxyServerFunc : httpsServerValidHostname (t ),
296
+ proxyAuth : url .UserPassword ("proxy user" , "proxypasswd%" ),
297
+ clientTLS : & tls.Config {RootCAs : localhostPool },
298
+ serverConnectionHeader : "Upgrade" ,
299
+ serverUpgradeHeader : "SPDY/3.1" ,
300
+ serverStatusCode : http .StatusSwitchingProtocols ,
301
+ shouldError : false ,
302
+ },
294
303
}
295
304
296
305
for k , testCase := range testCases {
@@ -400,18 +409,19 @@ func TestRoundTripAndNewConnection(t *testing.T) {
400
409
}
401
410
}
402
411
403
- var expectedProxyAuth string
404
412
if testCase .proxyAuth != nil {
405
- encodedCredentials := base64 .StdEncoding .EncodeToString ([]byte (testCase .proxyAuth .String ()))
406
- expectedProxyAuth = "Basic " + encodedCredentials
407
- }
408
- if len (expectedProxyAuth ) == 0 && proxyCalledWithAuth {
413
+ expectedUsername := testCase .proxyAuth .Username ()
414
+ expectedPassword , _ := testCase .proxyAuth .Password ()
415
+ username , password , ok := (& http.Request {Header : http.Header {"Authorization" : []string {proxyCalledWithAuthHeader }}}).BasicAuth ()
416
+ if ! ok {
417
+ t .Fatalf ("invalid proxy auth header %s" , proxyCalledWithAuthHeader )
418
+ }
419
+ if username != expectedUsername || password != expectedPassword {
420
+ t .Fatalf ("expected proxy auth \" %s:%s\" , got \" %s:%s\" " , expectedUsername , expectedPassword , username , password )
421
+ }
422
+ } else if proxyCalledWithAuth {
409
423
t .Fatalf ("proxy authorization unexpected, got %q" , proxyCalledWithAuthHeader )
410
424
}
411
- if proxyCalledWithAuthHeader != expectedProxyAuth {
412
- t .Fatalf ("expected to see a call to the proxy with credentials %q, got %q" , testCase .proxyAuth , proxyCalledWithAuthHeader )
413
- }
414
-
415
425
})
416
426
}
417
427
}
0 commit comments