X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fpublisher_test.exs;h=93bf5c345e95084a7f6b4d3abb9e13f63895196b;hb=1f863f0a36ebb0648c3d39ecb7ea9e3d01deab60;hp=3503d25b22ce906116d91e70f8bd7065abee4030;hpb=31c89acd00396f95a35ea325ed848ffeb2826017;p=akkoma diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 3503d25b2..93bf5c345 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,11 @@ 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], []) + clear_config([:mrf_simple, :reject], []) + end describe "gather_webfinger_links/1" do test "it returns links" do @@ -38,7 +42,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 +271,129 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do end describe "publish/2" do + test_with_mock "doesn't publish any activity to quarantined or rejected instances.", + Pleroma.Web.Federator.Publisher, + [:passthrough], + [] do + Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}]) + + Config.put([:mrf_simple, :reject], [{"rejected.com", "some reason"}]) + + follower = + insert(:user, %{ + local: false, + inbox: "https://domain.com/users/nick1/inbox", + ap_enabled: true + }) + + another_follower = + insert(:user, %{ + local: false, + inbox: "https://rejected.com/users/nick2/inbox", + ap_enabled: true + }) + + actor = insert(:user, follower_address: follower.ap_id) + + {:ok, follower, actor} = Pleroma.User.follow(follower, actor) + {:ok, _another_follower, actor} = Pleroma.User.follow(another_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"] + }) + ) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://rejected.com/users/nick2/inbox", + actor_id: actor.id, + id: note_activity.data["id"] + }) + ) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://rejected.com/users/nick2/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, @@ -305,6 +428,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Pleroma.Web.Federator.Publisher, [:passthrough], [] do + clear_config([:instance, :quarantined_instances], []) + fetcher = insert(:user, local: false, @@ -322,7 +447,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())