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")
}
}
|