forked from openp2p-cn/totp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
totp_test.go
37 lines (34 loc) · 807 Bytes
/
totp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Time-based One-time Password
package totp
import (
"testing"
"time"
)
func TestTOTP(t *testing.T) {
tt := TOTP{Step: RelayTOTPStep}
for i := 0; i < 20; i++ {
ts := time.Now().Unix()
code := tt.Gen(13666999958022769123, ts)
t.Log(code)
if !tt.Verify(code, 13666999958022769123, ts) {
t.Error("TOTP error")
}
if !tt.Verify(code, 13666999958022769123, ts-10) {
t.Error("TOTP error")
}
if !tt.Verify(code, 13666999958022769123, ts+10) {
t.Error("TOTP error")
}
if tt.Verify(code, 13666999958022769123, ts+60) {
t.Error("TOTP error")
}
if tt.Verify(code, 13666999958022769124, ts+1) {
t.Error("TOTP error")
}
if tt.Verify(code, 13666999958022769125, ts+1) {
t.Error("TOTP error")
}
time.Sleep(time.Second)
t.Log("round", i, " ", ts, " test ok")
}
}