feature: verify tokens
This commit is contained in:
43
pkg/user/token_test.go
Normal file
43
pkg/user/token_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FuzzNewVerifyEmailToken(f *testing.F) {
|
||||
f.Add(int64(123))
|
||||
f.Fuzz(func(t *testing.T, userID int64) {
|
||||
_, err := newTokenToVerifyEmail(userID, time.Millisecond*100)
|
||||
if err != nil {
|
||||
t.Errorf("failed for input %d, %v", userID, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestEmailToken(t *testing.T) {
|
||||
uID := int64(1234)
|
||||
// create a token
|
||||
t1, err := newTokenToVerifyEmail(uID, time.Millisecond*100)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// let decode token
|
||||
id, err := tokenToVerifyEmail(t1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if uID != id {
|
||||
t.Error("uid and decoded id are not same, ", uID, "!=", id)
|
||||
}
|
||||
|
||||
// lets wait and try decode again
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
_, err = tokenToVerifyEmail(t1)
|
||||
if !errors.Is(err, ErrExpiredToken) {
|
||||
t.Error("expected expired token error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user