pkg/config: force api.servingCertificate.renewBeforeSeconds to be positive

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Ryan Richard 2020-08-20 18:14:07 -04:00 committed by Andrew Keesler
parent 88f3b41e71
commit d0a9d8df33
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
5 changed files with 32 additions and 2 deletions

View File

@ -64,6 +64,10 @@ func validateAPI(apiConfig *api.APIConfigSpec) error {
return constable.Error("durationSeconds cannot be smaller than renewBeforeSeconds") return constable.Error("durationSeconds cannot be smaller than renewBeforeSeconds")
} }
if *apiConfig.ServingCertificateConfig.RenewBeforeSeconds <= 0 {
return constable.Error("renewBefore must be positive")
}
return nil return nil
} }

View File

@ -63,6 +63,16 @@ func TestFromPath(t *testing.T) {
path: "testdata/invalid-duration-renew-before.yaml", path: "testdata/invalid-duration-renew-before.yaml",
wantError: "validate api: durationSeconds cannot be smaller than renewBeforeSeconds", 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 { for _, test := range tests {
test := test test := test

View File

@ -0,0 +1,8 @@
---
webhook:
url: https://tuna.com/fish?marlin
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u
api:
servingCertificate:
durationSeconds: 2400
renewBeforeSeconds: -10

View File

@ -0,0 +1,8 @@
---
webhook:
url: https://tuna.com/fish?marlin
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u
api:
servingCertificate:
durationSeconds: 2400
renewBeforeSeconds: -10

View File

@ -154,7 +154,7 @@ func TestAPIServingCertificateAutoCreationAndRotation(t *testing.T) {
func createExpiredCertificate() ([]byte, error) { func createExpiredCertificate() ([]byte, error) {
return testutil.CreateCertificate( return testutil.CreateCertificate(
time.Now().Add(-24*time.Hour), time.Now().Add(-24*time.Hour), // notBefore
time.Now().Add(-time.Hour), time.Now().Add(-time.Hour), // notAfter
) )
} }