Skip to content

Commit 916f58e

Browse files
author
Kate Osborn
committed
Reinstate header/server validation
1 parent f1290da commit 916f58e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

internal/mode/static/policies/clientsettings/validator.go

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func conflicts(a, b ngfAPI.ClientSettingsPolicySpec) bool {
6767
if a.KeepAlive.Timeout != nil && b.KeepAlive.Timeout != nil {
6868
return true
6969
}
70+
7071
}
7172

7273
return false
@@ -173,6 +174,22 @@ func (v *Validator) validateClientKeepAlive(keepAlive ngfAPI.ClientKeepAlive, fi
173174
)
174175
}
175176
}
177+
178+
// This is a special case. The keepalive_timeout directive takes two parameters:
179+
// keepalive_timeout server [header], where header is optional. If header is provided and server is not,
180+
// we can't properly configure the directive.
181+
if keepAlive.Timeout.Header != nil && keepAlive.Timeout.Server == nil {
182+
path := fieldPath.Child("timeout")
183+
184+
allErrs = append(
185+
allErrs,
186+
field.Invalid(
187+
path,
188+
nil,
189+
"server timeout must be set if header timeout is set",
190+
),
191+
)
192+
}
176193
}
177194

178195
return allErrs

internal/mode/static/policies/clientsettings/validator_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ func TestValidator_Validate(t *testing.T) {
9696
"spec.keepAlive.timeout.header",
9797
},
9898
},
99+
{
100+
name: "invalid keepalive timeout; header provided without server",
101+
policy: createModifiedPolicy(func(p *ngfAPI.ClientSettingsPolicy) *ngfAPI.ClientSettingsPolicy {
102+
p.Spec.KeepAlive.Timeout.Server = nil
103+
return p
104+
}),
105+
expErrSubstrings: []string{"spec.keepAlive.timeout"},
106+
},
99107
{
100108
name: "valid",
101109
policy: createValidPolicy(),

0 commit comments

Comments
 (0)