Set default minimum for pki certs (#12905) (#12921)

Co-authored-by: divyaac <divya.chandrasekaran@hashicorp.com>
This commit is contained in:
Vault Automation 2026-03-11 13:16:13 -04:00 committed by GitHub
parent 6674b4358a
commit 2ce86cb367
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -58,7 +58,12 @@ func durationAdjustedCertificateCount(validitySeconds int64) float64 {
validityHours := float64(validitySeconds) / 3600.0
units := validityHours / standardDuration
// Round to 4 decimal places
return math.Round(units*10000) / 10000
ret := math.Round(units*10000) / 10000
if ret == 0.0 && validitySeconds > 0 {
// Ensure we don't return 0.0, which would be interpreted as no billable units.
return 0.0001
}
return ret
}
type CertCountIncrementer interface {

View File

@ -17,7 +17,7 @@ func Test_durationAdjustedCertificateCount(t *testing.T) {
{
name: "zero duration",
validitySeconds: 0,
want: 0.0,
want: 0, // If the duration is zero, the normalized unit should be zero
},
{
name: "1 hour",
@ -72,12 +72,12 @@ func Test_durationAdjustedCertificateCount(t *testing.T) {
{
name: "very small duration - 1 second",
validitySeconds: 1,
want: 0.0, // 1/3600/730 = 0.00000038... rounds to 0.0
want: 0.0001, // 1/3600/730 = 0.00000038... rounds to 0.0 but should return default minimum 0.0001
},
{
name: "very small duration - 60 seconds",
validitySeconds: 60,
want: 0.0, // 60/3600/730 = 0.000023... rounds to 0.0
want: 0.0001, // 60/3600/730 = 0.000023... rounds to 0.0 and should return default minimum 0.0001
},
{
name: "very small duration - 600 seconds",