From b52c8aeea34fc854f1b9d4e665173d6255ec7aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 4 Jul 2024 13:56:28 +0800 Subject: [PATCH] should reject empty Consumer (#624) Signed-off-by: spacewander --- types/apis/v1/validation.go | 4 ++++ types/apis/v1/validation_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/types/apis/v1/validation.go b/types/apis/v1/validation.go index 53596d3c..884baee0 100644 --- a/types/apis/v1/validation.go +++ b/types/apis/v1/validation.go @@ -287,6 +287,10 @@ func NormalizeK8sGatewayProtocol(protocol gwapiv1.ProtocolType) string { } func ValidateConsumer(c *Consumer) error { + if len(c.Spec.Auth) == 0 { + return errors.New("authn filter is required") + } + for name, filter := range c.Spec.Auth { plugin := plugins.LoadPluginType(name) if plugin == nil { diff --git a/types/apis/v1/validation_test.go b/types/apis/v1/validation_test.go index d7059773..9e541b7f 100644 --- a/types/apis/v1/validation_test.go +++ b/types/apis/v1/validation_test.go @@ -739,6 +739,13 @@ func TestValidateConsumer(t *testing.T) { }, err: "this http filter can not be added by the consumer: keyAuth", }, + { + name: "empty", + consumer: &Consumer{ + Spec: ConsumerSpec{}, + }, + err: "authn filter is required", + }, } for _, tt := range tests {