bdbbb1fc494745fa2b304c24bd61f52da8d05200
[akkoma] / test / web / activity_pub / mrf / object_age_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
6 use Pleroma.DataCase
7 alias Pleroma.Config
8 alias Pleroma.User
9 alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
10 alias Pleroma.Web.ActivityPub.Visibility
11
12 clear_config(:mrf_object_age,
13 threshold: 172_800,
14 actions: [:delist, :strip_followers]
15 )
16
17 setup_all do
18 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
19 :ok
20 end
21
22 describe "with reject action" do
23 test "it rejects an old post" do
24 Config.put([:mrf_object_age, :actions], [:reject])
25
26 data =
27 File.read!("test/fixtures/mastodon-post-activity.json")
28 |> Poison.decode!()
29
30 {:reject, _} = ObjectAgePolicy.filter(data)
31 end
32
33 test "it allows a new post" do
34 Config.put([:mrf_object_age, :actions], [:reject])
35
36 data =
37 File.read!("test/fixtures/mastodon-post-activity.json")
38 |> Poison.decode!()
39 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
40
41 {:ok, _} = ObjectAgePolicy.filter(data)
42 end
43 end
44
45 describe "with delist action" do
46 test "it delists an old post" do
47 Config.put([:mrf_object_age, :actions], [:delist])
48
49 data =
50 File.read!("test/fixtures/mastodon-post-activity.json")
51 |> Poison.decode!()
52
53 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
54
55 {:ok, data} = ObjectAgePolicy.filter(data)
56
57 assert Visibility.get_visibility(%{data: data}) == "unlisted"
58 end
59
60 test "it allows a new post" do
61 Config.put([:mrf_object_age, :actions], [:delist])
62
63 data =
64 File.read!("test/fixtures/mastodon-post-activity.json")
65 |> Poison.decode!()
66 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
67
68 {:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
69
70 {:ok, ^data} = ObjectAgePolicy.filter(data)
71 end
72 end
73
74 describe "with strip_followers action" do
75 test "it strips followers collections from an old post" do
76 Config.put([:mrf_object_age, :actions], [:strip_followers])
77
78 data =
79 File.read!("test/fixtures/mastodon-post-activity.json")
80 |> Poison.decode!()
81
82 {:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
83
84 {:ok, data} = ObjectAgePolicy.filter(data)
85
86 refute user.follower_address in data["to"]
87 refute user.follower_address in data["cc"]
88 end
89
90 test "it allows a new post" do
91 Config.put([:mrf_object_age, :actions], [:strip_followers])
92
93 data =
94 File.read!("test/fixtures/mastodon-post-activity.json")
95 |> Poison.decode!()
96 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
97
98 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
99
100 {:ok, ^data} = ObjectAgePolicy.filter(data)
101 end
102 end
103 end