Skip to content

Commit

Permalink
should reject empty Consumer (#624)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Jul 4, 2024
1 parent 56102be commit b52c8ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions types/apis/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions types/apis/v1/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b52c8ae

Please sign in to comment.