Emoji Reactions: Actually use the validation.
authorlain <lain@soykaf.club>
Thu, 30 Jan 2020 15:07:37 +0000 (16:07 +0100)
committerlain <lain@soykaf.club>
Thu, 30 Jan 2020 15:07:37 +0000 (16:07 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/transmogrifier_test.exs
test/web/common_api/common_api_test.exs

index 1ac67b618c84fc8675efcf591bb7fbb686ddcd87..5c436941ae7aa8f6eea72cdb42256298bca69bfb 100644 (file)
@@ -325,12 +325,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   def react_with_emoji(user, object, emoji, options \\ []) do
     with local <- Keyword.get(options, :local, true),
          activity_id <- Keyword.get(options, :activity_id, nil),
-         Pleroma.Emoji.is_unicode_emoji?(emoji),
+         true <- Pleroma.Emoji.is_unicode_emoji?(emoji),
          reaction_data <- make_emoji_reaction_data(user, object, emoji, activity_id),
          {:ok, activity} <- insert(reaction_data, local),
          {:ok, object} <- add_emoji_reaction_to_object(activity, object),
          :ok <- maybe_federate(activity) do
       {:ok, activity, object}
+    else
+      e -> {:error, e}
     end
   end
 
@@ -345,6 +347,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
          {:ok, object} <- remove_emoji_reaction_from_object(reaction_activity, object),
          :ok <- maybe_federate(activity) do
       {:ok, activity, object}
+    else
+      e -> {:error, e}
     end
   end
 
index 5da358c43636e10fa0556dfbb3d4b72393c43bfe..0829a6ec2d1e2f47064a99ab1fcaceedeb87db12 100644 (file)
@@ -395,6 +395,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert data["content"] == "👌"
     end
 
+    test "it reject invalid emoji reactions" do
+      user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+
+      data =
+        File.read!("test/fixtures/emoji-reaction-too-long.json")
+        |> Poison.decode!()
+        |> Map.put("object", activity.data["object"])
+
+      assert :error = Transmogrifier.handle_incoming(data)
+
+      data =
+        File.read!("test/fixtures/emoji-reaction-no-emoji.json")
+        |> Poison.decode!()
+        |> Map.put("object", activity.data["object"])
+
+      assert :error = Transmogrifier.handle_incoming(data)
+    end
+
     test "it works for incoming emoji reaction undos" do
       user = insert(:user)
 
index f8963e42e90a9c41666fc78f4f0905b27e736310..8fa0c6faa952d7c7a6bb6fbe38c659df8c4d9190 100644 (file)
@@ -238,7 +238,9 @@ defmodule Pleroma.Web.CommonAPITest do
       assert reaction.data["actor"] == user.ap_id
       assert reaction.data["content"] == "👍"
 
-      # TODO: test error case.
+      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+      {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
     end
 
     test "unreacting to a status with an emoji" do