From 28f0fe5a9c0f16f7521420e32590c1a2b5fb448e Mon Sep 17 00:00:00 2001 From: Ashish Banerjee Date: Thu, 20 Jun 2024 16:16:19 -0400 Subject: [PATCH] Add http/2 test --- test/e2e/header_validation_test.go | 8 ++++++++ test/testutils/http_client.go | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/test/e2e/header_validation_test.go b/test/e2e/header_validation_test.go index e5012f747c0..777f7130aa0 100644 --- a/test/e2e/header_validation_test.go +++ b/test/e2e/header_validation_test.go @@ -87,6 +87,14 @@ var _ = Describe("Header Validation", Label(), func() { req := buildRequest() Expect(testutils.DefaultHttpClient.Do(req)).Should(matchers.HaveStatusCode(http.StatusOK)) }) + + // We expect this test to fail when UHV is enabled in upstream Envoy + It("does not allow custom HTTP methods on HTTP/2", func() { + waitUntilProxyIsRunning() + req := buildRequest() + testClient := testutils.DefaultClientBuilder().WithHttp2(true).Build() + Expect(testClient.Do(req)).Should(matchers.HaveStatusCode(http.StatusOK)) + }) }) }) diff --git a/test/testutils/http_client.go b/test/testutils/http_client.go index ba29281e0d4..3064beac464 100644 --- a/test/testutils/http_client.go +++ b/test/testutils/http_client.go @@ -9,6 +9,7 @@ import ( "time" "github.com/onsi/ginkgo/v2" + "golang.org/x/net/http2" ) // DefaultHttpClient should be used in tests because it configures a timeout which the http.DefaultClient @@ -33,6 +34,7 @@ type HttpClientBuilder struct { rootCaCert string serverName string proxyProtocolBytes []byte + useHttp2 bool } // DefaultClientBuilder returns an HttpClientBuilder with some default values @@ -45,6 +47,11 @@ func DefaultClientBuilder() *HttpClientBuilder { } } +func (c *HttpClientBuilder) WithHttp2(useHttp2 bool) *HttpClientBuilder { + c.useHttp2 = useHttp2 + return c +} + func (c *HttpClientBuilder) WithTimeout(timeout time.Duration) *HttpClientBuilder { c.timeout = timeout return c @@ -128,9 +135,15 @@ func (c *HttpClientBuilder) Build() *http.Client { } } - client.Transport = &http.Transport{ - TLSClientConfig: tlsClientConfig, - DialContext: dialContext, + if c.useHttp2 { + client.Transport = &http2.Transport{ + TLSClientConfig: tlsClientConfig, + } + } else { + client.Transport = &http.Transport{ + TLSClientConfig: tlsClientConfig, + DialContext: dialContext, + } } client.Timeout = c.timeout