diff --git a/tests/framework/framework.go b/tests/framework/framework.go index 6e00cc6a..b65e35eb 100644 --- a/tests/framework/framework.go +++ b/tests/framework/framework.go @@ -2,6 +2,7 @@ package framework import ( "context" + "crypto/tls" "fmt" "io" "math/rand" @@ -217,7 +218,11 @@ func (f *framework) Request(ctx context.Context, t *testing.T, method, host, pat t.Logf("request method=%s host=%s path=%s\n", method, host, path) opt := options.ParseRequestOptions(o...) - req, err := http.NewRequestWithContext(ctx, method, "http://127.0.0.1:18080", nil) + url := "http://127.0.0.1:18080" + if opt.HTTPS { + url = "https://127.0.0.1:18443" + } + req, err := http.NewRequestWithContext(ctx, method, url, nil) require.NoError(t, err) req.Host = host req.URL.Path = path @@ -225,6 +230,11 @@ func (f *framework) Request(ctx context.Context, t *testing.T, method, host, pat CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: opt.TLSSkipVerify, + }, + }, } var res *http.Response if opt.ExpectResponseCode > 0 { diff --git a/tests/framework/options/request.go b/tests/framework/options/request.go index 76fdfac4..357e4e88 100644 --- a/tests/framework/options/request.go +++ b/tests/framework/options/request.go @@ -8,8 +8,17 @@ func ExpectResponseCode(code int) Request { } } +func HTTPSRequest(skipVerify bool) Request { + return func(o *requestOpt) { + o.HTTPS = true + o.TLSSkipVerify = skipVerify + } +} + type requestOpt struct { ExpectResponseCode int + HTTPS bool + TLSSkipVerify bool } func ParseRequestOptions(opts ...Request) (opt requestOpt) { diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6ba85c8d..db25376f 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -68,6 +68,41 @@ func TestIntegrationIngress(t *testing.T) { assert.Equal(t, fmt.Sprintf("https://%s/", hostname), res.HTTPResponse.Header.Get("location")) }) + t.Run("should send default http headers on http request", func(t *testing.T) { + t.Parallel() + svc := f.CreateService(ctx, t, httpServerPort) + _, hostname := f.CreateIngress(ctx, t, svc) + res := f.Request(ctx, t, http.MethodGet, hostname, "/", options.ExpectResponseCode(http.StatusOK)) + assert.True(t, res.EchoResponse) + reqHeaders := map[string]string{ + "accept-encoding": "gzip", + "user-agent": "Go-http-client/1.1", + "x-forwarded-for": "127.0.0.1", + "x-forwarded-proto": "http", + "x-real-ip": "127.0.0.1", + } + assert.Equal(t, reqHeaders, res.ReqHeaders) + }) + + t.Run("should send default http headers on https request", func(t *testing.T) { + t.Parallel() + svc := f.CreateService(ctx, t, httpServerPort) + _, hostname := f.CreateIngress(ctx, t, svc, options.DefaultHostTLS()) + res := f.Request(ctx, t, http.MethodGet, hostname, "/", + options.ExpectResponseCode(http.StatusOK), + options.HTTPSRequest(true), + ) + assert.True(t, res.EchoResponse) + reqHeaders := map[string]string{ + "accept-encoding": "gzip", + "user-agent": "Go-http-client/1.1", + "x-forwarded-for": "127.0.0.1", + "x-forwarded-proto": "https", + "x-real-ip": "127.0.0.1", + } + assert.Equal(t, reqHeaders, res.ReqHeaders) + }) + t.Run("should take leader", func(t *testing.T) { t.Parallel() assert.EventuallyWithT(t, func(collect *assert.CollectT) {