|
| 1 | +/* |
| 2 | +Copyright 2023 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 | + "context" |
| 21 | + "crypto/tls" |
| 22 | + "net" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "golang.org/x/net/http2" |
| 26 | + |
| 27 | + "k8s.io/apimachinery/pkg/types" |
| 28 | + |
| 29 | + "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 30 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 31 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 32 | +) |
| 33 | + |
| 34 | +func init() { |
| 35 | + ConformanceTests = append(ConformanceTests, HTTPRouteBackendProtocolH2C) |
| 36 | +} |
| 37 | + |
| 38 | +var HTTPRouteBackendProtocolH2C = suite.ConformanceTest{ |
| 39 | + ShortName: "HTTPRouteBackendProtocolH2C", |
| 40 | + Description: "A HTTPRoute with a BackendRef that has an appProtocol kubernetes.io/h2c should be functional", |
| 41 | + Features: []suite.SupportedFeature{ |
| 42 | + suite.SupportGateway, |
| 43 | + suite.SupportHTTPRoute, |
| 44 | + suite.SupportHTTPRouteBackendProtocolH2C, |
| 45 | + }, |
| 46 | + Manifests: []string{ |
| 47 | + "tests/httproute-backend-protocol-h2c.yaml", |
| 48 | + }, |
| 49 | + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { |
| 50 | + ns := "gateway-conformance-infra" |
| 51 | + routeNN := types.NamespacedName{Name: "backend-protocol-h2c", Namespace: ns} |
| 52 | + gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} |
| 53 | + gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) |
| 54 | + |
| 55 | + t.Run("http2 prior knowledge request should reach backend", func(t *testing.T) { |
| 56 | + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{ |
| 57 | + Request: http.Request{ |
| 58 | + Transport: &http2.Transport{ |
| 59 | + AllowHTTP: true, |
| 60 | + DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { |
| 61 | + var d net.Dialer |
| 62 | + return d.DialContext(ctx, network, addr) |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + Response: http.Response{StatusCode: 200}, |
| 67 | + Backend: "infra-backend-v1", |
| 68 | + Namespace: "gateway-conformance-infra", |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + t.Run("h2c upgrade request should reach backend", func(t *testing.T) { |
| 73 | + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{ |
| 74 | + Request: http.Request{ |
| 75 | + Headers: map[string]string{ |
| 76 | + "HTTP2-Settings": "", |
| 77 | + "Connection": "Upgrade, HTTP2-Settings", |
| 78 | + }, |
| 79 | + }, |
| 80 | + Response: http.Response{StatusCode: 200}, |
| 81 | + Backend: "infra-backend-v1", |
| 82 | + Namespace: "gateway-conformance-infra", |
| 83 | + }) |
| 84 | + }) |
| 85 | + }, |
| 86 | +} |
0 commit comments