diff --git a/sdk/logical/certificate_counter.go b/sdk/logical/certificate_counter.go index a93afbf06a..811f6fe73e 100644 --- a/sdk/logical/certificate_counter.go +++ b/sdk/logical/certificate_counter.go @@ -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 { diff --git a/sdk/logical/certificate_counter_test.go b/sdk/logical/certificate_counter_test.go index 4d449878bf..889cee2e26 100644 --- a/sdk/logical/certificate_counter_test.go +++ b/sdk/logical/certificate_counter_test.go @@ -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",