|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package tests |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "k8s.io/apimachinery/pkg/types" |
| 23 | + |
| 24 | + "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 25 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 26 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 27 | + "sigs.k8s.io/gateway-api/conformance/utils/tls" |
| 28 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 29 | +) |
| 30 | + |
| 31 | +func init() { |
| 32 | + ConformanceTests = append(ConformanceTests, TLSRouteTerminateSimpleSameNamespace) |
| 33 | +} |
| 34 | + |
| 35 | +var TLSRouteTerminateSimpleSameNamespace = suite.ConformanceTest{ |
| 36 | + ShortName: "TLSRouteTerminateSimpleSameNamespace", |
| 37 | + Description: "A single TLSRoute in the gateway-conformance-infra namespace attaches to a Gateway using Terminate mode in the same namespace", |
| 38 | + Features: []features.FeatureName{ |
| 39 | + features.SupportGateway, |
| 40 | + features.SupportTLSRoute, |
| 41 | + }, |
| 42 | + Manifests: []string{"tests/tlsroute-terminate-simple-same-namespace.yaml"}, |
| 43 | + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { |
| 44 | + ns := "gateway-conformance-infra" |
| 45 | + routeNN := types.NamespacedName{Name: "gateway-conformance-infra-test", Namespace: ns} |
| 46 | + gwNN := types.NamespacedName{Name: "gateway-tlsroute-terminate", Namespace: ns} |
| 47 | + certNN := types.NamespacedName{Name: "tls-checks-certificate", Namespace: ns} |
| 48 | + |
| 49 | + kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, []string{ns}) |
| 50 | + |
| 51 | + gwAddr, hostnames := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) |
| 52 | + if len(hostnames) != 1 { |
| 53 | + t.Fatalf("unexpected error in test configuration, found %d hostnames", len(hostnames)) |
| 54 | + } |
| 55 | + serverStr := string(hostnames[0]) |
| 56 | + |
| 57 | + cPem, keyPem, err := GetTLSSecret(suite.Client, certNN) |
| 58 | + if err != nil { |
| 59 | + t.Fatalf("unexpected error finding TLS secret: %v", err) |
| 60 | + } |
| 61 | + t.Run("Simple TLS request matching TLSRoute should reach infra-backend", func(t *testing.T) { |
| 62 | + tls.MakeTLSRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, cPem, keyPem, serverStr, |
| 63 | + http.ExpectedResponse{ |
| 64 | + Request: http.Request{Host: serverStr, Path: "/"}, |
| 65 | + Backend: "infra-backend-v2", |
| 66 | + Namespace: "gateway-conformance-infra", |
| 67 | + }) |
| 68 | + }) |
| 69 | + }, |
| 70 | +} |
0 commit comments