summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/activity_pub/publisher_test.exs171
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs28
-rw-r--r--test/support/factory.ex3
3 files changed, 130 insertions, 72 deletions
diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs
index 569b6af1a..3acbac396 100644
--- a/test/pleroma/web/activity_pub/publisher_test.exs
+++ b/test/pleroma/web/activity_pub/publisher_test.exs
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.PublisherTest do
+ use Oban.Testing, repo: Pleroma.Repo
use Pleroma.Web.ConnCase
import ExUnit.CaptureLog
@@ -13,6 +14,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
alias Pleroma.Activity
alias Pleroma.Instances
alias Pleroma.Object
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.ActivityPub.Publisher
alias Pleroma.Web.CommonAPI
@@ -150,32 +152,20 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
_actor = insert(:user)
assert {:ok, %{body: "port 42"}} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox42,
activity_id: activity.id,
unreachable_since: true
})
+ |> Publisher.publish_one()
assert {:ok, %{body: "port 80"}} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox80,
activity_id: activity.id,
unreachable_since: true
})
- end
-
- test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",
- Instances,
- [:passthrough],
- [] do
- _actor = insert(:user)
- inbox = "http://200.site/users/nick1/inbox"
- activity = insert(:note_activity)
-
- assert {:ok, _} =
- Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
-
- assert called(Instances.set_reachable(inbox))
+ |> Publisher.publish_one()
end
test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is set",
@@ -187,11 +177,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
activity = insert(:note_activity)
assert {:ok, _} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox,
activity_id: activity.id,
unreachable_since: NaiveDateTime.utc_now()
})
+ |> Publisher.publish_one()
assert called(Instances.set_reachable(inbox))
end
@@ -205,11 +196,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
activity = insert(:note_activity)
assert {:ok, _} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox,
activity_id: activity.id,
unreachable_since: nil
})
+ |> Publisher.publish_one()
refute called(Instances.set_reachable(inbox))
end
@@ -223,7 +215,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
activity = insert(:note_activity)
assert {:cancel, _} =
- Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
+ Publisher.prepare_one(%{inbox: inbox, activity_id: activity.id})
+ |> Publisher.publish_one()
assert called(Instances.set_unreachable(inbox))
end
@@ -238,10 +231,11 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert capture_log(fn ->
assert {:error, _} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox,
activity_id: activity.id
})
+ |> Publisher.publish_one()
end) =~ "connrefused"
assert called(Instances.set_unreachable(inbox))
@@ -256,7 +250,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
activity = insert(:note_activity)
assert {:ok, _} =
- Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
+ Publisher.prepare_one(%{inbox: inbox, activity_id: activity.id})
+ |> Publisher.publish_one()
refute called(Instances.set_unreachable(inbox))
end
@@ -271,11 +266,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert capture_log(fn ->
assert {:error, _} =
- Publisher.publish_one(%{
+ Publisher.prepare_one(%{
inbox: inbox,
activity_id: activity.id,
unreachable_since: NaiveDateTime.utc_now()
})
+ |> Publisher.publish_one()
end) =~ "connrefused"
refute called(Instances.set_unreachable(inbox))
@@ -310,12 +306,15 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert res == :ok
- assert not called(
- Publisher.enqueue_one(%{
- inbox: "https://domain.com/users/nick1/inbox",
- activity_id: note_activity.id
- })
- )
+ refute_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "params" => %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ activity_id: note_activity.id
+ }
+ }
+ )
end
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
@@ -345,15 +344,16 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert res == :ok
- assert called(
- Publisher.enqueue_one(
- %{
- inbox: "https://domain.com/users/nick1/inbox",
- activity_id: note_activity.id
- },
- priority: 1
- )
- )
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "params" => %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ activity_id: note_activity.id
+ }
+ },
+ priority: 1
+ )
end
test_with_mock "Publishes to directly addressed actors with higher priority.",
@@ -403,12 +403,15 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
res = Publisher.publish(actor, note_activity)
assert res == :ok
- assert called(
- Publisher.enqueue_one(%{
- inbox: "https://domain.com/users/nick1/inbox",
- activity_id: note_activity.id
- })
- )
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "params" => %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ activity_id: note_activity.id
+ }
+ }
+ )
end
test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
@@ -452,25 +455,69 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
res = Publisher.publish(actor, delete)
assert res == :ok
- assert called(
- Publisher.enqueue_one(
- %{
- inbox: "https://domain.com/users/nick1/inbox",
- activity_id: delete.id
- },
- priority: 1
- )
- )
-
- assert called(
- Publisher.enqueue_one(
- %{
- inbox: "https://domain2.com/users/nick1/inbox",
- activity_id: delete.id
- },
- priority: 1
- )
- )
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "params" => %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ activity_id: delete.id
+ }
+ },
+ priority: 1
+ )
+
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "params" => %{
+ inbox: "https://domain2.com/users/nick1/inbox",
+ activity_id: delete.id
+ }
+ },
+ priority: 1
+ )
end
end
+
+ test "cc in prepared json for a follow request is an empty list" do
+ user = insert(:user)
+ remote_user = insert(:user, local: false)
+
+ {:ok, _, _, activity} = CommonAPI.follow(remote_user, user)
+
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "activity_id" => activity.id,
+ "op" => "publish"
+ }
+ )
+
+ ObanHelpers.perform_all()
+
+ expected_params =
+ %{
+ "activity_id" => activity.id,
+ "inbox" => remote_user.inbox,
+ "unreachable_since" => nil
+ }
+
+ assert_enqueued(
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{
+ "op" => "publish_one",
+ "params" => expected_params
+ }
+ )
+
+ # params need to be atom keys for Publisher.prepare_one.
+ # this is done in the Oban job.
+ expected_params = Map.new(expected_params, fn {k, v} -> {String.to_atom(k), v} end)
+
+ %{json: json} = Publisher.prepare_one(expected_params)
+
+ {:ok, decoded} = Jason.decode(json)
+
+ assert decoded["cc"] == []
+ end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index 904bf1471..a4bca6cf9 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -922,13 +922,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
%{id: id1} = insert(:note_activity)
%{id: id2} = insert(:note_activity)
- query_string = "ids[]=#{id1}&ids[]=#{id2}"
+ query_string = "id[]=#{id1}&id[]=#{id2}"
conn = get(conn, "/api/v1/statuses/?#{query_string}")
assert [%{"id" => ^id1}, %{"id" => ^id2}] =
Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])
end
+ test "get statuses by IDs falls back to ids[]" do
+ %{conn: conn} = oauth_access(["read:statuses"])
+ %{id: id} = insert(:note_activity)
+
+ query_string = "ids[]=#{id}"
+ conn = get(conn, "/api/v1/statuses/?#{query_string}")
+
+ assert [%{"id" => ^id}] = json_response_and_validate_schema(conn, 200)
+ end
+
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
setup do: local_and_remote_activities()
@@ -937,7 +947,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
assert json_response_and_validate_schema(res_conn, 200) == []
end
@@ -945,7 +955,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
@@ -957,7 +967,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
remote_id = remote.id
assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)
@@ -966,7 +976,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
@@ -978,7 +988,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
local_id = local.id
assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)
@@ -987,7 +997,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
+ res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
@@ -2241,7 +2251,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
result =
conn
- |> get("/api/v1/statuses/?ids[]=#{activity.id}")
+ |> get("/api/v1/statuses/?id[]=#{activity.id}")
|> json_response_and_validate_schema(200)
assert [
@@ -2254,7 +2264,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
result =
conn
- |> get("/api/v1/statuses/?ids[]=#{activity.id}&with_muted=true")
+ |> get("/api/v1/statuses/?id[]=#{activity.id}&with_muted=true")
|> json_response_and_validate_schema(200)
assert [
diff --git a/test/support/factory.ex b/test/support/factory.ex
index b248508fa..fb26f4162 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -63,7 +63,8 @@ defmodule Pleroma.Factory do
ap_id: ap_id,
follower_address: ap_id <> "/followers",
following_address: ap_id <> "/following",
- featured_address: ap_id <> "/collections/featured"
+ featured_address: ap_id <> "/collections/featured",
+ inbox: "https://#{base_domain}/inbox"
}
else
%{