-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
76 lines (66 loc) · 1.58 KB
/
utils_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
66
67
68
69
70
71
72
73
74
75
76
package gotp
// spell-checker:disable
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
testValidURI = "otpauth://totp/SomeOrg:diebietse?secret=4S62BZNFXXSZLCRO&issuer=SomeOrg"
testValidURILong = "otpauth://hotp/SomeOrg:diebietse?secret=4S62BZNFXXSZLCRO&counter=0&issuer=SomeOrg&algorithm=SHA256&digits=8&period=15"
)
func TestBuildUri(t *testing.T) {
uri, err := buildURI(
"totp",
"4S62BZNFXXSZLCRO",
"diebietse",
"SomeOrg",
"sha1",
0,
6,
0,
)
assert.NoError(t, err, "URI building failed")
assert.Equal(t, testValidURI, uri, "Generated URI did not match")
}
func TestBuildUri_nonDefaults(t *testing.T) {
uri, err := buildURI(
"hotp",
"4S62BZNFXXSZLCRO",
"diebietse",
"SomeOrg",
"sha256",
0,
8,
15,
)
assert.NoError(t, err, "URI building failed")
assert.Equal(t, testValidURILong, uri, "Generated URI did not match")
}
func TestBuildUri_fail(t *testing.T) {
_, err := buildURI(
"potp",
"4S62BZNFXXSZLCRO",
"diebietse",
"SomeOrg",
"sha1",
0,
6,
0,
)
assert.Error(t, err, "invalid OTP standard did not cause an error")
}
func TestITob(t *testing.T) {
i := 1524486261
expect := []byte{0, 0, 0, 0, 90, 221, 208, 117}
assert.Equal(t, string(expect), string(itob(i)), "Integer to byte array conversion failed")
}
func TestRandomSecretLength(t *testing.T) {
length := 12
secret, err := RandomSecret(length)
assert.NoError(t, err)
assert.Equal(t, length, len(secret), "Secret length did not match expected length")
}
func TestDecodeSecretBase32_Invalid(t *testing.T) {
_, err := DecodeBase32("1")
assert.Error(t, err)
}