X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fobject%2Ffetcher_test.exs;h=e26443a81bdb41f67c6460e10748046bc1fbe018;hb=ea30d22dfe58d3b652bb27ea7c6080ac85cacc2a;hp=cd5437617b6aa5229df14e747e16bcc43ee0a2a1;hpb=3e0a5851e528135a04ca8f9ab59607ecc3ba42d9;p=akkoma diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs index cd5437617..e26443a81 100644 --- a/test/pleroma/object/fetcher_test.exs +++ b/test/pleroma/object/fetcher_test.exs @@ -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" ) @@ -548,4 +572,75 @@ defmodule Pleroma.Object.FetcherTest do } = object.data end end + + describe "get_object/1" do + test "should return ok if the content type is application/activity+json" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + end + + test "should return ok if the content type is application/ld+json with a profile" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [ + {"content-type", + "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""} + ], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [ + {"content-type", + "application/ld+json; profile=\"http://www.w3.org/ns/activitystreams\""} + ], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + end + + test "should not return ok with other content types" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/json"}], + body: "{}" + } + end) + + assert {:error, {:content_type, "application/json"}} = + Fetcher.get_object("https://mastodon.social/2") + end + end end