| 1 | package daemon |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestVisibleConnectionsFollowViewerRole(t *testing.T) { |
| 11 | ctx := context.Background() |
| 12 | _, tenant := testTenant(t) |
| 13 | rows := `[{"template":"notes","visibility":"public"},{"template":"bookmarks","visibility":"members"},{"template":"relay-page","visibility":"owner"},{"template":"nope","visibility":"public"}]` |
| 14 | if _, err := tenant.Execute(ctx, tenant.Policy().Owner, "setconnections" , []json.RawMessage{json.RawMessage(rows)}); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | names := func(actor string) string { |
| 18 | value, err := tenant.Execute(ctx, actor, "connections" , nil) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | raw, _ := json.Marshal(value) |
| 23 | var list []map[string]any |
| 24 | _ = json.Unmarshal(raw, &list) |
| 25 | out := []string{} |
| 26 | for _, item := range list { |
| 27 | out = append(out, item["template" ].(string)) |
| 28 | } |
| 29 | return strings.Join(out, "," ) |
| 30 | } |
| 31 | if got := names("" ); got != "notes" { |
| 32 | t.Fatalf("guest sees %q" , got) |
| 33 | } |
| 34 | if got := names(tenant.Policy().Owner); got != "notes,bookmarks,relay-page" { |
| 35 | t.Fatalf("owner sees %q" , got) |
| 36 | } |
| 37 | value, _ := tenant.Execute(ctx, "" , "connections" , nil) |
| 38 | raw, _ := json.Marshal(value) |
| 39 | if !strings.Contains(string(raw), "jumble.social" ) || !strings.Contains(string(raw), `"links"` ) { |
| 40 | t.Fatalf("connection is missing its template links: %s" , raw) |
| 41 | } |
| 42 | } |