-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathykoath_test.go
52 lines (39 loc) · 1.24 KB
/
ykoath_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
// SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package ykoath_test
import (
"math/rand"
"testing"
"time"
iso "cunicu.li/go-iso7816"
yk "cunicu.li/go-iso7816/devices/yubikey"
"cunicu.li/go-iso7816/test"
"github.com/stretchr/testify/require"
"cunicu.li/go-ykoath/v2"
)
// withCard is a helper to initialize a card for testing
func withCard(t *testing.T, vs []vector, cb func(t *testing.T, card *ykoath.Card)) {
test.WithCard(t, yk.HasOATH, func(t *testing.T, isoCard *iso.Card) {
require := require.New(t)
oathCard, err := ykoath.NewCard(isoCard)
require.NoError(err)
_, err = oathCard.Select()
require.NoError(err, "Failed to select applet")
err = oathCard.Reset()
require.NoError(err, "Failed to reset applet")
for _, v := range vs {
v := v
err = oathCard.Put(v.Name, v.Alg, v.Typ, v.Digits, v.Secret, v.Touch, v.Counter)
require.NoError(err, "Failed to put credential")
}
// Fix the clock for our tests
oathCard.Clock = func() time.Time {
return time.Unix(59, 0)
}
// Fix the random source for reproducible tests
oathCard.Rand = rand.New(rand.NewSource(4242)) //nolint:gosec
cb(t, oathCard)
err = oathCard.Close()
require.NoError(err)
})
}