From d8212e6c43f0f799afa6fceb2d8edeafbf33a032 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 --- conformance/conformance_test.go | 20 +++++++++- .../tests/tlsroute-simple-same-namespace.go | 13 +++---- .../tests/tlsroute-simple-same-namespace.yaml | 2 +- conformance/utils/flags/flags.go | 1 + conformance/utils/http/http.go | 16 ++++++-- conformance/utils/tls/tls.go | 37 +------------------ 6 files changed, 39 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/flags/flags.go b/conformance/utils/flags/flags.go index 5159773987..15b8334f6d 100644 --- a/conformance/utils/flags/flags.go +++ b/conformance/utils/flags/flags.go @@ -29,4 +29,5 @@ var ( CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run") SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites") ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites") + RunOneTest = flag.String("test", "", "A single test name when you want to run only one") ) diff --git a/conformance/utils/http/http.go b/conformance/utils/http/http.go index 47d0ec08ab..2ee3044e77 100644 --- a/conformance/utils/http/http.go +++ b/conformance/utils/http/http.go @@ -93,6 +93,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" } @@ -101,15 +109,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{}, } @@ -125,7 +133,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) }