From ab91a3fc6362453a65412e109d8049aceae6a33c Mon Sep 17 00:00:00 2001 From: candita Date: Mon, 19 Dec 2022 18:39:20 -0500 Subject: [PATCH] Issue #1579 TLSRoute Passthrough - PR review update - rebase --- conformance/conformance_test.go | 20 +++++++++- .../tests/tlsroute-simple-same-namespace.go | 13 +++---- .../tests/tlsroute-simple-same-namespace.yaml | 2 +- conformance/utils/http/http.go | 16 ++++++-- conformance/utils/tls/tls.go | 37 +------------------ 5 files changed, 38 insertions(+), 50 deletions(-) diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go index a81adc221c..faa26cc3ff 100644 --- a/conformance/conformance_test.go +++ b/conformance/conformance_test.go @@ -49,8 +49,24 @@ func TestConformance(t *testing.T) { for feature := range exemptFeatures { supportedFeatures[feature] = false } - t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]", - *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.SupportedFeatures, *flags.ExemptFeatures) + + // Check if this should be a single test run + if *flags.RunOneTest != "" { + saved := []suite.ConformanceTest{} + for _, ctest := range tests.ConformanceTests { + if ctest.ShortName == *flags.RunOneTest { + saved = append(saved, ctest) + break + } + } + tests.ConformanceTests = saved + if len(saved) == 0 { + t.Fatalf("error, no such test: %s", *flags.RunOneTest) + } + } + + t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]\n run one test: %s", + *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.SupportedFeatures, *flags.ExemptFeatures, *flags.RunOneTest) cSuite := suite.New(suite.Options{ Client: client, diff --git a/conformance/tests/tlsroute-simple-same-namespace.go b/conformance/tests/tlsroute-simple-same-namespace.go index 8859a3c45b..20f9b21e4d 100644 --- a/conformance/tests/tlsroute-simple-same-namespace.go +++ b/conformance/tests/tlsroute-simple-same-namespace.go @@ -48,18 +48,17 @@ var TLSRouteSimpleSameNamespace = suite.ConformanceTest{ gwNN := types.NamespacedName{Name: "gateway-tlsroute", Namespace: string(ns)} certNN := types.NamespacedName{Name: "tls-passthrough-checks-certificate", Namespace: string(ns)} - gwAddr, server := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) - if len(server) != 1 { - fmt.Errorf("one and only one server required for TLS") + gwAddr, hostnames := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) + if len(hostnames) != 1 { + t.Fatalf("unexpected error in test configuration, found %d hostnames", len(hostnames)) } - serverStr := string(server[0]) + serverStr := string(hostnames[0]) cPem, kPem, err := GetTLSSecret(suite.Client, certNN) if err != nil { - fmt.Errorf("unexpected error finding TLS secret: %w", err) + t.Fatalf("unexpected error finding TLS secret: %v", err) } - - t.Run("Simple HTTP request for TLSRoute should reach infra-backend", func(t *testing.T) { + t.Run("Simple TLS request matching TLSRoute should reach infra-backend", func(t *testing.T) { tls.MakeTLSRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, cPem, kPem, serverStr, http.ExpectedResponse{ Request: http.Request{Host: serverStr, Path: "/"}, diff --git a/conformance/tests/tlsroute-simple-same-namespace.yaml b/conformance/tests/tlsroute-simple-same-namespace.yaml index 07c878a2d3..dea677bb9a 100644 --- a/conformance/tests/tlsroute-simple-same-namespace.yaml +++ b/conformance/tests/tlsroute-simple-same-namespace.yaml @@ -32,4 +32,4 @@ spec: kinds: - kind: TLSRoute tls: - mode: Passthrough \ No newline at end of file + mode: Passthrough diff --git a/conformance/utils/http/http.go b/conformance/utils/http/http.go index 333bdfb014..2c1dd6fbfa 100644 --- a/conformance/utils/http/http.go +++ b/conformance/utils/http/http.go @@ -96,6 +96,14 @@ const requiredConsecutiveSuccesses = 3 func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripper.RoundTripper, timeoutConfig config.TimeoutConfig, gwAddr string, expected ExpectedResponse) { t.Helper() + req := MakeRequest(t, &expected, gwAddr, "HTTP", "http") + + WaitForConsistentResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency) +} + +func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, scheme string) roundtripper.Request { + t.Helper() + if expected.Request.Method == "" { expected.Request.Method = "GET" } @@ -104,15 +112,15 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp expected.Response.StatusCode = 200 } - t.Logf("Making %s request to http://%s%s", expected.Request.Method, gwAddr, expected.Request.Path) + t.Logf("Making %s request to %s://%s%s", expected.Request.Method, scheme, gwAddr, expected.Request.Path) path, query, _ := strings.Cut(expected.Request.Path, "?") req := roundtripper.Request{ Method: expected.Request.Method, Host: expected.Request.Host, - URL: url.URL{Scheme: "http", Host: gwAddr, Path: path, RawQuery: query}, - Protocol: "HTTP", + URL: url.URL{Scheme: scheme, Host: gwAddr, Path: path, RawQuery: query}, + Protocol: protocol, Headers: map[string][]string{}, UnfollowRedirect: expected.Request.UnfollowRedirect, } @@ -129,7 +137,7 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp } req.Headers["X-Echo-Set-Header"] = []string{strings.Join(backendSetHeaders, ",")} - WaitForConsistentResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency) + return req } // AwaitConvergence runs the given function until it returns 'true' `threshold` times in a row. diff --git a/conformance/utils/tls/tls.go b/conformance/utils/tls/tls.go index 917a110e7e..938d1150f4 100644 --- a/conformance/utils/tls/tls.go +++ b/conformance/utils/tls/tls.go @@ -17,8 +17,6 @@ limitations under the License. package tls import ( - "net/url" - "strings" "testing" "time" @@ -41,40 +39,7 @@ const requiredConsecutiveSuccesses = 3 func MakeTLSRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripper.RoundTripper, timeoutConfig config.TimeoutConfig, gwAddr string, cPem, kPem []byte, server string, expected http.ExpectedResponse) { t.Helper() - protocol := "HTTPS" - scheme := "https" - - if expected.Request.Method == "" { - expected.Request.Method = "GET" - } - - if expected.Response.StatusCode == 0 { - expected.Response.StatusCode = 200 - } - - t.Logf("Making %s request to %s://%s%s", expected.Request.Method, scheme, gwAddr, expected.Request.Path) - - path, query, _ := strings.Cut(expected.Request.Path, "?") - - req := roundtripper.Request{ - Method: expected.Request.Method, - Host: expected.Request.Host, - URL: url.URL{Scheme: scheme, Host: gwAddr, Path: path, RawQuery: query}, - Protocol: protocol, - Headers: map[string][]string{}, - } - - if expected.Request.Headers != nil { - for name, value := range expected.Request.Headers { - req.Headers[name] = []string{value} - } - } - - backendSetHeaders := []string{} - for name, val := range expected.BackendSetResponseHeaders { - backendSetHeaders = append(backendSetHeaders, name+":"+val) - } - req.Headers["X-Echo-Set-Header"] = []string{strings.Join(backendSetHeaders, ",")} + req := http.MakeRequest(t, &expected, gwAddr, "HTTPS", "https") WaitForConsistentTLSResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency, cPem, kPem, server) }