[MAR-3131] Set grace to 0 on non-positive lease duration (#12372)

* [MAR-3131] Set grace to 0 on non-positive lease duration

* [MAR-3131] Add changelog

* [VAULT-3131] Add test for negative lease duration
This commit is contained in:
Pratyoy Mukhopadhyay 2021-08-24 19:06:40 -07:00 committed by GitHub
parent 306071f8b8
commit c379fd43a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -377,7 +377,7 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,
// assumptions given the total lease time; it also adds some jitter to not have // assumptions given the total lease time; it also adds some jitter to not have
// clients be in sync. // clients be in sync.
func (r *LifetimeWatcher) calculateGrace(leaseDuration time.Duration) { func (r *LifetimeWatcher) calculateGrace(leaseDuration time.Duration) {
if leaseDuration == 0 { if leaseDuration <= 0 {
r.grace = 0 r.grace = 0
return return
} }

View File

@ -149,6 +149,17 @@ func TestLifetimeWatcher(t *testing.T) {
nil, nil,
false, false,
}, },
{
15 * time.Second,
"negative_lease_duration",
-15,
15,
func(_ string, _ int) (*Secret, error) {
return renewedSecret, nil
},
nil,
true,
},
} }
for _, tc := range cases { for _, tc := range cases {

3
changelog/12372.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note: bug
core/api: Fix an arm64 bug converting a negative int to an unsigned int
```