Add test confirming cancellation for activity by a deleted user

This commit is contained in:
Mark Felder 2024-08-28 15:54:49 -04:00
parent fc450fdefc
commit 60101e240d

View file

@ -51,46 +51,32 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
}) })
end end
test "it does not retry if a user fetch fails with a 403" do describe "cancels on a failed user fetch" do
setup do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{url: "https://simpsons.com/users/bart"} -> %{url: "https://springfield.social/users/bart"} ->
%Tesla.Env{ %Tesla.Env{
status: 403, status: 403,
body: "" body: ""
} }
end)
params = %{url: "https://springfield.social/users/troymcclure"} ->
%{ %Tesla.Env{
"@context" => [ status: 404,
"https://www.w3.org/ns/activitystreams", body: ""
"https://w3id.org/security/v1"
],
"actor" => "https://simpsons.com/users/bart",
"cc" => [],
"id" => "https://simpsons.com/activity/eat-my-shorts",
"object" => %{},
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"type" => "Create"
} }
end)
end
req_headers = [ test "when request returns a 403" do
["accept-encoding", "gzip"], params =
["content-length", "31337"], insert(:note_activity).data
["content-type", "application/activity+json"], |> Map.put("actor", "https://springfield.social/users/bart")
["date", "Wed, 28 Aug 2024 15:36:31 GMT"],
["digest", "SHA-256=ouge/6HP2/QryG6F3JNtZ6vzs/hSwMk67xdxe87eH7A="],
["host", "bikeshed.party"],
[
"signature",
"does not matter as user needs to be fetched first"
]
]
{:ok, oban_job} = {:ok, oban_job} =
Federator.incoming_ap_doc(%{ Federator.incoming_ap_doc(%{
method: "POST", method: "POST",
req_headers: req_headers, req_headers: [],
request_path: "/inbox", request_path: "/inbox",
params: params, params: params,
query_string: "" query_string: ""
@ -99,6 +85,24 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
assert {:cancel, {:error, :forbidden}} = ReceiverWorker.perform(oban_job) assert {:cancel, {:error, :forbidden}} = ReceiverWorker.perform(oban_job)
end end
test "when request returns a 404" do
params =
insert(:note_activity).data
|> Map.put("actor", "https://springfield.social/users/troymcclure")
{:ok, oban_job} =
Federator.incoming_ap_doc(%{
method: "POST",
req_headers: [],
request_path: "/inbox",
params: params,
query_string: ""
})
assert {:cancel, {:error, :not_found}} = ReceiverWorker.perform(oban_job)
end
end
test "it can validate the signature" do test "it can validate the signature" do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{url: "https://mastodon.social/users/bastianallgeier"} -> %{url: "https://mastodon.social/users/bastianallgeier"} ->