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