From b9f84a382a0e4bbee09e21346f9293962b80917c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 12 May 2019 03:01:42 +0300 Subject: [PATCH 1/2] Normalize the object only after ensuring the activity type is Create --- lib/pleroma/conversation.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/conversation.ex b/lib/pleroma/conversation.ex index 6e26c5fd4..0db195988 100644 --- a/lib/pleroma/conversation.ex +++ b/lib/pleroma/conversation.ex @@ -47,8 +47,8 @@ defmodule Pleroma.Conversation do """ def create_or_bump_for(activity) do with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity), - object <- Pleroma.Object.normalize(activity), "Create" <- activity.data["type"], + object <- Pleroma.Object.normalize(activity), "Note" <- object.data["type"], ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do {:ok, conversation} = create_for_ap_id(ap_id) From 15cda998f3bdc03f58c30e34e35ebc026a90cf29 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 13 May 2019 10:32:04 +0300 Subject: [PATCH 2/2] Add a test to ensure create_or_bump_for does not normalize objects before checking the activity type --- test/conversation_test.exs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/conversation_test.exs b/test/conversation_test.exs index f3300e7d1..864b2eb03 100644 --- a/test/conversation_test.exs +++ b/test/conversation_test.exs @@ -4,7 +4,9 @@ defmodule Pleroma.ConversationTest do use Pleroma.DataCase + alias Pleroma.Activity alias Pleroma.Conversation + alias Pleroma.Object alias Pleroma.Web.CommonAPI import Pleroma.Factory @@ -134,4 +136,40 @@ defmodule Pleroma.ConversationTest do assert {:error, _} = Conversation.create_or_bump_for(activity) end + + test "create_or_bump_for does not normalize objects before checking the activity type" do + note = insert(:note) + note_id = note.data["id"] + Repo.delete(note) + refute Object.get_by_ap_id(note_id) + + Tesla.Mock.mock(fn env -> + case env.url do + ^note_id -> + # TODO: add attributedTo and tag to the note factory + body = + note.data + |> Map.put("attributedTo", note.data["actor"]) + |> Map.put("tag", []) + |> Jason.encode!() + + %Tesla.Env{status: 200, body: body} + end + end) + + undo = %Activity{ + id: "fake", + data: %{ + "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(), + "actor" => note.data["actor"], + "to" => [note.data["actor"]], + "object" => note_id, + "type" => "Undo" + } + } + + Conversation.create_or_bump_for(undo) + + refute Object.get_by_ap_id(note_id) + end end