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}
14 %{method: :get, url: "https://mastodon.example.org/users/userisgone404"} ->
15 %Tesla.Env{status: 404}
18 apply(HttpRequestMock, :request, [env])
24 describe "actor origin containment" do
25 test "it rejects objects with a bogus origin" do
26 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
29 test "it rejects objects when attributedTo is wrong (variant 1)" do
30 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
33 test "it rejects objects when attributedTo is wrong (variant 2)" do
34 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
38 describe "fetching an object" do
39 test "it fetches an object" do
41 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
43 assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
44 assert activity.data["id"]
47 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
49 assert [attachment] = object.data["attachment"]
50 assert is_list(attachment["url"])
52 assert object == object_again
55 test "it works with objects only available via Ostatus" do
56 {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
57 assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
58 assert activity.data["id"]
60 {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
62 assert object == object_again
65 test "it correctly stitches up conversations between ostatus and ap" do
66 last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
67 {:ok, object} = Fetcher.fetch_object_from_id(last)
69 object = Object.get_by_ap_id(object.data["inReplyTo"])
74 describe "implementation quirks" do
75 test "it can fetch plume articles" do
77 Fetcher.fetch_object_from_id(
78 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
84 test "it can fetch peertube videos" do
86 Fetcher.fetch_object_from_id(
87 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
93 test "all objects with fake directions are rejected by the object fetcher" do
95 Fetcher.fetch_and_contain_remote_object_from_id(
96 "https://info.pleroma.site/activity4.json"
100 test "handle HTTP 410 Gone response" do
101 assert {:error, "Object has been deleted"} ==
102 Fetcher.fetch_and_contain_remote_object_from_id(
103 "https://mastodon.example.org/users/userisgone"
107 test "handle HTTP 404 response" do
108 assert {:error, "Object has been deleted"} ==
109 Fetcher.fetch_and_contain_remote_object_from_id(
110 "https://mastodon.example.org/users/userisgone404"
115 describe "pruning" do
116 test "it can refetch pruned objects" do
117 object_id = "http://mastodon.example.org/@admin/99541947525187367"
119 {:ok, object} = Fetcher.fetch_object_from_id(object_id)
123 {:ok, _object} = Object.prune(object)
125 refute Object.get_by_ap_id(object_id)
127 {:ok, %Object{} = object_two} = Fetcher.fetch_object_from_id(object_id)
129 assert object.data["id"] == object_two.data["id"]
130 assert object.id != object_two.id