1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Object.FetcherTest do
10 alias Pleroma.Object.Fetcher
16 %{method: :get, url: "https://mastodon.example.org/users/userisgone"} ->
17 %Tesla.Env{status: 410}
19 %{method: :get, url: "https://mastodon.example.org/users/userisgone404"} ->
20 %Tesla.Env{status: 404}
23 apply(HttpRequestMock, :request, [env])
29 describe "actor origin containment" do
30 test "it rejects objects with a bogus origin" do
31 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
34 test "it rejects objects when attributedTo is wrong (variant 1)" do
35 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
38 test "it rejects objects when attributedTo is wrong (variant 2)" do
39 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
43 describe "fetching an object" do
44 test "it fetches an object" do
46 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
48 assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
49 assert activity.data["id"]
52 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
54 assert [attachment] = object.data["attachment"]
55 assert is_list(attachment["url"])
57 assert object == object_again
61 describe "implementation quirks" do
62 test "it can fetch plume articles" do
64 Fetcher.fetch_object_from_id(
65 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
71 test "it can fetch peertube videos" do
73 Fetcher.fetch_object_from_id(
74 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
80 test "it can fetch Mobilizon events" do
82 Fetcher.fetch_object_from_id(
83 "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
89 test "it can fetch wedistribute articles" do
91 Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810")
96 test "all objects with fake directions are rejected by the object fetcher" do
98 Fetcher.fetch_and_contain_remote_object_from_id(
99 "https://info.pleroma.site/activity4.json"
103 test "handle HTTP 410 Gone response" do
104 assert {:error, "Object has been deleted"} ==
105 Fetcher.fetch_and_contain_remote_object_from_id(
106 "https://mastodon.example.org/users/userisgone"
110 test "handle HTTP 404 response" do
111 assert {:error, "Object has been deleted"} ==
112 Fetcher.fetch_and_contain_remote_object_from_id(
113 "https://mastodon.example.org/users/userisgone404"
118 describe "pruning" do
119 test "it can refetch pruned objects" do
120 object_id = "http://mastodon.example.org/@admin/99541947525187367"
122 {:ok, object} = Fetcher.fetch_object_from_id(object_id)
126 {:ok, _object} = Object.prune(object)
128 refute Object.get_by_ap_id(object_id)
130 {:ok, %Object{} = object_two} = Fetcher.fetch_object_from_id(object_id)
132 assert object.data["id"] == object_two.data["id"]
133 assert object.id != object_two.id
137 describe "signed fetches" do
138 clear_config([:activitypub, :sign_object_fetches])
140 test_with_mock "it signs fetches when configured to do so",
144 Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
146 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
148 assert called(Pleroma.Signature.sign(:_, :_))
151 test_with_mock "it doesn't sign fetches when not configured to do so",
155 Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
157 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
159 refute called(Pleroma.Signature.sign(:_, :_))