3bbade9d13104230c1d9f0c3cccb37131ea30ff7
[akkoma] / test / object / fetcher_test.exs
1 defmodule Pleroma.Object.FetcherTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.{Activity, Object}
5 alias Pleroma.Object.Fetcher
6
7 import Pleroma.Factory
8
9 describe "actor origin containment" do
10 test "it rejects objects with a bogus origin" do
11 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
12 end
13
14 test "it rejects objects when attributedTo is wrong (variant 1)" do
15 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
16 end
17
18 test "it rejects objects when attributedTo is wrong (variant 2)" do
19 {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
20 end
21 end
22
23 describe "fetching an object" do
24 test "it fetches an object" do
25 {:ok, object} =
26 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
27
28 assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
29 assert activity.data["id"]
30
31 {:ok, object_again} =
32 Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
33
34 assert [attachment] = object.data["attachment"]
35 assert is_list(attachment["url"])
36
37 assert object == object_again
38 end
39
40 test "it works with objects only available via Ostatus" do
41 {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
42 assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
43 assert activity.data["id"]
44
45 {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
46
47 assert object == object_again
48 end
49
50 test "it correctly stitches up conversations between ostatus and ap" do
51 last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
52 {:ok, object} = Fetcher.fetch_object_from_id(last)
53
54 object = Object.get_by_ap_id(object.data["inReplyTo"])
55 assert object
56 end
57 end
58
59 describe "implementation quirks" do
60 test "it can fetch plume articles" do
61 {:ok, object} =
62 Fetcher.fetch_object_from_id(
63 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
64 )
65
66 assert object
67 end
68
69 test "it can fetch peertube videos" do
70 {:ok, object} =
71 Fetcher.fetch_object_from_id(
72 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
73 )
74
75 assert object
76 end
77
78 test "all objects with fake directions are rejected by the object fetcher" do
79 {:error, _} =
80 Fetcher.fetch_and_contain_remote_object_from_id(
81 "https://info.pleroma.site/activity4.json"
82 )
83 end
84 end
85 end