Move Go reference implementation to refimpl/go-lang/ and add new Python reference implementation in refimpl/python/. Update build.sh with renamed draft and simplified tool paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package ect
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestJTICache_SeenAndAdd(t *testing.T) {
|
|
cache := NewJTICache(10, 1*time.Second)
|
|
if cache.Seen("jti-1") {
|
|
t.Error("unseen jti should not be seen")
|
|
}
|
|
cache.Add("jti-1")
|
|
if !cache.Seen("jti-1") {
|
|
t.Error("added jti should be seen")
|
|
}
|
|
if cache.Seen("jti-2") {
|
|
t.Error("other jti should not be seen")
|
|
}
|
|
cache.Add("jti-2")
|
|
if !cache.Seen("jti-2") {
|
|
t.Error("second jti should be seen")
|
|
}
|
|
}
|
|
|
|
func TestJTICache_Expiry(t *testing.T) {
|
|
cache := NewJTICache(10, 50*time.Millisecond)
|
|
cache.Add("jti-1")
|
|
if !cache.Seen("jti-1") {
|
|
t.Fatal("added jti should be seen")
|
|
}
|
|
time.Sleep(60 * time.Millisecond)
|
|
if cache.Seen("jti-1") {
|
|
t.Error("expired jti should not be seen")
|
|
}
|
|
}
|
|
|
|
func TestJTICache_MaxSizeEviction(t *testing.T) {
|
|
cache := NewJTICache(2, 5*time.Second)
|
|
cache.Add("jti-1")
|
|
cache.Add("jti-2")
|
|
cache.Add("jti-3") // evicts one
|
|
// At least one of jti-1, jti-2 may be evicted; jti-3 must be present
|
|
if !cache.Seen("jti-3") {
|
|
t.Error("newest jti should be present")
|
|
}
|
|
}
|
|
|
|
func TestJTICache_AddWhenAlreadyPresent(t *testing.T) {
|
|
cache := NewJTICache(2, 5*time.Second)
|
|
cache.Add("jti-1")
|
|
cache.Add("jti-1") // refresh same jti; should not evict
|
|
if !cache.Seen("jti-1") {
|
|
t.Error("jti-1 should still be present")
|
|
}
|
|
}
|