clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/tinyagent
tinyrelay / internal / daemon / management_test.go
management_test.go 1.8K
1package daemon23import (4 "encoding/json"5 "testing"6)78func TestAddressFilterForPath(t *testing.T) {9 id := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"10 tests := []struct {11 name string12 path string13 want bool14 }{15 {"event", "/e/" + id, true},16 {"article", "/a/article-name", true},17 {"view", "/view/profiles", true},18 {"bad event", "/e/not-an-id", false},19 {"traversal", "/view/%2fetc", false},20 }21 for _, test := range tests {22 t.Run(test.name, func(t *testing.T) {23 filter, ok := AddressFilterForPath(test.path, id, id)24 if ok != test.want {25 t.Fatalf("ok = %v, want %v (filter=%v)", ok, test.want, filter)26 }27 })28 }29}3031func TestAddressFilterForPathShape(t *testing.T) {32 id := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"33 filter, ok := AddressFilterForPath("/a/my%20article", id, id)34 if !ok || filter["#d"].([]string)[0] != "my article" {35 t.Fatalf("unexpected address filter: %#v", filter)36 }37 filter, ok = AddressFilterForPath("/view/profiles", id, id)38 if !ok || filter["#d"].([]string)[0] != "bind.ws/view/profiles" {39 t.Fatalf("unexpected view filter: %#v", filter)40 }41}4243func TestPublicFilterDefaultsAndLimit(t *testing.T) {44 f, err := publicFilter(nil)45 if err != nil || f.Limit == nil || *f.Limit != 50 {46 t.Fatalf("default filter: %#v %v", f, err)47 }48 raw, _ := json.Marshal(map[string]any{"kinds": []int{1}, "limit": 1000})49 f, err = publicFilter([]json.RawMessage{raw})50 if err != nil || f.Limit == nil || *f.Limit != 1000 {51 t.Fatalf("bounded filter: %#v %v", f, err)52 }53}5455func TestManagementMethodsExcludeHostedControls(t *testing.T) {56 for _, method := range ManagementMethods() {57 for _, excluded := range []string{"lease", "trial", "fuel", "productcapacity"} {58 if method == excluded {59 t.Fatalf("hosted control %q leaked into self-hosted registry", method)60 }61 }62 }63}