Public getting stripped from unlisted activity CC: Add possible tests

This commit is contained in:
Lain Soykaf 2025-05-05 15:28:02 +04:00
commit ded40182b0
3 changed files with 133 additions and 0 deletions

65
test/fixtures/poast_unlisted.json vendored Normal file
View file

@ -0,0 +1,65 @@
{
"@context" : [
"https://www.w3.org/ns/activitystreams",
"https://poa.st/schemas/litepub-0.1.jsonld",
{
"@language" : "und"
}
],
"actor" : "https://poa.st/users/TrevorGoodchild",
"attachment" : [],
"attributedTo" : "https://poa.st/users/TrevorGoodchild",
"cc" : [
"https://www.w3.org/ns/activitystreams#Public"
],
"context" : "https://poa.st/contexts/c6d125f1-4e7f-43bd-aa31-33de4d90d049",
"conversation" : "https://poa.st/contexts/c6d125f1-4e7f-43bd-aa31-33de4d90d049",
"directMessage" : false,
"id" : "https://poa.st/activities/bbd3347a-4a89-4cdb-bf86-4f9eed9506e3",
"object" : {
"actor" : "https://poa.st/users/TrevorGoodchild",
"attachment" : [],
"attributedTo" : "https://poa.st/users/TrevorGoodchild",
"cc" : [
"https://www.w3.org/ns/activitystreams#Public"
],
"content" : "<span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"AfOKoodAGeklO08nyq\" href=\"https://poa.st/users/HoroTheWhiteWolf\" rel=\"ugc\">@<span>HoroTheWhiteWolf</span></a></span> </span>&gt;please let this be his zero fucks given final statement before he joins the 52%+ tranny club",
"context" : "https://poa.st/contexts/c6d125f1-4e7f-43bd-aa31-33de4d90d049",
"conversation" : "https://poa.st/contexts/c6d125f1-4e7f-43bd-aa31-33de4d90d049",
"id" : "https://poa.st/objects/7eb785d5-a556-4070-9091-f4afb226466c",
"inReplyTo" : "https://poa.st/objects/71995b41-cfb2-48ce-abce-76d570d54edc",
"published" : "2025-05-03T23:54:07.489885Z",
"repliesCount" : 2,
"sensitive" : false,
"source" : {
"content" : ">please let this be his zero fucks given final statement before he joins the 52%+ tranny club",
"mediaType" : "text/plain"
},
"summary" : "",
"tag" : [
{
"href" : "https://poa.st/users/HoroTheWhiteWolf",
"name" : "@HoroTheWhiteWolf",
"type" : "Mention"
}
],
"to" : [
"https://poa.st/users/HoroTheWhiteWolf",
"https://poa.st/users/TrevorGoodchild/followers"
],
"type" : "Note"
},
"published" : "2025-05-03T23:54:07.489837Z",
"tag" : [
{
"href" : "https://poa.st/users/HoroTheWhiteWolf",
"name" : "@HoroTheWhiteWolf",
"type" : "Mention"
}
],
"to" : [
"https://poa.st/users/HoroTheWhiteWolf",
"https://poa.st/users/TrevorGoodchild/followers"
],
"type" : "Create"
}

View file

@ -786,4 +786,35 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
assert object.data["context"] == object.data["inReplyTo"] assert object.data["context"] == object.data["inReplyTo"]
assert modified.data["context"] == object.data["inReplyTo"] assert modified.data["context"] == object.data["inReplyTo"]
end end
test "it keeps the public address in cc in the activity when it is present" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
object =
data["object"]
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
|> Map.put("to", [])
data =
data
|> Map.put("object", object)
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
|> Map.put("to", [])
{:ok, %Activity{} = modified} = Transmogrifier.handle_incoming(data)
assert modified.data["cc"] == ["https://www.w3.org/ns/activitystreams#Public"]
end
test "it tries it with the real poast_unlisted.json, ensuring that public is in the cc" do
data =
File.read!("test/fixtures/poast_unlisted.json")
|> Jason.decode!()
_user = insert(:user, ap_id: data["actor"])
{:ok, %Activity{} = modified} = Transmogrifier.handle_incoming(data)
assert modified.data["cc"] == ["https://www.w3.org/ns/activitystreams#Public"]
end
end end

View file

@ -757,6 +757,43 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
refute recipient.follower_address in fixed_object["cc"] refute recipient.follower_address in fixed_object["cc"]
refute recipient.follower_address in fixed_object["to"] refute recipient.follower_address in fixed_object["to"]
end end
test "preserves public URL in cc even when not explicitly mentioned", %{user: user} do
public_url = "https://www.w3.org/ns/activitystreams#Public"
# Case 1: Public URL in cc but no mentions
object = %{
"actor" => user.ap_id,
"to" => ["https://social.beepboop.ga/users/dirb"],
"cc" => [public_url],
"tag" => []
}
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert public_url in fixed_object["cc"]
# Case 2: Public URL in cc, with mentions but public not in to
object = %{
"actor" => user.ap_id,
"to" => ["https://pleroma.gold/users/user1"],
"cc" => [public_url],
"tag" => [%{"type" => "Mention", "href" => "https://pleroma.gold/users/user1"}]
}
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert public_url in fixed_object["cc"]
# Case 3: Public URL in to, it should be moved to to
object = %{
"actor" => user.ap_id,
"to" => [public_url],
"cc" => [],
"tag" => []
}
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert public_url in fixed_object["to"]
end
end end
describe "fix_summary/1" do describe "fix_summary/1" do