A remote account's searchableBy, and a post's own, outrank indexable in status search: Public lets anyone find a public post, the author's followers only those who follow it, anything else nobody but those it already reaches (their own, named, favourited, bookmarked or boosted posts). Read on actors and posts, kept through edits; PrivaPub does not emit it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
This commit is contained in:
1 parent
d4b1788a4f
commit
fb4949b511
11 files changed
+111
-5
No files matched your search
@@ -1,6 +1,12 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Federation.Objects;
|
||||
using PrivaPub.Models.Social;
|
||||
using PrivaPub.Tests.Support;
|
||||
using PrivaPub.Tests.Support.Host;
|
||||
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace PrivaPub.Tests.Http
|
||||
{
|
||||
// Status search by words, as Mastodon scopes it: the persona's own posts and those it boosted, favourited, bookmarked
|
||||
@@ -47,6 +53,67 @@ namespace PrivaPub.Tests.Http
|
||||
(await reader.Client.Get($"/api/v2/search?q={word}&type=statuses&limit=1&offset=1")).Ok().Body["statuses"]!.AsArray().Select(s => s.Text("id")));
|
||||
}
|
||||
|
||||
// FEP-268d: a remote account's searchableBy outranks its indexable, and a post's own outranks its author's
|
||||
[Fact]
|
||||
public async Task A_remote_searchable_by_decides_before_indexable()
|
||||
{
|
||||
var token = TestContext.Current.CancellationToken;
|
||||
await using var peer = await Peer.Start();
|
||||
var reader = await _host.Mastodon("reader");
|
||||
var keeper = await _host.Mastodon("keeper");
|
||||
var word = $"s{Guid.NewGuid():N}"[..12];
|
||||
|
||||
async Task<RemoteActor> Author(string name, bool indexable, Func<RemoteActor, JsonArray> searchableBy)
|
||||
{
|
||||
var author = new RemoteActor(peer, name);
|
||||
var document = author.Document();
|
||||
document["indexable"] = indexable;
|
||||
if (searchableBy != default)
|
||||
document["searchableBy"] = searchableBy(author);
|
||||
peer.Serve($"/users/{author.Name}", document.ToJsonString());
|
||||
await DB.Default.SaveAsync(new Following { AvatarId = keeper.Id, TargetActorURI = author.Id, State = FollowState.Accepted }, token);
|
||||
return author;
|
||||
}
|
||||
async Task<string> Says(RemoteActor author, string text, JsonArray searchableBy = default)
|
||||
{
|
||||
var noteId = $"{peer.A}/notes/{Guid.NewGuid():N}";
|
||||
var note = new JsonObject
|
||||
{
|
||||
["id"] = noteId, ["type"] = "Note", ["attributedTo"] = author.Id, ["content"] = $"<p>{text}</p>",
|
||||
["to"] = new JsonArray(Addressing.Public), ["cc"] = new JsonArray(author.Id + "/followers"), ["published"] = DateTime.UtcNow.ToString("O")
|
||||
};
|
||||
if (searchableBy != default)
|
||||
note["searchableBy"] = searchableBy;
|
||||
using var client = _host.Client();
|
||||
await client.SendAsync(author.SignedPost("/human-centipede", new JsonObject
|
||||
{
|
||||
["id"] = noteId + "/activity", ["type"] = "Create", ["actor"] = author.Id,
|
||||
["to"] = new JsonArray(Addressing.Public), ["cc"] = new JsonArray(author.Id + "/followers"), ["object"] = note
|
||||
}), token);
|
||||
Assert.Equal(1, await _host.RunInbox(noteId + "/activity", token));
|
||||
return (await DB.Default.Find<Models.Post.Post>().Match(p => p.ObjectURI == noteId).ExecuteFirstAsync(token)).ID;
|
||||
}
|
||||
|
||||
var open = await Says(await Author("open", indexable: false, _ => new JsonArray(Addressing.Public)), $"open {word}");
|
||||
var closed = await Says(await Author("closed", indexable: true, _ => new JsonArray()), $"closed {word}");
|
||||
var friendly = await Author("friendly", indexable: false, a => new JsonArray(a.Id + "/followers"));
|
||||
var friends = await Says(friendly, $"friends {word}");
|
||||
var quiet = await Author("quiet", indexable: false, default);
|
||||
var perPost = await Says(quiet, $"per post {word}", new JsonArray(Addressing.Public));
|
||||
var plain = await Says(quiet, $"plain {word}");
|
||||
|
||||
static List<string> Found(JsonNode body) => body["statuses"]!.AsArray().Select(s => s.Text("id")).ToList();
|
||||
var before = Found((await reader.Client.Get($"/api/v2/search?q={word}&type=statuses&limit=40")).Ok().Body);
|
||||
Assert.Contains(open, before);
|
||||
Assert.Contains(perPost, before);
|
||||
Assert.DoesNotContain(closed, before);
|
||||
Assert.DoesNotContain(friends, before);
|
||||
Assert.DoesNotContain(plain, before);
|
||||
|
||||
await DB.Default.SaveAsync(new Following { AvatarId = reader.Id, TargetActorURI = friendly.Id, State = FollowState.Accepted }, token);
|
||||
Assert.Contains(friends, Found((await reader.Client.Get($"/api/v2/search?q={word}&type=statuses&limit=40")).Ok().Body));
|
||||
}
|
||||
|
||||
// a handle asks for its account: no posts sharing its words, and no hashtag made of it
|
||||
[Fact]
|
||||
public async Task A_handle_finds_its_account_and_neither_posts_nor_a_hashtag()
|
||||
|
||||
Reference in new issue
Block a user