Merge branch 'fix/unfollows-not-working' into 'develop'

Normalize the object in `create_or_bump_for` only after ensuring the activity type is Create

Closes #874

See merge request pleroma/pleroma!1138
This commit is contained in:
rinpatch 2019-05-13 07:39:12 +00:00
commit 17f7c5e290
2 changed files with 39 additions and 1 deletions

View File

@ -47,8 +47,8 @@ defmodule Pleroma.Conversation do
""" """
def create_or_bump_for(activity) do def create_or_bump_for(activity) do
with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity), with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity),
object <- Pleroma.Object.normalize(activity),
"Create" <- activity.data["type"], "Create" <- activity.data["type"],
object <- Pleroma.Object.normalize(activity),
"Note" <- object.data["type"], "Note" <- object.data["type"],
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do 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) {:ok, conversation} = create_for_ap_id(ap_id)

View File

@ -4,7 +4,9 @@
defmodule Pleroma.ConversationTest do defmodule Pleroma.ConversationTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Conversation alias Pleroma.Conversation
alias Pleroma.Object
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import Pleroma.Factory import Pleroma.Factory
@ -134,4 +136,40 @@ defmodule Pleroma.ConversationTest do
assert {:error, _} = Conversation.create_or_bump_for(activity) assert {:error, _} = Conversation.create_or_bump_for(activity)
end 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 end