28 lines
604 B
Go
28 lines
604 B
Go
package captcha
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMemoryNonceStoreSingleUse(t *testing.T) {
|
|
st := NewMemoryNonceStore()
|
|
if !st.MarkUsed("n1", time.Minute) {
|
|
t.Fatal("first use should return true")
|
|
}
|
|
if st.MarkUsed("n1", time.Minute) {
|
|
t.Fatal("second use should return false")
|
|
}
|
|
if !st.MarkUsed("n2", time.Minute) {
|
|
t.Fatal("distinct nonce should return true")
|
|
}
|
|
}
|
|
|
|
func TestMemoryNonceStoreExpiry(t *testing.T) {
|
|
st := NewMemoryNonceStore()
|
|
st.MarkUsed("n1", -time.Second) // already expired
|
|
if !st.MarkUsed("n1", time.Minute) {
|
|
t.Fatal("expired nonce should be reusable")
|
|
}
|
|
}
|