From d3adc3e05e09fdcb663ec1a3e20c1bc2d04a6ab5 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 12 Jun 2025 21:59:26 -0700 Subject: [PATCH] Split this cc test into two individual cases --- .../web/activity_pub/publisher_test.exs | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index ec3201b96..7bc571595 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -521,9 +521,11 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do assert decoded["cc"] == [] end - test "retains public address in cc for unlisted activities" do + test "unlisted activities retain public address in cc" do user = insert(:user) + # simulate unlistd activity by only having + # public address in cc activity = insert(:note_activity, user: user, @@ -535,58 +537,66 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do assert @as_public in activity.data["cc"] - # Call prepare_one without an explicit cc parameter (default in production) prepared = Publisher.prepare_one(%{ inbox: "https://remote.instance/users/someone/inbox", activity_id: activity.id }) - # Parse the JSON to verify the cc field in the federated message {:ok, decoded} = Jason.decode(prepared.json) - # The public address should be preserved in the cc field - # Currently this will fail because it's being removed assert @as_public in decoded["cc"] - - # For verification, also test with an explicit cc parameter - # to show the cc field is completely replaced - prepared_with_cc = - Publisher.prepare_one(%{ - inbox: "https://remote.instance/users/someone/inbox", - activity_id: activity.id, - cc: ["https://example.com/specific/user"] - }) - - {:ok, decoded_with_cc} = Jason.decode(prepared_with_cc.json) - - # Verify cc is completely replaced with the provided value - assert decoded_with_cc["cc"] == ["https://example.com/specific/user"] end test "public address in cc parameter is preserved" do user = insert(:user) + cc_with_public = [@as_public, "https://example.org/users/other"] + activity = insert(:note_activity, user: user, data_attrs: %{ - "cc" => [@as_public, "https://example.org/users/other"], + "cc" => cc_with_public, "to" => [user.follower_address] } ) assert @as_public in activity.data["cc"] - prepared_with_public_cc = + prepared = Publisher.prepare_one(%{ inbox: "https://remote.instance/users/someone/inbox", activity_id: activity.id, - cc: [@as_public] + cc: cc_with_public }) - {:ok, decoded_with_public_cc} = Jason.decode(prepared_with_public_cc.json) + {:ok, decoded} = Jason.decode(prepared.json) - assert @as_public in decoded_with_public_cc["cc"] + assert cc_with_public == decoded["cc"] + end + + test "cc parameter is preserved" do + user = insert(:user) + + activity = + insert(:note_activity, + user: user, + data_attrs: %{ + "cc" => ["https://example.com/specific/user"], + "to" => [user.follower_address] + } + ) + + prepared = + Publisher.prepare_one(%{ + inbox: "https://remote.instance/users/someone/inbox", + activity_id: activity.id, + cc: ["https://example.com/specific/user"] + }) + + {:ok, decoded} = Jason.decode(prepared.json) + + assert decoded["cc"] == ["https://example.com/specific/user"] end end