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 wedistribute articles" do
82 Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810")
87 test "all objects with fake directions are rejected by the object fetcher" do
89 Fetcher.fetch_and_contain_remote_object_from_id(
90 "https://info.pleroma.site/activity4.json"
94 test "handle HTTP 410 Gone response" do
95 assert {:error, "Object has been deleted"} ==
96 Fetcher.fetch_and_contain_remote_object_from_id(
97 "https://mastodon.example.org/users/userisgone"
101 test "handle HTTP 404 response" do
102 assert {:error, "Object has been deleted"} ==
103 Fetcher.fetch_and_contain_remote_object_from_id(
104 "https://mastodon.example.org/users/userisgone404"
109 describe "pruning" do
110 test "it can refetch pruned objects" do
111 object_id = "http://mastodon.example.org/@admin/99541947525187367"
113 {:ok, object} = Fetcher.fetch_object_from_id(object_id)
117 {:ok, _object} = Object.prune(object)
119 refute Object.get_by_ap_id(object_id)
121 {:ok, %Object{} = object_two} = Fetcher.fetch_object_from_id(object_id)
123 assert object.data["id"] == object_two.data["id"]
124 assert object.id != object_two.id
128 describe "signed fetches" do
129 clear_config([:activitypub, :sign_object_fetches])
131 test_with_mock "it signs fetches when configured to do so",
135 Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
137 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
139 assert called(Pleroma.Signature.sign(:_, :_))
142 test_with_mock "it doesn't sign fetches when not configured to do so",
146 Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
148 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
150 refute called(Pleroma.Signature.sign(:_, :_))