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, HTTPRoutePartiallyInvalidViaInvalidReferenceGrant)
33 }
34
35 var HTTPRoutePartiallyInvalidViaInvalidReferenceGrant = suite.ConformanceTest{
36 ShortName: "HTTPRoutePartiallyInvalidViaInvalidReferenceGrant",
37 Description: "A single HTTPRoute in the gateway-conformance-infra namespace should attach to a Gateway in the same namespace if the route has a backendRef Service in the gateway-conformance-app-backend namespace and a ReferenceGrant exists but does not grant permission to route to that specific Service",
38 Features: []suite.SupportedFeature{
39 suite.SupportGateway,
40 suite.SupportHTTPRoute,
41 suite.SupportReferenceGrant,
42 },
43 Manifests: []string{"tests/httproute-partially-invalid-via-reference-grant.yaml"},
44 Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
45 routeNN := types.NamespacedName{Name: "invalid-reference-grant", Namespace: "gateway-conformance-infra"}
46 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
47
48
49 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, s.Client, s.TimeoutConfig, s.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
50
51 t.Run("HTTPRoute with BackendRef in another namespace and no ReferenceGrant covering the Service 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, s.Client, s.TimeoutConfig, routeNN, gwNN, resolvedRefsCond)
59 })
60
61 t.Run("HTTP Request to invalid backend with missing referenceGrant should receive a 500", func(t *testing.T) {
62 http.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, http.ExpectedResponse{
63 Request: http.Request{
64 Method: "GET",
65 Path: "/v2",
66 },
67 Response: http.Response{StatusCode: 500},
68 })
69 })
70
71 t.Run("HTTP Request to valid sibling backend should succeed", func(t *testing.T) {
72 http.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, http.ExpectedResponse{
73 Request: http.Request{
74 Method: "GET",
75 Path: "/",
76 },
77 Response: http.Response{StatusCode: 200},
78 Backend: "app-backend-v1",
79 Namespace: "gateway-conformance-app-backend",
80 })
81 })
82 },
83 }
84
View as plain text