diff options
| author | lain <lain@soykaf.club> | 2020-01-30 18:27:13 +0000 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-01-30 18:27:13 +0000 | 
| commit | e52e78a93731db46f35552d79db1d9083be0235f (patch) | |
| tree | 60a253d399e130d02236461405397ab724416bad | |
| parent | e2f2602fdc512d502cb41b8cdf07e6cc6362cf48 (diff) | |
| parent | 01fb4dbeae2b08e5ffa3d5dd8eedf6c741c7b63f (diff) | |
| download | pleroma-e52e78a93731db46f35552d79db1d9083be0235f.tar.gz pleroma-e52e78a93731db46f35552d79db1d9083be0235f.zip  | |
Merge branch 'emoji-reaction-fixie-fixes-uwu' into 'develop'
Emoji Reactions: Actually use the validation.
See merge request pleroma/pleroma!2166
| -rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 6 | ||||
| -rw-r--r-- | test/fixtures/emoji-reaction-no-emoji.json | 30 | ||||
| -rw-r--r-- | test/fixtures/emoji-reaction-too-long.json | 30 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 19 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 4 | 
5 files changed, 87 insertions, 2 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1ac67b618..5c436941a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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 diff --git a/test/fixtures/emoji-reaction-no-emoji.json b/test/fixtures/emoji-reaction-no-emoji.json new file mode 100644 index 000000000..fff77b29b --- /dev/null +++ b/test/fixtures/emoji-reaction-no-emoji.json @@ -0,0 +1,30 @@ +{ +  "type": "EmojiReaction", +  "signature": { +    "type": "RsaSignature2017", +    "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", +    "creator": "http://mastodon.example.org/users/admin#main-key", +    "created": "2018-02-17T18:57:49Z" +  }, +  "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454", +  "content": "~", +  "nickname": "lain", +  "id": "http://mastodon.example.org/users/admin#reactions/2", +  "actor": "http://mastodon.example.org/users/admin", +  "@context": [ +    "https://www.w3.org/ns/activitystreams", +    "https://w3id.org/security/v1", +    { +      "toot": "http://joinmastodon.org/ns#", +      "sensitive": "as:sensitive", +      "ostatus": "http://ostatus.org#", +      "movedTo": "as:movedTo", +      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", +      "inReplyToAtomUri": "ostatus:inReplyToAtomUri", +      "conversation": "ostatus:conversation", +      "atomUri": "ostatus:atomUri", +      "Hashtag": "as:Hashtag", +      "Emoji": "toot:Emoji" +    } +  ] +} diff --git a/test/fixtures/emoji-reaction-too-long.json b/test/fixtures/emoji-reaction-too-long.json new file mode 100644 index 000000000..31830d90c --- /dev/null +++ b/test/fixtures/emoji-reaction-too-long.json @@ -0,0 +1,30 @@ +{ +  "type": "EmojiReaction", +  "signature": { +    "type": "RsaSignature2017", +    "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", +    "creator": "http://mastodon.example.org/users/admin#main-key", +    "created": "2018-02-17T18:57:49Z" +  }, +  "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454", +  "content": "👌👌", +  "nickname": "lain", +  "id": "http://mastodon.example.org/users/admin#reactions/2", +  "actor": "http://mastodon.example.org/users/admin", +  "@context": [ +    "https://www.w3.org/ns/activitystreams", +    "https://w3id.org/security/v1", +    { +      "toot": "http://joinmastodon.org/ns#", +      "sensitive": "as:sensitive", +      "ostatus": "http://ostatus.org#", +      "movedTo": "as:movedTo", +      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", +      "inReplyToAtomUri": "ostatus:inReplyToAtomUri", +      "conversation": "ostatus:conversation", +      "atomUri": "ostatus:atomUri", +      "Hashtag": "as:Hashtag", +      "Emoji": "toot:Emoji" +    } +  ] +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 5da358c43..0829a6ec2 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -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) diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index f8963e42e..8fa0c6faa 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -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  | 
