...
1 package totp
2
3 import (
4 "fmt"
5 "testing"
6 "time"
7
8 "github.com/stretchr/testify/assert"
9 )
10
11 func TestGenerateTotp(t *testing.T) {
12 totpSecret := fmt.Sprintf("totp-secret-%d", time.Now().UnixNano())
13 totp, err := GenerateTotp(totpSecret)
14 assert.NoError(t, err)
15 assert.NotNil(t, totp)
16 assert.NotEmpty(t, totp.Code)
17 assert.NotEmpty(t, totp.CreatedAt)
18 assert.NotEmpty(t, totp.ExpiresAt)
19 assert.NotZero(t, totp.Duration)
20 }
21
22 func TestValidateTotp(t *testing.T) {
23 totpSecret := fmt.Sprintf("totp-secret-%d", time.Now().UnixNano())
24 totp, err := GenerateTotp(totpSecret)
25 assert.NoError(t, err)
26 assert.NotNil(t, totp)
27 assert.NoError(t, ValidateTotpToken(totp.Code, totpSecret))
28 }
29
View as plain text