1 defmodule Pleroma.Object.FetcherTest do
6 alias Pleroma.Object.Fetcher
11 %{method: :get, url: "https://mastodon.example.org/users/userisgone"} ->
12 %Tesla.Env{status: 410}
15 apply(HttpRequestMock, :request, [env])
21 describe "actor origin containment" do
22 test "it rejects objects with a bogus origin" do
23 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
26 test "it rejects objects when attributedTo is wrong (variant 1)" do
27 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
30 test "it rejects objects when attributedTo is wrong (variant 2)" do
31 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
35 describe "fetching an object" do
36 test "it fetches an object" do
38 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
40 assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
41 assert activity.data["id"]
44 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
46 assert [attachment] = object.data["attachment"]
47 assert is_list(attachment["url"])
49 assert object == object_again
52 test "it works with objects only available via Ostatus" do
53 {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
54 assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
55 assert activity.data["id"]
57 {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
59 assert object == object_again
62 test "it correctly stitches up conversations between ostatus and ap" do
63 last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
64 {:ok, object} = Fetcher.fetch_object_from_id(last)
66 object = Object.get_by_ap_id(object.data["inReplyTo"])
71 describe "implementation quirks" do
72 test "it can fetch plume articles" do
74 Fetcher.fetch_object_from_id(
75 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
81 test "it can fetch peertube videos" do
83 Fetcher.fetch_object_from_id(
84 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
90 test "all objects with fake directions are rejected by the object fetcher" do
92 Fetcher.fetch_and_contain_remote_object_from_id(
93 "https://info.pleroma.site/activity4.json"
97 test "handle HTTP 410 Gone response" do
98 assert {:error, "Object has been deleted"} ==
99 Fetcher.fetch_and_contain_remote_object_from_id(
100 "https://mastodon.example.org/users/userisgone"
105 describe "pruning" do
106 test "it can refetch pruned objects" do
107 object_id = "http://mastodon.example.org/@admin/99541947525187367"
109 {:ok, object} = Fetcher.fetch_object_from_id(object_id)
113 {:ok, _object} = Object.prune(object)
115 refute Object.get_by_ap_id(object_id)
117 {:ok, %Object{} = object_two} = Fetcher.fetch_object_from_id(object_id)
119 assert object.data["id"] == object_two.data["id"]
120 assert object.id != object_two.id