package webauthn import ( "testing" libwebauthn "github.com/go-webauthn/webauthn/webauthn" "git.wntrmute.dev/kyle/mcias/internal/config" ) func TestNewWebAuthn(t *testing.T) { cfg := &config.WebAuthnConfig{ RPID: "example.com", RPOrigin: "https://example.com", DisplayName: "Test App", } wa, err := NewWebAuthn(cfg) if err != nil { t.Fatalf("NewWebAuthn: %v", err) } if wa == nil { t.Fatal("expected non-nil WebAuthn instance") } } func TestNewWebAuthnMissingFields(t *testing.T) { _, err := NewWebAuthn(&config.WebAuthnConfig{}) if err == nil { t.Error("expected error for empty config") } _, err = NewWebAuthn(&config.WebAuthnConfig{RPID: "example.com"}) if err == nil { t.Error("expected error for missing RPOrigin") } } func TestNewWebAuthnDefaultDisplayName(t *testing.T) { cfg := &config.WebAuthnConfig{ RPID: "example.com", RPOrigin: "https://example.com", } wa, err := NewWebAuthn(cfg) if err != nil { t.Fatalf("NewWebAuthn: %v", err) } if wa == nil { t.Fatal("expected non-nil WebAuthn instance") } } func TestAccountUserInterface(t *testing.T) { uuidBytes := []byte("12345678-1234-1234-1234-123456789abc") creds := []libwebauthn.Credential{ {ID: []byte("cred1")}, {ID: []byte("cred2")}, } user := NewAccountUser(uuidBytes, "alice", creds) // Verify interface compliance. var _ libwebauthn.User = user if string(user.WebAuthnID()) != string(uuidBytes) { t.Error("WebAuthnID mismatch") } if user.WebAuthnName() != "alice" { t.Errorf("WebAuthnName = %q, want %q", user.WebAuthnName(), "alice") } if user.WebAuthnDisplayName() != "alice" { t.Errorf("WebAuthnDisplayName = %q, want %q", user.WebAuthnDisplayName(), "alice") } if len(user.WebAuthnCredentials()) != 2 { t.Errorf("WebAuthnCredentials len = %d, want 2", len(user.WebAuthnCredentials())) } }