Skip to content

Commit

Permalink
Add http/2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb-solo committed Jun 20, 2024
1 parent 2bf9e75 commit 28f0fe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/e2e/header_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

})
19 changes: 16 additions & 3 deletions test/testutils/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,7 @@ type HttpClientBuilder struct {
rootCaCert string
serverName string
proxyProtocolBytes []byte
useHttp2 bool
}

// DefaultClientBuilder returns an HttpClientBuilder with some default values
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 28f0fe5

Please sign in to comment.