Do not fetch anything from blocked instances
[akkoma] / test / pleroma / object / fetcher_test.exs
index cd5437617b6aa5229df14e747e16bcc43ee0a2a1..c76a09fd7142e7c3f82961afb2dc315376ea988f 100644 (file)
@@ -161,12 +161,34 @@ defmodule Pleroma.Object.FetcherTest do
                )
     end
 
+    test "does not fetch anything from a rejected instance" do
+      clear_config([:mrf_simple, :reject], [{"evil.example.org", "i said so"}])
+
+      assert {:reject, _} =
+               Fetcher.fetch_object_from_id("http://evil.example.org/@admin/99541947525187367")
+    end
+
+    test "does not fetch anything if mrf_simple accept is on" do
+      clear_config([:mrf_simple, :accept], [{"mastodon.example.org", "i said so"}])
+      clear_config([:mrf_simple, :reject], [])
+
+      assert {:reject, _} =
+               Fetcher.fetch_object_from_id(
+                 "http://notlisted.example.org/@admin/99541947525187367"
+               )
+
+      assert {:ok, _object} =
+               Fetcher.fetch_object_from_id(
+                 "http://mastodon.example.org/@admin/99541947525187367"
+               )
+    end
+
     test "it resets instance reachability on successful fetch" do
       id = "http://mastodon.example.org/@admin/99541947525187367"
       Instances.set_consistently_unreachable(id)
       refute Instances.reachable?(id)
 
-      {:ok, object} =
+      {:ok, _object} =
         Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
 
       assert Instances.reachable?(id)
@@ -216,14 +238,16 @@ defmodule Pleroma.Object.FetcherTest do
     end
 
     test "handle HTTP 410 Gone response" do
-      assert {:error, "Object has been deleted"} ==
+      assert {:error,
+              {"Object has been deleted", "https://mastodon.example.org/users/userisgone", 410}} ==
                Fetcher.fetch_and_contain_remote_object_from_id(
                  "https://mastodon.example.org/users/userisgone"
                )
     end
 
     test "handle HTTP 404 response" do
-      assert {:error, "Object has been deleted"} ==
+      assert {:error,
+              {"Object has been deleted", "https://mastodon.example.org/users/userisgone404", 404}} ==
                Fetcher.fetch_and_contain_remote_object_from_id(
                  "https://mastodon.example.org/users/userisgone404"
                )