1package auth_test23import (4 "encoding/base64"5 "strings"6 "testing"7 "time"89 legacy "github.com/FelineStateMachine/tinyrelay/internal/auth"10 "github.com/FelineStateMachine/tinyrelay/protocol/auth"11 "github.com/FelineStateMachine/tinyrelay/protocol/nostr"12)1314func TestCompatibilitySharesReplayStateAndErrors(t *testing.T) {15 if legacy.ErrMissingAuthorization != auth.ErrMissingAuthorization || legacy.ErrGRASP08Unauthorized != auth.ErrGRASP08Unauthorized {16 t.Fatal("compatibility facade changed error identity")17 }18 now := time.Unix(1700000000, 0)19 old := legacy.NewValidator(func() time.Time { return now })20 var public *auth.Validator = old21 e := nostr.Event{Kind: 27235, CreatedAt: now.Unix(), Tags: [][]string{{"u", "https://relay.example"}, {"method", "GET"}}}22 if err := nostr.Sign(&e, strings.Repeat("0", 63)+"1"); err != nil {23 t.Fatal(err)24 }25 raw, err := nostr.Canonical(e)26 if err != nil {27 t.Fatal(err)28 }29 header := "Nostr " + base64.StdEncoding.EncodeToString(raw)30 if _, err := old.VerifyNIP98(header, "https://relay.example", "GET", ""); err != nil {31 t.Fatal(err)32 }33 if _, err := public.VerifyNIP98(header, "https://relay.example", "GET", ""); err == nil || !strings.Contains(err.Error(), "replay") {34 t.Fatalf("facade lost replay state: %v", err)35 }36 var manager *auth.ChallengeManager = legacy.NewChallengeManager("wss://relay.example", nil)37 if _, err := manager.Issue(); err != nil {38 t.Fatal(err)39 }40}