forked from envoyproxy/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: Add an e2e test for useClientProtocol (envoyproxy#3314)
* Added an e2e test for useClientProtocol Signed-off-by: Lior Okman <lior.okman@sap.com> * make linter happy Signed-off-by: Lior Okman <lior.okman@sap.com> --------- Signed-off-by: Lior Okman <lior.okman@sap.com>
- Loading branch information
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: BackendTrafficPolicy | ||
metadata: | ||
name: use-client-protocol-btp | ||
namespace: gateway-conformance-infra | ||
spec: | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
name: use-client-protocol | ||
namespace: gateway-conformance-infra | ||
useClientProtocol: true | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: use-client-protocol | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: same-namespace | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /http11 | ||
backendRefs: | ||
- name: infra-backend-v1 | ||
port: 8080 | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /http2 | ||
backendRefs: | ||
- name: infra-backend-v1 | ||
port: 8081 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
//go:build e2e | ||
// +build e2e | ||
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/gateway-api/conformance/utils/http" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, UseClientProtocolTest) | ||
} | ||
|
||
var UseClientProtocolTest = suite.ConformanceTest{ | ||
ShortName: "UseClientProtocol", | ||
Description: "Test that the UseClientProtocol knob does what it's supposed to", | ||
Manifests: []string{"testdata/use-client-protocol.yaml"}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
t.Run("use client protocol", func(t *testing.T) { | ||
ns := "gateway-conformance-infra" | ||
routeNN := types.NamespacedName{Name: "use-client-protocol", Namespace: ns} | ||
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
|
||
// Send an http/1.1 request to the /http11 path | ||
expectedResponse := http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/http11/headers", | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 200, | ||
}, | ||
Namespace: ns, | ||
} | ||
|
||
req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response: %v", err) | ||
} | ||
|
||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response: %v", err) | ||
} | ||
if cReq.Protocol != "HTTP/1.1" { | ||
t.Errorf("expected http/1.1 protocol, got %s", cReq.Protocol) | ||
} | ||
|
||
// Send an http/1.1 request to the http/2 path | ||
expectedResponse = http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/http2/headers", | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 400, | ||
}, | ||
Namespace: ns, | ||
} | ||
|
||
req = http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
cReq, cResp, err = suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response: %v", err) | ||
} | ||
|
||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response: %v", err) | ||
} | ||
|
||
// Send an http/2 request to the /http2 path | ||
expectedResponse = http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/http2/headers", | ||
Protocol: roundtripper.H2CPriorKnowledgeProtocol, | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 200, | ||
}, | ||
Namespace: ns, | ||
} | ||
|
||
req = http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
cReq, cResp, err = suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response: %v", err) | ||
} | ||
|
||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response: %v", err) | ||
} | ||
if cReq.Protocol != "HTTP/2.0" { | ||
t.Errorf("expected http/2.0 protocol, got %s", cReq.Protocol) | ||
} | ||
|
||
// Send an http/2 request to the http/1.1 path | ||
expectedResponse = http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/http11/headers", | ||
Protocol: roundtripper.H2CPriorKnowledgeProtocol, | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 502, | ||
}, | ||
Namespace: ns, | ||
} | ||
|
||
req = http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
cReq, cResp, err = suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response: %v", err) | ||
} | ||
|
||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response: %v", err) | ||
} | ||
}) | ||
}, | ||
} |