-
Notifications
You must be signed in to change notification settings - Fork 37
/
hotp_test.go
65 lines (57 loc) · 1.26 KB
/
hotp_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package otp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHOTP(t *testing.T) {
secret := `12345678901234567890`
table := map[uint64]string{
0: `755224`,
1: `287082`,
2: `359152`,
3: `969429`,
4: `338314`,
5: `254676`,
6: `287922`,
7: `162583`,
8: `399871`,
9: `520489`,
}
for cnt, expected := range table {
hotp := &HOTP{Secret: secret, Counter: cnt, Length: 6}
result := hotp.Get()
assert.Equal(t, expected, result)
}
}
func TestHOTPBase32(t *testing.T) {
secret := `JBSWY3DPEHPK3PXP`
table := map[uint64]string{
0: `282760`,
1: `996554`,
2: `602287`,
3: `143627`,
4: `960129`,
5: `768897`,
6: `883951`,
7: `449891`,
8: `964230`,
9: `924769`,
}
for cnt, expected := range table {
hotp := &HOTP{Secret: secret, Counter: cnt, Length: 6, IsBase32Secret: true}
result := hotp.Get()
assert.Equal(t, expected, result)
}
}
func TestHOTPShouldBeCroppedToMaxLength(t *testing.T) {
hotp := &HOTP{Length: 20}
result := hotp.Get()
assert.Equal(t, MaxLength, len(result))
}
func TestHOTPShouldUseDefaultValues(t *testing.T) {
hotp := &HOTP{}
result := hotp.Get()
assert.Equal(t, uint8(DefaultLength), hotp.Length)
assert.NotEmpty(t, hotp.Secret)
assert.Equal(t, hotp.Length, uint8(len(result)))
}