tinyrelayfile
tinyrelay/internal/auth/compatibility_test.go/

internal/auth/compatibility_test.go raw
1package auth_test
2
3import (
4 "encoding/base64"
5 "strings"
6 "testing"
7 "time"
8
9 legacy "github.com/FelineStateMachine/tinyrelay/internal/auth"
10 "github.com/FelineStateMachine/tinyrelay/protocol/auth"
11 "github.com/FelineStateMachine/tinyrelay/protocol/nostr"
12)
13
14func 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 = old
21 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}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs