|
|
|
@ -91,6 +91,49 @@ func Test_keyStore(t *testing.T) {
|
|
|
|
|
assert.True(t, hits.Hits > 1, fmt.Sprintf("invalid number of hits: %d is not greater than 1", hits.Hits))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_keyStore_noCache(t *testing.T) {
|
|
|
|
|
srv := generateJWKServer(2)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
ks, err := newKeyStore(srv.URL + "/no-cache")
|
|
|
|
|
assert.FatalError(t, err)
|
|
|
|
|
defer ks.Close()
|
|
|
|
|
ks.RLock()
|
|
|
|
|
keySet1 := ks.keySet
|
|
|
|
|
ks.RUnlock()
|
|
|
|
|
// The keys will rotate on Get.
|
|
|
|
|
// So we won't be able to find the cached ones
|
|
|
|
|
assert.Len(t, 2, keySet1.Keys)
|
|
|
|
|
assert.Len(t, 0, ks.Get(keySet1.Keys[0].KeyID))
|
|
|
|
|
assert.Len(t, 0, ks.Get(keySet1.Keys[1].KeyID))
|
|
|
|
|
assert.Len(t, 0, ks.Get("foobar"))
|
|
|
|
|
|
|
|
|
|
ks.RLock()
|
|
|
|
|
keySet2 := ks.keySet
|
|
|
|
|
ks.RUnlock()
|
|
|
|
|
if reflect.DeepEqual(keySet1, keySet2) {
|
|
|
|
|
t.Error("keyStore did not rotated")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The keys will rotate on Get.
|
|
|
|
|
// So we won't be able to find the cached ones
|
|
|
|
|
assert.Len(t, 2, keySet2.Keys)
|
|
|
|
|
assert.Len(t, 0, ks.Get(keySet2.Keys[0].KeyID))
|
|
|
|
|
assert.Len(t, 0, ks.Get(keySet2.Keys[1].KeyID))
|
|
|
|
|
assert.Len(t, 0, ks.Get("foobar"))
|
|
|
|
|
|
|
|
|
|
// Check hits
|
|
|
|
|
resp, err := srv.Client().Get(srv.URL + "/hits")
|
|
|
|
|
assert.FatalError(t, err)
|
|
|
|
|
hits := struct {
|
|
|
|
|
Hits int `json:"hits"`
|
|
|
|
|
}{}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&hits)
|
|
|
|
|
assert.FatalError(t, err)
|
|
|
|
|
assert.True(t, hits.Hits > 1, fmt.Sprintf("invalid number of hits: %d is not greater than 1", hits.Hits))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_keyStore_Get(t *testing.T) {
|
|
|
|
|
srv := generateJWKServer(2)
|
|
|
|
|
defer srv.Close()
|
|
|
|
@ -119,3 +162,31 @@ func Test_keyStore_Get(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_abs(t *testing.T) {
|
|
|
|
|
maxInt64 := time.Duration(1<<63 - 1)
|
|
|
|
|
minInt64 := time.Duration(-1 << 63)
|
|
|
|
|
type args struct {
|
|
|
|
|
n time.Duration
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
args args
|
|
|
|
|
want time.Duration
|
|
|
|
|
}{
|
|
|
|
|
{"ok", args{0}, 0},
|
|
|
|
|
{"ok", args{-time.Hour}, time.Hour},
|
|
|
|
|
{"ok", args{time.Hour}, time.Hour},
|
|
|
|
|
{"ok maxInt64", args{maxInt64}, maxInt64},
|
|
|
|
|
{"ok minInt64 + 1", args{minInt64 + 1}, maxInt64},
|
|
|
|
|
{"overflow on minInt64", args{minInt64}, minInt64},
|
|
|
|
|
{"overflow on minInt64", args{minInt64}, -minInt64},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
if got := abs(tt.args.n); got != tt.want {
|
|
|
|
|
t.Errorf("abs() = %v, want %v", got, tt.want)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|