simpleadmin-web/internal/steam/steam_test.go

35 lines
787 B
Go

package steam
import (
"testing"
"time"
)
func TestValidID(t *testing.T) {
for id, want := range map[string]bool{
"76561198012345601": true,
"76561197960265728": false, // account 0
"7656119801234560": false,
"76561198012345601 ": false,
"86561198012345601": false,
"7656119801234560a": false,
} {
if got := ValidID(id); got != want {
t.Errorf("ValidID(%q) = %v", id, got)
}
}
}
func TestNonce(t *testing.T) {
fresh := time.Now().UTC().Format(time.RFC3339) + "abc"
if err := checkNonce(fresh); err != nil {
t.Fatal(err)
}
old := time.Now().Add(-10*time.Minute).UTC().Format(time.RFC3339) + "abc"
if checkNonce(old) == nil {
t.Fatal("old nonce accepted")
}
if !seen.claim(fresh) || seen.claim(fresh) {
t.Fatal("nonce replay not caught")
}
}