File: totp_test.go

package info (click to toggle)
golang-github-xlzd-gotp 0.0~git20181030.c8557ba-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 108 kB
  • sloc: makefile: 5
file content (38 lines) | stat: -rw-r--r-- 817 bytes parent folder | download
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
package gotp

import (
	"testing"
)

var totp = NewDefaultTOTP("4S62BZNFXXSZLCRO")

func TestTOTP_At(t *testing.T) {
	if totp.Now() != totp.At(currentTimestamp()) {
		t.Error("TOTP generate otp error!")
	}
}

func TestTOTP_NowWithExpiration(t *testing.T) {
	otp, exp := totp.NowWithExpiration()
	cts := currentTimestamp()
	if otp != totp.Now() {
		t.Error("TOTP generate otp error!")
	}
	if totp.At(cts+30) != totp.At(int(exp)) {
		t.Error("TOTP expiration otp error!")
	}
}

func TestTOTP_Verify(t *testing.T) {
	if !totp.Verify("179394", 1524485781) {
		t.Error("verify faild")
	}
}

func TestTOTP_ProvisioningUri(t *testing.T) {
	expect := "otpauth://totp/github:xlzd?secret=4S62BZNFXXSZLCRO&issuer=github"
	uri := totp.ProvisioningUri("xlzd", "github")
	if expect != uri {
		t.Error("ProvisioningUri error")
	}
}