From 1121f099e98c62bd6ee7a5a7e4124ae36a45fba1 Mon Sep 17 00:00:00 2001 From: tusooa Date: Thu, 15 Dec 2022 20:20:11 -0500 Subject: [PATCH] Ensure actor in Activity is also anonymized --- lib/pleroma/web/activity_pub/utils.ex | 3 ++- .../pleroma/web/activity_pub/activity_pub_test.exs | 4 +++- test/pleroma/web/activity_pub/utils_test.exs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index f230730ab..0b989d02d 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -887,7 +887,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do end def maybe_anonymize_reporter(%Activity{data: data} = activity) do - %Activity{activity | data: maybe_anonymize_reporter(data)} + new_data = maybe_anonymize_reporter(data) + %Activity{activity | actor: new_data["actor"], data: new_data} end def maybe_anonymize_reporter(activity) do diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index a4030ff03..0eb262fc6 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1738,7 +1738,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do |> put_in(["object"], [target_account.ap_id, object_ap_id]) |> Map.put("actor", placeholder.ap_id) - assert_called(Utils.maybe_federate(%{activity | data: new_data})) + assert_called( + Utils.maybe_federate(%{activity | actor: placeholder.ap_id, data: new_data}) + ) end end diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index fc289d712..a48639c38 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -693,6 +693,20 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do assert %{"actor" => placeholder.ap_id} == Utils.maybe_anonymize_reporter(report) end + test "anonymize Activity", %{ + placeholder: placeholder, + reporter: reporter, + report: report + } do + clear_config([:activitypub, :anonymize_reporter], true) + clear_config([:activitypub, :anonymize_reporter_local_nickname], placeholder.nickname) + report_activity = %Activity{actor: reporter, data: report} + anon_id = placeholder.ap_id + + assert %Activity{actor: ^anon_id, data: %{"actor" => ^anon_id}} = + Utils.maybe_anonymize_reporter(report_activity) + end + test "do not anonymize when disabled", %{ placeholder: placeholder, reporter: reporter,