...
1
16
17 package tests
18
19 import (
20 "testing"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 "k8s.io/apimachinery/pkg/types"
24
25 v1 "sigs.k8s.io/gateway-api/apis/v1"
26 "sigs.k8s.io/gateway-api/conformance/utils/http"
27 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
28 "sigs.k8s.io/gateway-api/conformance/utils/suite"
29 )
30
31 func init() {
32 ConformanceTests = append(ConformanceTests, HTTPRouteInvalidCrossNamespaceBackendRef)
33 }
34
35 var HTTPRouteInvalidCrossNamespaceBackendRef = suite.ConformanceTest{
36 ShortName: "HTTPRouteInvalidCrossNamespaceBackendRef",
37 Description: "A single HTTPRoute in the gateway-conformance-infra namespace should set a ResolvedRefs status False with reason RefNotPermitted when attempting to bind to a Gateway in the same namespace if the route has a BackendRef Service in the gateway-conformance-web-backend namespace and a ReferenceGrant granting permission to route to that Service does not exist",
38 Features: []suite.SupportedFeature{
39 suite.SupportGateway,
40 suite.SupportHTTPRoute,
41 suite.SupportReferenceGrant,
42 },
43 Manifests: []string{"tests/httproute-invalid-cross-namespace-backend-ref.yaml"},
44 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
45 routeNN := types.NamespacedName{Name: "invalid-cross-namespace-backend-ref", Namespace: "gateway-conformance-infra"}
46 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
47
48
49 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
50
51 t.Run("HTTPRoute with a cross-namespace BackendRef and no ReferenceGrant has a ResolvedRefs Condition with status False and Reason RefNotPermitted", func(t *testing.T) {
52 resolvedRefsCond := metav1.Condition{
53 Type: string(v1.RouteConditionResolvedRefs),
54 Status: metav1.ConditionFalse,
55 Reason: string(v1.RouteReasonRefNotPermitted),
56 }
57
58 kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, resolvedRefsCond)
59 })
60
61 t.Run("HTTP Request to invalid cross-namespace backend must receive a 500", func(t *testing.T) {
62 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
63 Request: http.Request{
64 Method: "GET",
65 Path: "/",
66 },
67 Response: http.Response{StatusCode: 500},
68 })
69 })
70 },
71 }
72
View as plain text