1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
6 use Oban.Testing, repo: Pleroma.Repo
11 alias Pleroma.Tests.ObanHelpers
13 alias Pleroma.Web.ActivityPub.Transmogrifier
15 import Pleroma.Factory
16 import ExUnit.CaptureLog
19 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
23 test "it works for incoming deletes" do
24 activity = insert(:note_activity)
25 deleting_user = insert(:user)
28 File.read!("test/fixtures/mastodon-delete.json")
33 |> Map.put("id", activity.data["object"])
37 |> Map.put("object", object)
38 |> Map.put("actor", deleting_user.ap_id)
40 {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
41 Transmogrifier.handle_incoming(data)
43 assert id == data["id"]
45 # We delete the Create activity because base our timelines on it.
46 # This should be changed after we unify objects and activities
47 refute Activity.get_by_id(activity.id)
48 assert actor == deleting_user.ap_id
50 # Objects are replaced by a tombstone object.
51 object = Object.normalize(activity.data["object"])
52 assert object.data["type"] == "Tombstone"
55 test "it fails for incoming deletes with spoofed origin" do
56 activity = insert(:note_activity)
59 File.read!("test/fixtures/mastodon-delete.json")
64 |> Map.put("id", activity.data["object"])
68 |> Map.put("object", object)
70 assert capture_log(fn ->
71 :error = Transmogrifier.handle_incoming(data)
73 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, :nxdomain}"
75 assert Activity.get_by_id(activity.id)
78 @tag capture_log: true
79 test "it works for incoming user deletes" do
80 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
83 File.read!("test/fixtures/mastodon-delete-user.json")
86 {:ok, _} = Transmogrifier.handle_incoming(data)
87 ObanHelpers.perform_all()
89 refute User.get_cached_by_ap_id(ap_id)
92 test "it fails for incoming user deletes with spoofed origin" do
93 %{ap_id: ap_id} = insert(:user)
96 File.read!("test/fixtures/mastodon-delete-user.json")
98 |> Map.put("actor", ap_id)
100 assert capture_log(fn ->
101 assert :error == Transmogrifier.handle_incoming(data)
102 end) =~ "Object containment failed"
104 assert User.get_cached_by_ap_id(ap_id)