X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Ftransmogrifier_test.exs;h=5a3b57acb84d1923ac2d950f1c022105a93d2ffb;hb=197cdebca936fd01175476036f1230167bf353bc;hp=d0bd00b58dda8c162e9f4b9da1a2c3f8f8d1b9af;hpb=acb03d591bea1b20a715201f479f1ad7bf7bb67b;p=akkoma
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index d0bd00b58..5a3b57acb 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI
@@ -56,7 +57,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "test post"})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
note_obj = %{
"type" => "Note",
@@ -153,23 +154,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
end
- test "it adds the sensitive property" do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
-
- assert modified["object"]["sensitive"]
- end
-
test "it adds the json-ld context and the conversation property" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- assert modified["@context"] ==
- Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
+ assert modified["@context"] == Utils.make_json_ld_header()["@context"]
assert modified["object"]["conversation"] == modified["context"]
end
@@ -202,39 +193,46 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it strips internal fields" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ status: "#2hu :firefox:",
+ generator: %{type: "Application", name: "TestClient", url: "https://pleroma.social"}
+ })
- {:ok, %{"object" => modified_object}} = Transmogrifier.prepare_outgoing(activity.data)
+ # Ensure injected application data made it into the activity
+ # as we don't have a Token to derive it from, otherwise it will
+ # be nil and the test will pass
+ assert %{
+ type: "Application",
+ name: "TestClient",
+ url: "https://pleroma.social"
+ } == activity.object.data["generator"]
- assert [
- %{"name" => "#2hu", "type" => "Hashtag"},
- %{"name" => ":firefox:", "type" => "Emoji"}
- ] = modified_object["tag"]
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- refute Map.has_key?(modified_object, "hashtags")
- refute Map.has_key?(modified_object, "emoji")
- refute Map.has_key?(modified_object, "like_count")
- refute Map.has_key?(modified_object, "announcements")
- refute Map.has_key?(modified_object, "announcement_count")
- refute Map.has_key?(modified_object, "context_id")
+ assert length(modified["object"]["tag"]) == 2
+
+ assert is_nil(modified["object"]["emoji"])
+ assert is_nil(modified["object"]["like_count"])
+ assert is_nil(modified["object"]["announcements"])
+ assert is_nil(modified["object"]["announcement_count"])
+ assert is_nil(modified["object"]["context_id"])
+ assert is_nil(modified["object"]["generator"])
end
test "it strips internal fields of article" do
activity = insert(:article_activity)
- {:ok, %{"object" => modified_object}} = Transmogrifier.prepare_outgoing(activity.data)
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- assert [
- %{"name" => "#2hu", "type" => "Hashtag"},
- %{"name" => ":2hu:", "type" => "Emoji"}
- ] = modified_object["tag"]
+ assert length(modified["object"]["tag"]) == 2
- refute Map.has_key?(modified_object, "hashtags")
- refute Map.has_key?(modified_object, "emoji")
- refute Map.has_key?(modified_object, "like_count")
- refute Map.has_key?(modified_object, "announcements")
- refute Map.has_key?(modified_object, "announcement_count")
- refute Map.has_key?(modified_object, "context_id")
+ assert is_nil(modified["object"]["emoji"])
+ assert is_nil(modified["object"]["like_count"])
+ assert is_nil(modified["object"]["announcements"])
+ assert is_nil(modified["object"]["announcement_count"])
+ assert is_nil(modified["object"]["context_id"])
+ assert is_nil(modified["object"]["likes"])
end
test "the directMessage flag is present" do
@@ -288,6 +286,21 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
end
+
+ test "custom emoji urls are URI encoded" do
+ # :dinosaur: filename has a space -> dino walking.gif
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
+
+ {:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert length(prepared["object"]["tag"]) == 1
+
+ url = prepared["object"]["tag"] |> List.first() |> Map.get("icon") |> Map.get("url")
+
+ assert url == "http://localhost:4001/emoji/dino%20walking.gif"
+ end
end
describe "user upgrade" do
@@ -433,7 +446,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end)
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
@@ -446,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
"cc" => []
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert user.follower_address in fixed_object["to"]
refute user.follower_address in fixed_object["cc"]
end
@@ -460,7 +473,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
"cc" => [user.follower_address, recipient.follower_address]
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert user.follower_address in fixed_object["cc"]
refute recipient.follower_address in fixed_object["cc"]