Make HashtagPolicy history-aware

This commit is contained in:
Tusooa Zhu 2022-07-24 00:02:39 -04:00
commit d877d2a4e7
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
2 changed files with 107 additions and 10 deletions

View file

@ -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)