X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fpublisher_test.exs;h=95f12de2d869ffbe84f07f2f5f718fd6db4dfae8;hb=90c4785b893416b95e637437b08298781e86573c;hp=b9388b966d5d3e067df18c325a54b8c146728a35;hpb=049ece1ef38f1aeb656a88ed1d15bf3d4a364e01;p=akkoma diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index b9388b966..95f12de2d 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.PublisherTest do @@ -23,7 +23,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do :ok end - setup_all do: clear_config([:instance, :federating], true) + setup_all do + clear_config([:instance, :federating], true) + clear_config([:instance, :quarantined_instances], []) + end describe "gather_webfinger_links/1" do test "it returns links" do @@ -38,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do }, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", - "template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}" + "template" => "#{Pleroma.Web.Endpoint.url()}/ostatus_subscribe?acct={uri}" } ] @@ -267,10 +270,102 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do end describe "publish/2" do + test_with_mock "doesn't publish any activity to quarantined instances.", + Pleroma.Web.Federator.Publisher, + [:passthrough], + [] do + Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}]) + + follower = + insert(:user, %{ + local: false, + inbox: "https://domain.com/users/nick1/inbox", + ap_enabled: true + }) + + actor = insert(:user, follower_address: follower.ap_id) + + {:ok, follower, actor} = Pleroma.User.follow(follower, actor) + actor = refresh_record(actor) + + note_activity = + insert(:followers_only_note_activity, + user: actor, + recipients: [follower.ap_id] + ) + + public_note_activity = + insert(:note_activity, + user: actor, + recipients: [follower.ap_id, @as_public] + ) + + res = Publisher.publish(actor, note_activity) + + assert res == :ok + + :ok = Publisher.publish(actor, public_note_activity) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://domain.com/users/nick1/inbox", + actor_id: actor.id, + id: note_activity.data["id"] + }) + ) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://domain.com/users/nick1/inbox", + actor_id: actor.id, + id: public_note_activity.data["id"] + }) + ) + end + + test_with_mock "Publishes a non-public activity to non-quarantined instances.", + Pleroma.Web.Federator.Publisher, + [:passthrough], + [] do + Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}]) + + follower = + insert(:user, %{ + local: false, + inbox: "https://domain.com/users/nick1/inbox", + ap_enabled: true + }) + + actor = insert(:user, follower_address: follower.ap_id) + + {:ok, follower, actor} = Pleroma.User.follow(follower, actor) + actor = refresh_record(actor) + + note_activity = + insert(:followers_only_note_activity, + user: actor, + recipients: [follower.ap_id] + ) + + res = Publisher.publish(actor, note_activity) + + assert res == :ok + + assert called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://domain.com/users/nick1/inbox", + actor_id: actor.id, + id: note_activity.data["id"] + }) + ) + end + test_with_mock "publishes an activity with BCC to all relevant peers.", Pleroma.Web.Federator.Publisher, [:passthrough], [] do + Config.put([:instance, :quarantined_instances], []) + follower = insert(:user, %{ local: false, @@ -281,8 +376,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do actor = insert(:user, follower_address: follower.ap_id) user = insert(:user) - {:ok, _follower_one} = Pleroma.User.follow(follower, actor) - actor = refresh_record(actor) + {:ok, follower, actor} = Pleroma.User.follow(follower, actor) note_activity = insert(:note_activity, @@ -306,6 +400,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Pleroma.Web.Federator.Publisher, [:passthrough], [] do + clear_config([:instance, :quarantined_instances], []) + fetcher = insert(:user, local: false, @@ -323,7 +419,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do actor = insert(:user) note_activity = insert(:note_activity, user: actor) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url()) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())