From 595d8cb6689a2c6f6f4444125127270b2e10b380 Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Fri, 17 May 2024 11:28:43 +0200 Subject: http: ignore http_proxy env in tests Type: test Change-Id: I45a091a43e7ecb3f321fc9ecc761df2b44c9c351 Signed-off-by: Matus Fabian --- extras/hs-test/http_test.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index f52d2816930..37416194e6c 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -115,10 +115,13 @@ func HttpStaticMovedTest(s *NoTopoSuite) { serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() s.log(vpp.vppctl("http static server www-root /tmp uri tcp://" + serverAddress + "/80 debug")) + transport := http.DefaultTransport + transport.(*http.Transport).Proxy = nil client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, + Transport: transport, } req, err := http.NewRequest("GET", "http://"+serverAddress+":80/tmp.aaa", nil) s.assertNil(err, fmt.Sprint(err)) @@ -134,9 +137,12 @@ func HttpStaticNotFoundTest(s *NoTopoSuite) { serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() s.log(vpp.vppctl("http static server www-root /tmp uri tcp://" + serverAddress + "/80 debug")) + transport := http.DefaultTransport + transport.(*http.Transport).Proxy = nil + client := &http.Client{Transport: transport} req, err := http.NewRequest("GET", "http://"+serverAddress+":80/notfound.html", nil) s.assertNil(err, fmt.Sprint(err)) - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) s.assertNil(err, fmt.Sprint(err)) defer resp.Body.Close() s.assertEqual(404, resp.StatusCode) @@ -147,9 +153,12 @@ func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() vpp.vppctl("http cli server") + transport := http.DefaultTransport + transport.(*http.Transport).Proxy = nil + client := &http.Client{Transport: transport} req, err := http.NewRequest("POST", "http://"+serverAddress+":80/test", nil) s.assertNil(err, fmt.Sprint(err)) - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) s.assertNil(err, fmt.Sprint(err)) defer resp.Body.Close() s.assertEqual(405, resp.StatusCode) @@ -162,9 +171,12 @@ func HttpCliBadRequestTest(s *NoTopoSuite) { serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() vpp.vppctl("http cli server") + transport := http.DefaultTransport + transport.(*http.Transport).Proxy = nil + client := &http.Client{Transport: transport} req, err := http.NewRequest("GET", "http://"+serverAddress+":80", nil) s.assertNil(err, fmt.Sprint(err)) - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) s.assertNil(err, fmt.Sprint(err)) defer resp.Body.Close() s.assertEqual(400, resp.StatusCode) @@ -175,9 +187,12 @@ func HeaderServerTest(s *NoTopoSuite) { serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() vpp.vppctl("http cli server") + transport := http.DefaultTransport + transport.(*http.Transport).Proxy = nil + client := &http.Client{Transport: transport} req, err := http.NewRequest("GET", "http://"+serverAddress+":80/show/version", nil) s.assertNil(err, fmt.Sprint(err)) - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) s.assertNil(err, fmt.Sprint(err)) defer resp.Body.Close() s.assertEqual("http_cli_server", resp.Header.Get("Server")) -- cgit 1.2.3-korg