pkg/config: force api.servingCertificate.renewBeforeSeconds to be positive
Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
parent
88f3b41e71
commit
d0a9d8df33
@ -64,6 +64,10 @@ func validateAPI(apiConfig *api.APIConfigSpec) error {
|
||||
return constable.Error("durationSeconds cannot be smaller than renewBeforeSeconds")
|
||||
}
|
||||
|
||||
if *apiConfig.ServingCertificateConfig.RenewBeforeSeconds <= 0 {
|
||||
return constable.Error("renewBefore must be positive")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,16 @@ func TestFromPath(t *testing.T) {
|
||||
path: "testdata/invalid-duration-renew-before.yaml",
|
||||
wantError: "validate api: durationSeconds cannot be smaller than renewBeforeSeconds",
|
||||
},
|
||||
{
|
||||
name: "NegativeRenewBefore",
|
||||
path: "testdata/negative-renew-before.yaml",
|
||||
wantError: "validate api: renewBefore must be positive",
|
||||
},
|
||||
{
|
||||
name: "ZeroRenewBefore",
|
||||
path: "testdata/zero-renew-before.yaml",
|
||||
wantError: "validate api: renewBefore must be positive",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
|
8
pkg/config/testdata/negative-renew-before.yaml
vendored
Normal file
8
pkg/config/testdata/negative-renew-before.yaml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
webhook:
|
||||
url: https://tuna.com/fish?marlin
|
||||
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u
|
||||
api:
|
||||
servingCertificate:
|
||||
durationSeconds: 2400
|
||||
renewBeforeSeconds: -10
|
8
pkg/config/testdata/zero-renew-before.yaml
vendored
Normal file
8
pkg/config/testdata/zero-renew-before.yaml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
webhook:
|
||||
url: https://tuna.com/fish?marlin
|
||||
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u
|
||||
api:
|
||||
servingCertificate:
|
||||
durationSeconds: 2400
|
||||
renewBeforeSeconds: -10
|
@ -154,7 +154,7 @@ func TestAPIServingCertificateAutoCreationAndRotation(t *testing.T) {
|
||||
|
||||
func createExpiredCertificate() ([]byte, error) {
|
||||
return testutil.CreateCertificate(
|
||||
time.Now().Add(-24*time.Hour),
|
||||
time.Now().Add(-time.Hour),
|
||||
time.Now().Add(-24*time.Hour), // notBefore
|
||||
time.Now().Add(-time.Hour), // notAfter
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user