Skip to content

Commit

Permalink
tests: integration tests for policies only with unmatching route sele…
Browse files Browse the repository at this point in the history
…ctors
  • Loading branch information
guicassolato committed Oct 5, 2023
1 parent 0f86599 commit 7982c80
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -362,6 +363,48 @@ var _ = Describe("AuthPolicy controller", func() {
}, 30*time.Second, 5*time.Second).Should(BeTrue())
})

It("Rejects policy only with unmatching route selectors", func() {
policy := &api.AuthPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "toystore",
Namespace: testNamespace,
},
Spec: api.AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Kind: "HTTPRoute",
Name: testHTTPRouteName,
Namespace: ptr.To(gatewayapiv1beta1.Namespace(testNamespace)),
},
RouteSelectors: []api.RouteSelector{
{ // does not select any HTTPRouteRule
Matches: []gatewayapiv1alpha2.HTTPRouteMatch{
{
Method: ptr.To(gatewayapiv1alpha2.HTTPMethod("DELETE")),
},
},
},
},
AuthScheme: testBasicAuthScheme(),
},
}

err := k8sClient.Create(context.Background(), policy)
logf.Log.V(1).Info("Creating AuthPolicy", "key", client.ObjectKeyFromObject(policy).String(), "error", err)
Expect(err).ToNot(HaveOccurred())

// check policy status
Eventually(func() bool {
existingPolicy := &api.AuthPolicy{}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(policy), existingPolicy)
if err != nil {
return false
}
condition := meta.FindStatusCondition(existingPolicy.Status.Conditions, APAvailableConditionType)
return condition != nil && condition.Reason == "ReconciliationError" && strings.Contains(condition.Message, "cannot match any route rules, check for invalid route selectors in the policy")
}, 30*time.Second, 5*time.Second).Should(BeTrue())
})

It("Deletes resources when the policy is deleted", func() {
policy := &api.AuthPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 7982c80

Please sign in to comment.