X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Ftransmogrifier_test.exs;h=a1070848106ccc585a22149cbffe8fb20da69590;hb=ca1accc1cf6689fc52a897003b5e297f51fefaf6;hp=333bb4f9bf9812167719796463e1418a6990f1c3;hpb=30ed7b502f5db14a4635d3d80a62df3c18b91813;p=akkoma
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 333bb4f9b..a10708481 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
@@ -31,14 +32,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
follow_data =
File.read!("test/fixtures/mastodon-follow-activity.json")
- |> Poison.decode!()
+ |> Jason.decode!()
|> Map.put("object", user.ap_id)
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
data =
File.read!("test/fixtures/mastodon-unfollow-activity.json")
- |> Poison.decode!()
+ |> Jason.decode!()
|> Map.put("object", follow_data)
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -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",
@@ -106,6 +107,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert activity.data["target"] == new_user.ap_id
assert activity.data["type"] == "Move"
end
+
+ test "it fixes both the Create and object contexts in a reply" do
+ insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8")
+ insert(:user, ap_id: "https://p.helene.moe/users/helene")
+
+ create_activity =
+ "test/fixtures/create-pleroma-reply-to-misskey-thread.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(create_activity)
+
+ object = Object.normalize(activity, fetch: false)
+
+ assert activity.data["context"] == object.data["context"]
+ end
end
describe "prepare outgoing" do
@@ -153,23 +170,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,7 +209,20 @@ 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"}
+ })
+
+ # 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"]
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@@ -212,7 +232,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
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
@@ -226,7 +246,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
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
@@ -268,18 +287,41 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["bcc"])
end
- test "it can handle Listen activities" do
- listen_activity = insert(:listen)
+ test "custom emoji urls are URI encoded" do
+ # :dinosaur: filename has a space -> dino walking.gif
+ user = insert(:user)
- {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
+ {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
- assert modified["type"] == "Listen"
+ {: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
+
+ test "Updates of Notes are handled" do
user = insert(:user)
- {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
+ {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"})
+
+ {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data)
- {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
+ assert %{
+ "content" => "mew mew :blank:",
+ "tag" => [%{"name" => ":blank:", "type" => "Emoji"}],
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "content" => "everybody do the dinosaur :dinosaur:",
+ "tag" => [%{"name" => ":dinosaur:", "type" => "Emoji"}]
+ }
+ ]
+ }
+ } = prepared["object"]
end
end
@@ -426,7 +468,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"]
@@ -439,7 +481,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
@@ -453,7 +495,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"]
@@ -504,4 +546,83 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
)
end
end
+
+ describe "fix_attachments/1" do
+ test "puts dimensions into attachment url field" do
+ object = %{
+ "attachment" => [
+ %{
+ "type" => "Document",
+ "name" => "Hello world",
+ "url" => "https://media.example.tld/1.jpg",
+ "width" => 880,
+ "height" => 960,
+ "mediaType" => "image/jpeg",
+ "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+ }
+ ]
+ }
+
+ expected = %{
+ "attachment" => [
+ %{
+ "type" => "Document",
+ "name" => "Hello world",
+ "url" => [
+ %{
+ "type" => "Link",
+ "mediaType" => "image/jpeg",
+ "href" => "https://media.example.tld/1.jpg",
+ "width" => 880,
+ "height" => 960
+ }
+ ],
+ "mediaType" => "image/jpeg",
+ "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+ }
+ ]
+ }
+
+ assert Transmogrifier.fix_attachments(object) == expected
+ end
+ end
+
+ describe "prepare_object/1" do
+ test "it processes history" do
+ original = %{
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "generator" => %{},
+ "emoji" => %{"blobcat" => "http://localhost:4001/emoji/blobcat.png"}
+ }
+ ]
+ }
+ }
+
+ processed = Transmogrifier.prepare_object(original)
+
+ history_item = Enum.at(processed["formerRepresentations"]["orderedItems"], 0)
+
+ refute Map.has_key?(history_item, "generator")
+
+ assert [%{"name" => ":blobcat:"}] = history_item["tag"]
+ end
+
+ test "it works when there is no or bad history" do
+ original = %{
+ "formerRepresentations" => %{
+ "items" => [
+ %{
+ "generator" => %{},
+ "emoji" => %{"blobcat" => "http://localhost:4001/emoji/blobcat.png"}
+ }
+ ]
+ }
+ }
+
+ processed = Transmogrifier.prepare_object(original)
+ assert processed["formerRepresentations"] == original["formerRepresentations"]
+ end
+ end
end