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

View file

@ -786,4 +786,35 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
assert object.data["context"] == object.data["inReplyTo"]
assert modified.data["context"] == object.data["inReplyTo"]
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

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["to"]
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
describe "fix_summary/1" do