Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/apis/configuration/validation/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,20 @@ func validateOIDC(oidc *v1.OIDC, fieldPath *field.Path) field.ErrorList {

func validateAPIKey(apiKey *v1.APIKey, fieldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

if apiKey == nil {
allErrs = append(allErrs, field.Required(fieldPath, "apiKey cannot be nil"))
return allErrs
}

if apiKey.SuppliedIn == nil {
allErrs = append(allErrs, field.Required(fieldPath.Child("suppliedIn"), "suppliedIn cannot be nil"))
return allErrs
}

if apiKey.SuppliedIn.Query == nil && apiKey.SuppliedIn.Header == nil {
msg := "at least one query or header name must be provided"
allErrs = append(allErrs, field.Required(fieldPath.Child("SuppliedIn"), msg))
allErrs = append(allErrs, field.Required(fieldPath.Child("suppliedIn"), msg))
}

if apiKey.SuppliedIn.Header != nil {
Expand All @@ -316,11 +327,11 @@ func validateAPIKey(apiKey *v1.APIKey, fieldPath *field.Path) field.ErrorList {
}

if apiKey.ClientSecret == "" {
allErrs = append(allErrs, field.Required(fieldPath.Child("clientSecret"), ""))
allErrs = append(allErrs, field.Required(fieldPath.Child("clientSecret"), "clientSecret cannot be empty"))
} else {
allErrs = append(allErrs, validateSecretName(apiKey.ClientSecret, fieldPath.Child("clientSecret"))...)
}

allErrs = append(allErrs, validateSecretName(apiKey.ClientSecret, fieldPath.Child("clientSecret"))...)

return allErrs
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/configuration/validation/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,16 @@ func TestValidateAPIKeyPolicy_FailsOnInvalidInput(t *testing.T) {
},
msg: "invalid secret name",
},
{
apiKey: &v1.APIKey{
ClientSecret: "secret_1",
},
msg: "no suppliedIn provided",
},

{
apiKey: nil, msg: "no apikey provided",
},
}

for _, test := range tests {
Expand Down