...
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, HTTPRouteInvalidReferenceGrant)
33 }
34
35 var HTTPRouteInvalidReferenceGrant = suite.ConformanceTest{
36 ShortName: "HTTPRouteInvalidReferenceGrant",
37 Description: "A single HTTPRoute in the gateway-conformance-infra namespace, with a backendRef in another namespace without valid ReferenceGrant, should have the ResolvedRefs condition set to False and not forward HTTP requests to any backend",
38 Features: []suite.SupportedFeature{
39 suite.SupportGateway,
40 suite.SupportHTTPRoute,
41 suite.SupportReferenceGrant,
42 },
43 Manifests: []string{"tests/httproute-invalid-reference-grant.yaml"},
44 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
45 routeNN := types.NamespacedName{Name: "reference-grant", Namespace: "gateway-conformance-infra"}
46 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
47 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
48
49 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) {
50 resolvedRefsCond := metav1.Condition{
51 Type: string(v1.RouteConditionResolvedRefs),
52 Status: metav1.ConditionFalse,
53 Reason: string(v1.RouteReasonRefNotPermitted),
54 }
55
56 kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, resolvedRefsCond)
57 })
58
59 t.Run("Simple HTTP request not should reach web-backend", func(t *testing.T) {
60 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
61 Request: http.Request{
62 Method: "GET",
63 Path: "/",
64 },
65 Response: http.Response{StatusCode: 500},
66 Backend: "web-backend",
67 Namespace: "gateway-conformance-web-backend",
68 })
69 })
70 },
71 }
72
View as plain text