From dacd0353f962b4e49f19c5d087ae3d5c1e119d2d Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sat, 2 May 2020 20:54:58 +0200 Subject: HostClient can't switch between protocols --- client_test.go | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'client_test.go') diff --git a/client_test.go b/client_test.go index 3f9bc77..4ba78c3 100644 --- a/client_test.go +++ b/client_test.go @@ -245,7 +245,7 @@ func TestClientRedirectSameSchema(t *testing.T) { urlParsed, err := url.Parse(destURL) if err != nil { - fmt.Println(err) + t.Fatal(err) return } @@ -270,7 +270,7 @@ func TestClientRedirectSameSchema(t *testing.T) { } -func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { +func TestClientRedirectClientChangingSchemaHttp2Https(t *testing.T) { t.Parallel() listenHTTPS := testClientRedirectListener(t, true) @@ -287,14 +287,7 @@ func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { destURL := fmt.Sprintf("http://%s/baz", listenHTTP.Addr().String()) - urlParsed, err := url.Parse(destURL) - if err != nil { - fmt.Println(err) - return - } - - reqClient := &HostClient{ - Addr: urlParsed.Host, + reqClient := &Client{ TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, @@ -312,6 +305,42 @@ func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { } } +func TestClientRedirectHostClientChangingSchemaHttp2Https(t *testing.T) { + t.Parallel() + + listenHTTPS := testClientRedirectListener(t, true) + defer listenHTTPS.Close() + + listenHTTP := testClientRedirectListener(t, false) + defer listenHTTP.Close() + + sHTTPS := testClientRedirectChangingSchemaServer(t, listenHTTPS, listenHTTP, true) + defer sHTTPS.Stop() + + sHTTP := testClientRedirectChangingSchemaServer(t, listenHTTPS, listenHTTP, false) + defer sHTTP.Stop() + + destURL := fmt.Sprintf("http://%s/baz", listenHTTP.Addr().String()) + + urlParsed, err := url.Parse(destURL) + if err != nil { + t.Fatal(err) + return + } + + reqClient := &HostClient{ + Addr: urlParsed.Host, + TLSConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + } + + _, _, err = reqClient.GetTimeout(nil, destURL, 4000*time.Millisecond) + if err != ErrHostClientRedirectToDifferentScheme { + t.Fatal("expected HostClient error") + } +} + func testClientRedirectListener(t *testing.T, isTLS bool) net.Listener { var ln net.Listener var err error -- cgit v1.2.3