# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
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",
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, %{"object" => modified_object}} = Transmogrifier.prepare_outgoing(activity.data)
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- assert [
- %{"name" => "#2hu", "type" => "Hashtag"},
- %{"name" => ":firefox:", "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"]["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
{: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