Files
utilities/Yubikey/otp_test.go

45 lines
914 B
Go

package Yubikey
import (
"testing"
"time"
)
// Test the Valid method of Response.
func TestResponse_Valid(t *testing.T) {
resp := &Response{
status: "OK",
nonce: "abc123",
presentedNonce: "abc123",
}
if !resp.Valid() {
t.Errorf("Expected Valid() to return true")
}
resp.status = "BAD"
if resp.Valid() {
t.Errorf("Expected Valid() to return false when status is not OK")
}
resp.status = "OK"
resp.nonce = "xyz"
if resp.Valid() {
t.Errorf("Expected Valid() to return false when nonce does not match presentedNonce")
}
}
// Test the Time and TimeStamp methods.
func TestResponse_TimeAndTimeStamp(t *testing.T) {
now := time.Now()
resp := &Response{
t: now,
timestamp: 12345,
}
if !resp.Time().Equal(now) {
t.Errorf("Expected Time() to return the correct time")
}
if resp.TimeStamp() != 12345 {
t.Errorf("Expected TimeStamp() to return 12345")
}
}