Skip to content

Commit

Permalink
remove the key if expired, even when found
Browse files Browse the repository at this point in the history
  • Loading branch information
kpacha committed Sep 4, 2024
1 parent 48d11f5 commit 50c2fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions jwk_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func (u *memoryMissTracker) Exists(key string) bool {
var found bool

for i, uk := range u.keys {
if now.Sub(uk.time) > u.ttl {
cutPosition = i
}
if uk.name == key {
found = true
break
}
if now.Sub(uk.time) > u.ttl {
cutPosition = i
}
}

if cutPosition == -1 {
Expand Down
12 changes: 8 additions & 4 deletions jwk_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ func Test_memoryMissTracker(t *testing.T) {
t.Errorf("key1 should be present in list of misses %+v", uks)
}

if len(uks.keys) != 4 {
if len(uks.keys) != 3 {
t.Errorf("wrong size %+v", uks)
}

if !uks.Exists("key2") {
t.Errorf("key2 should be present in list of misses %+v", uks)
if !uks.Exists("key3") {
t.Errorf("key3 should be present in list of misses %+v", uks)
}

if len(uks.keys) != 3 {
if uks.Exists("key2") {
t.Errorf("key2 should not be present in list of misses %+v", uks)
}

if len(uks.keys) != 2 {
t.Errorf("wrong size %+v", uks)
}

Expand Down

0 comments on commit 50c2fd7

Please sign in to comment.