X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fmrf%2Fsimple_policy_test.exs;h=036573171e719af7cdbaa50931592281e99c382e;hb=d5828f1c5e54ca236e50ef7837bfba3d1e665854;hp=0a0f51bdbb8c91bf27dc903f216579414e900887;hpb=6e3df116935a549a92b74bfc2be9a4197ad7a995;p=akkoma diff --git a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs index 0a0f51bdb..036573171 100644 --- a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs @@ -26,15 +26,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do test "is empty" do clear_config([:mrf_simple, :media_removal], []) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == {:ok, media_message} + assert SimplePolicy.filter(media_update_message) == {:ok, media_update_message} assert SimplePolicy.filter(local_message) == {:ok, local_message} end test "has a matching host" do clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Some reason"}]) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == @@ -42,12 +45,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do media_message |> Map.put("object", Map.delete(media_message["object"], "attachment"))} + assert SimplePolicy.filter(media_update_message) == + {:ok, + media_update_message + |> Map.put("object", Map.delete(media_update_message["object"], "attachment"))} + assert SimplePolicy.filter(local_message) == {:ok, local_message} end test "match with wildcard domain" do clear_config([:mrf_simple, :media_removal], [{"*.remote.instance", "Whatever reason"}]) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == @@ -55,6 +64,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do media_message |> Map.put("object", Map.delete(media_message["object"], "attachment"))} + assert SimplePolicy.filter(media_update_message) == + {:ok, + media_update_message + |> Map.put("object", Map.delete(media_update_message["object"], "attachment"))} + assert SimplePolicy.filter(local_message) == {:ok, local_message} end end @@ -63,31 +77,41 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do test "is empty" do clear_config([:mrf_simple, :media_nsfw], []) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == {:ok, media_message} + assert SimplePolicy.filter(media_update_message) == {:ok, media_update_message} assert SimplePolicy.filter(local_message) == {:ok, local_message} end test "has a matching host" do clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "Whetever"}]) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == {:ok, put_in(media_message, ["object", "sensitive"], true)} + assert SimplePolicy.filter(media_update_message) == + {:ok, put_in(media_update_message, ["object", "sensitive"], true)} + assert SimplePolicy.filter(local_message) == {:ok, local_message} end test "match with wildcard domain" do clear_config([:mrf_simple, :media_nsfw], [{"*.remote.instance", "yeah yeah"}]) media_message = build_media_message() + media_update_message = build_media_update_message() local_message = build_local_message() assert SimplePolicy.filter(media_message) == {:ok, put_in(media_message, ["object", "sensitive"], true)} + assert SimplePolicy.filter(media_update_message) == + {:ok, put_in(media_update_message, ["object", "sensitive"], true)} + assert SimplePolicy.filter(local_message) == {:ok, local_message} end end @@ -104,6 +128,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do } end + defp build_media_update_message do + %{ + "actor" => "https://remote.instance/users/bob", + "type" => "Update", + "object" => %{ + "attachment" => [%{}], + "tag" => ["foo"], + "sensitive" => false + } + } + end + describe "when :report_removal" do test "is empty" do clear_config([:mrf_simple, :report_removal], []) @@ -216,6 +252,43 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do end end + describe "describe/1" do + test "returns a description of the policy" do + clear_config([:mrf_simple, :reject], [ + {"remote.instance", "did not give my catboy a burg"} + ]) + + assert {:ok, %{mrf_simple: %{reject: ["remote.instance"]}}} = SimplePolicy.describe() + end + + test "excludes domains listed in :transparency_exclusions" do + clear_config([:mrf, :transparency_exclusions], [{"remote.instance", ":("}]) + + clear_config([:mrf_simple, :reject], [ + {"remote.instance", "did not give my catboy a burg"} + ]) + + {:ok, description} = SimplePolicy.describe() + assert %{mrf_simple: %{reject: []}} = description + assert description[:mrf_simple_info][:reject] == nil + end + + test "obfuscates domains listed in :transparency_obfuscate_domains" do + clear_config([:mrf, :transparency_obfuscate_domains], ["remote.instance", "a.b"]) + + clear_config([:mrf_simple, :reject], [ + {"remote.instance", "did not give my catboy a burg"}, + {"a.b", "spam-poked me on facebook in 2006"} + ]) + + assert {:ok, + %{ + mrf_simple: %{reject: ["rem***.*****nce", "a.b"]}, + mrf_simple_info: %{reject: %{"rem***.*****nce" => %{}}} + }} = SimplePolicy.describe() + end + end + defp build_ftl_actor_and_message do actor = insert(:user)