diff options
author | Tusooa Zhu <tusooa@kazv.moe> | 2022-07-24 00:02:39 -0400 |
---|---|---|
committer | Tusooa Zhu <tusooa@kazv.moe> | 2022-07-24 00:02:39 -0400 |
commit | d877d2a4e7449e942b4d192f283824eebcade563 (patch) | |
tree | b7c2e3b05ee2667c90119b9716e6b3958ac27fdf /test | |
parent | 82c8fc1ede26837d024ecc2fd1231c6d2a3c2c3e (diff) | |
download | pleroma-d877d2a4e7449e942b4d192f283824eebcade563.tar.gz pleroma-d877d2a4e7449e942b4d192f283824eebcade563.zip |
Make HashtagPolicy history-aware
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs b/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs index 7f2d78a4c..32991c966 100644 --- a/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs @@ -20,6 +20,76 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicyTest do assert modified["object"]["sensitive"] end + test "it is history-aware" do + activity = %{ + "type" => "Create", + "object" => %{ + "content" => "hey", + "tag" => [] + } + } + + activity_data = + activity + |> put_in( + ["object", "formerRepresentations"], + %{ + "type" => "OrderedCollection", + "orderedItems" => [ + Map.put( + activity["object"], + "tag", + [%{"type" => "Hashtag", "name" => "#nsfw"}] + ) + ] + } + ) + + {:ok, modified} = + Pleroma.Web.ActivityPub.MRF.filter_one( + Pleroma.Web.ActivityPub.MRF.HashtagPolicy, + activity_data + ) + + refute modified["object"]["sensitive"] + assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"] + end + + test "it works with Update" do + activity = %{ + "type" => "Update", + "object" => %{ + "content" => "hey", + "tag" => [] + } + } + + activity_data = + activity + |> put_in( + ["object", "formerRepresentations"], + %{ + "type" => "OrderedCollection", + "orderedItems" => [ + Map.put( + activity["object"], + "tag", + [%{"type" => "Hashtag", "name" => "#nsfw"}] + ) + ] + } + ) + + {:ok, modified} = + Pleroma.Web.ActivityPub.MRF.filter_one( + Pleroma.Web.ActivityPub.MRF.HashtagPolicy, + activity_data + ) + + refute modified["object"]["sensitive"] + assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"] + end + test "it doesn't sets the sensitive property with irrelevant hashtags" do user = insert(:user) |