Merge branch 'feature/dm-sanity' into 'develop'
DM sanitization See merge request pleroma/pleroma!458
This commit is contained in:
commit
69454c8345
8 changed files with 186 additions and 4 deletions
|
|
@ -162,6 +162,36 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert data["object"]["url"] == "https://prismo.news/posts/83"
|
||||
end
|
||||
|
||||
test "it cleans up incoming notices which are not really DMs" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
to = [user.ap_id, other_user.ap_id]
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("to", to)
|
||||
|> Map.put("cc", [])
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("to", to)
|
||||
|> Map.put("cc", [])
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["to"] == []
|
||||
assert data["cc"] == to
|
||||
|
||||
object = data["object"]
|
||||
|
||||
assert object["to"] == []
|
||||
assert object["cc"] == to
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -872,6 +902,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert modified["object"]["likes"]["type"] == "OrderedCollection"
|
||||
assert modified["object"]["likes"]["totalItems"] == 0
|
||||
end
|
||||
|
||||
test "the directMessage flag is present" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["directMessage"] == false
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "@{other_user.nickname} :moominmamma:"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["directMessage"] == false
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "@{other_user.nickname} :moominmamma:",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["directMessage"] == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "user upgrade" do
|
||||
|
|
|
|||
57
test/web/activity_pub/utils_test.exs
Normal file
57
test/web/activity_pub/utils_test.exs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
||||
describe "determine_explicit_mentions()" do
|
||||
test "works with an object that has mentions" do
|
||||
object = %{
|
||||
"tag" => [
|
||||
%{
|
||||
"type" => "Mention",
|
||||
"href" => "https://example.com/~alyssa",
|
||||
"name" => "Alyssa P. Hacker"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
|
||||
end
|
||||
|
||||
test "works with an object that does not have mentions" do
|
||||
object = %{
|
||||
"tag" => [
|
||||
%{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
|
||||
]
|
||||
}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == []
|
||||
end
|
||||
|
||||
test "works with an object that has mentions and other tags" do
|
||||
object = %{
|
||||
"tag" => [
|
||||
%{
|
||||
"type" => "Mention",
|
||||
"href" => "https://example.com/~alyssa",
|
||||
"name" => "Alyssa P. Hacker"
|
||||
},
|
||||
%{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
|
||||
]
|
||||
}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
|
||||
end
|
||||
|
||||
test "works with an object that has no tags" do
|
||||
object = %{}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == []
|
||||
end
|
||||
|
||||
test "works with an object that has only IR tags" do
|
||||
object = %{"tag" => ["2hu"]}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == []
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue