You've already forked utilities
feat: add initial implementation of Go utilities and CI workflows
This commit is contained in:
44
Yubikey/otp_test.go
Normal file
44
Yubikey/otp_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user