1package tinyclient23import (4 "net/http"5 "net/http/httptest"6 "strings"7 "testing"89 "github.com/FelineStateMachine/tinyrelay/internal/policy"10)1112func prefixedSocialRequest(path, query string) *http.Request {13 r := httptest.NewRequest(http.MethodGet, path+"?"+query, nil)14 r.RequestURI = "/r/team" + path + "?" + query15 return r16}1718func TestSocialLinksKeepTenantPrefix(t *testing.T) {19 a, err := New(&socialBackend{fakeBackend: fakeBackend{policy: policy.Defaults(strings.Repeat("a", 64))}}, Options{})20 if err != nil {21 t.Fatal(err)22 }23 w := httptest.NewRecorder()24 a.ServeHTTP(w, prefixedSocialRequest("/social", "kind=podcasts&author="+strings.Repeat("a", 64)))25 body := w.Body.String()26 for _, want := range []string{27 `href="/r/team/social"`,28 `href="/r/team/social?kind=photos"`,29 `href="/r/team/social/profile"`,30 `href="/r/team/social/profile?author=`,31 `href="/r/team/social/podcasts.rss?author=`,32 `href="/r/team/social?author=`,33 } {34 if !strings.Contains(body, want) {35 t.Errorf("missing tenant-prefixed link %q in %s", want, body)36 }37 }38 if strings.Contains(body, `href="/social`) {39 t.Fatalf("unscoped Social link in %s", body)40 }41}4243func TestSocialProfilePaginationKeepsTenantPrefix(t *testing.T) {44 owner, other := strings.Repeat("a", 64), strings.Repeat("b", 64)45 b := &socialProfileTestBackend{fakeBackend: fakeBackend{policy: policy.Defaults(owner)}}46 a, err := New(b, Options{Actor: func(*http.Request) (string, error) { return owner, nil }})47 if err != nil {48 t.Fatal(err)49 }50 w := httptest.NewRecorder()51 a.ServeHTTP(w, prefixedSocialRequest("/social/profile", "author="+other+"&kind=photos"))52 body := w.Body.String()53 if w.Code != http.StatusOK || !strings.Contains(body, `/r/team/social/profile?author=`+other+`&cursor=next&kind=photos`) {54 t.Fatalf("profile pagination lost tenant prefix: %d %s", w.Code, body)55 }56 if strings.Contains(body, `href="/social`) {57 t.Fatalf("unscoped profile link in %s", body)58 }59}