diff options
Diffstat (limited to 'test/web/activity_pub')
10 files changed, 67 insertions, 28 deletions
diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs index fca0de7c6..3c795f5ac 100644 --- a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs +++ b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs @@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do          "id" => "https://example.com/activities/1234"        } -      {:reject, nil} = AntiFollowbotPolicy.filter(message) +      assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)      end      test "matches followbots by display name" do @@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do          "id" => "https://example.com/activities/1234"        } -      {:reject, nil} = AntiFollowbotPolicy.filter(message) +      assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)      end    end diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs index 6e9daa7f9..26f5bcdaa 100644 --- a/test/web/activity_pub/mrf/hellthread_policy_test.exs +++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs @@ -50,7 +50,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do      } do        Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2}) -      {:reject, nil} = filter(message) +      assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} == +               filter(message)      end      test "does not reject the message if the recipient count is below reject_threshold", %{ diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs index fd1f7aec8..b3d0f3d90 100644 --- a/test/web/activity_pub/mrf/keyword_policy_test.exs +++ b/test/web/activity_pub/mrf/keyword_policy_test.exs @@ -25,7 +25,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do          }        } -      assert {:reject, nil} == KeywordPolicy.filter(message) +      assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} = +               KeywordPolicy.filter(message)      end      test "rejects if string matches in summary" do @@ -39,7 +40,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do          }        } -      assert {:reject, nil} == KeywordPolicy.filter(message) +      assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} = +               KeywordPolicy.filter(message)      end      test "rejects if regex matches in content" do @@ -55,7 +57,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do                     }                   } -                 {:reject, nil} == KeywordPolicy.filter(message) +                 {:reject, "[KeywordPolicy] Matches with rejected keyword"} == +                   KeywordPolicy.filter(message)                 end)      end @@ -72,7 +75,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do                     }                   } -                 {:reject, nil} == KeywordPolicy.filter(message) +                 {:reject, "[KeywordPolicy] Matches with rejected keyword"} == +                   KeywordPolicy.filter(message)                 end)      end    end diff --git a/test/web/activity_pub/mrf/mention_policy_test.exs b/test/web/activity_pub/mrf/mention_policy_test.exs index aa003bef5..220309cc9 100644 --- a/test/web/activity_pub/mrf/mention_policy_test.exs +++ b/test/web/activity_pub/mrf/mention_policy_test.exs @@ -76,7 +76,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do          "to" => ["https://example.com/blocked"]        } -      assert MentionPolicy.filter(message) == {:reject, nil} +      assert MentionPolicy.filter(message) == +               {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}      end      test "cc" do @@ -88,7 +89,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do          "cc" => ["https://example.com/blocked"]        } -      assert MentionPolicy.filter(message) == {:reject, nil} +      assert MentionPolicy.filter(message) == +               {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}      end    end  end diff --git a/test/web/activity_pub/mrf/reject_non_public_test.exs b/test/web/activity_pub/mrf/reject_non_public_test.exs index f36299b86..58b46b9a2 100644 --- a/test/web/activity_pub/mrf/reject_non_public_test.exs +++ b/test/web/activity_pub/mrf/reject_non_public_test.exs @@ -64,7 +64,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do        }        Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false) -      assert {:reject, nil} = RejectNonPublic.filter(message) +      assert {:reject, _} = RejectNonPublic.filter(message)      end    end @@ -94,7 +94,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do        }        Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false) -      assert {:reject, nil} = RejectNonPublic.filter(message) +      assert {:reject, _} = RejectNonPublic.filter(message)      end    end  end diff --git a/test/web/activity_pub/mrf/simple_policy_test.exs b/test/web/activity_pub/mrf/simple_policy_test.exs index b7b9bc6a2..e842d8d8d 100644 --- a/test/web/activity_pub/mrf/simple_policy_test.exs +++ b/test/web/activity_pub/mrf/simple_policy_test.exs @@ -124,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        report_message = build_report_message()        local_message = build_local_message() -      assert SimplePolicy.filter(report_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(report_message)        assert SimplePolicy.filter(local_message) == {:ok, local_message}      end @@ -133,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        report_message = build_report_message()        local_message = build_local_message() -      assert SimplePolicy.filter(report_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(report_message)        assert SimplePolicy.filter(local_message) == {:ok, local_message}      end    end @@ -241,7 +241,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        remote_message = build_remote_message() -      assert SimplePolicy.filter(remote_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(remote_message)      end      test "activity matches with wildcard domain" do @@ -249,7 +249,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        remote_message = build_remote_message() -      assert SimplePolicy.filter(remote_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(remote_message)      end      test "actor has a matching host" do @@ -257,7 +257,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        remote_user = build_remote_user() -      assert SimplePolicy.filter(remote_user) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(remote_user)      end    end @@ -279,7 +279,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do        remote_message = build_remote_message()        assert SimplePolicy.filter(local_message) == {:ok, local_message} -      assert SimplePolicy.filter(remote_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(remote_message)      end      test "activity has a matching host" do @@ -429,7 +429,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do      test "it rejects the deletion" do        deletion_message = build_remote_deletion_message() -      assert SimplePolicy.filter(deletion_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(deletion_message)      end    end @@ -439,7 +439,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do      test "it rejects the deletion" do        deletion_message = build_remote_deletion_message() -      assert SimplePolicy.filter(deletion_message) == {:reject, nil} +      assert {:reject, _} = SimplePolicy.filter(deletion_message)      end    end diff --git a/test/web/activity_pub/mrf/tag_policy_test.exs b/test/web/activity_pub/mrf/tag_policy_test.exs index e7793641a..6ff71d640 100644 --- a/test/web/activity_pub/mrf/tag_policy_test.exs +++ b/test/web/activity_pub/mrf/tag_policy_test.exs @@ -12,8 +12,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do    describe "mrf_tag:disable-any-subscription" do      test "rejects message" do        actor = insert(:user, tags: ["mrf_tag:disable-any-subscription"]) -      message = %{"object" => actor.ap_id, "type" => "Follow"} -      assert {:reject, nil} = TagPolicy.filter(message) +      message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => actor.ap_id} +      assert {:reject, _} = TagPolicy.filter(message)      end    end @@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do        actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])        follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: false)        message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id} -      assert {:reject, nil} = TagPolicy.filter(message) +      assert {:reject, _} = TagPolicy.filter(message)      end      test "allows non-local follow requests" do diff --git a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs index ba1b69658..8e1ad5bc8 100644 --- a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs +++ b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs @@ -26,6 +26,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do      actor = insert(:user)      Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})      message = %{"actor" => actor.ap_id} -    assert UserAllowListPolicy.filter(message) == {:reject, nil} +    assert {:reject, _} = UserAllowListPolicy.filter(message)    end  end diff --git a/test/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/web/activity_pub/mrf/vocabulary_policy_test.exs index 69f22bb77..2bceb67ee 100644 --- a/test/web/activity_pub/mrf/vocabulary_policy_test.exs +++ b/test/web/activity_pub/mrf/vocabulary_policy_test.exs @@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do          }        } -      {:reject, nil} = VocabularyPolicy.filter(message) +      {:reject, _} = VocabularyPolicy.filter(message)      end      test "it does not accept disallowed parent types" do @@ -60,7 +60,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do          }        } -      {:reject, nil} = VocabularyPolicy.filter(message) +      {:reject, _} = VocabularyPolicy.filter(message)      end    end @@ -75,7 +75,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do          "object" => "whatever"        } -      {:reject, nil} = VocabularyPolicy.filter(message) +      {:reject, _} = VocabularyPolicy.filter(message)      end      test "it rejects based on child object type" do @@ -89,7 +89,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do          }        } -      {:reject, nil} = VocabularyPolicy.filter(message) +      {:reject, _} = VocabularyPolicy.filter(message)      end      test "it passes through objects that aren't disallowed" do diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs index c2bc38d52..b9388b966 100644 --- a/test/web/activity_pub/publisher_test.exs +++ b/test/web/activity_pub/publisher_test.exs @@ -123,6 +123,39 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do    end    describe "publish_one/1" do +    test "publish to url with with different ports" do +      inbox80 = "http://42.site/users/nick1/inbox" +      inbox42 = "http://42.site:42/users/nick1/inbox" + +      mock(fn +        %{method: :post, url: "http://42.site:42/users/nick1/inbox"} -> +          {:ok, %Tesla.Env{status: 200, body: "port 42"}} + +        %{method: :post, url: "http://42.site/users/nick1/inbox"} -> +          {:ok, %Tesla.Env{status: 200, body: "port 80"}} +      end) + +      actor = insert(:user) + +      assert {:ok, %{body: "port 42"}} = +               Publisher.publish_one(%{ +                 inbox: inbox42, +                 json: "{}", +                 actor: actor, +                 id: 1, +                 unreachable_since: true +               }) + +      assert {:ok, %{body: "port 80"}} = +               Publisher.publish_one(%{ +                 inbox: inbox80, +                 json: "{}", +                 actor: actor, +                 id: 1, +                 unreachable_since: true +               }) +    end +      test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",                     Instances,                     [:passthrough], @@ -131,7 +164,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do        inbox = "http://200.site/users/nick1/inbox"        assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) -        assert called(Instances.set_reachable(inbox))      end  | 
