Skip to content

Commit

Permalink
Reinstate header/server validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-osborn committed May 20, 2024
1 parent 5c41398 commit 2842083
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/mode/static/policies/clientsettings/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func conflicts(a, b ngfAPI.ClientSettingsPolicySpec) bool {
if a.KeepAlive.Timeout != nil && b.KeepAlive.Timeout != nil {
return true
}

}

return false
Expand Down Expand Up @@ -173,6 +174,22 @@ func (v *Validator) validateClientKeepAlive(keepAlive ngfAPI.ClientKeepAlive, fi
)
}
}

// This is a special case. The keepalive_timeout directive takes two parameters:
// keepalive_timeout server [header], where header is optional. If header is provided and server is not,
// we can't properly configure the directive.
if keepAlive.Timeout.Header != nil && keepAlive.Timeout.Server == nil {
path := fieldPath.Child("timeout")

allErrs = append(
allErrs,
field.Invalid(
path,
nil,
"server timeout must be set if header timeout is set",
),
)
}
}

return allErrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func TestValidator_Validate(t *testing.T) {
"spec.keepAlive.timeout.header",
},
},
{
name: "invalid keepalive timeout; header provided without server",
policy: createModifiedPolicy(func(p *ngfAPI.ClientSettingsPolicy) *ngfAPI.ClientSettingsPolicy {
p.Spec.KeepAlive.Timeout.Server = nil
return p
}),
expErrSubstrings: []string{"spec.keepAlive.timeout"},
},
{
name: "valid",
policy: createValidPolicy(),
Expand Down

0 comments on commit 2842083

Please sign in to comment.