Skip to content

Commit

Permalink
Issue #1579 TLSRoute Passthrough - PR review update
Browse files Browse the repository at this point in the history
  • Loading branch information
candita committed Dec 19, 2022
1 parent 1d54add commit d8212e6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 50 deletions.
20 changes: 18 additions & 2 deletions conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 6 additions & 7 deletions conformance/tests/tlsroute-simple-same-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "/"},
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/tlsroute-simple-same-namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ spec:
kinds:
- kind: TLSRoute
tls:
mode: Passthrough
mode: Passthrough
1 change: 1 addition & 0 deletions conformance/utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
16 changes: 12 additions & 4 deletions conformance/utils/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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{},
}

Expand All @@ -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.
Expand Down
37 changes: 1 addition & 36 deletions conformance/utils/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package tls

import (
"net/url"
"strings"
"testing"
"time"

Expand All @@ -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)
}
Expand Down

0 comments on commit d8212e6

Please sign in to comment.