1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
9 alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
10 alias Pleroma.Web.ActivityPub.Visibility
12 clear_config([:mrf_object_age]) do
13 Config.put(:mrf_object_age,
15 actions: [:delist, :strip_followers]
20 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
24 describe "with reject action" do
25 test "it rejects an old post" do
26 Config.put([:mrf_object_age, :actions], [:reject])
29 File.read!("test/fixtures/mastodon-post-activity.json")
32 {:reject, _} = ObjectAgePolicy.filter(data)
35 test "it allows a new post" do
36 Config.put([:mrf_object_age, :actions], [:reject])
39 File.read!("test/fixtures/mastodon-post-activity.json")
41 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
43 {:ok, _} = ObjectAgePolicy.filter(data)
47 describe "with delist action" do
48 test "it delists an old post" do
49 Config.put([:mrf_object_age, :actions], [:delist])
52 File.read!("test/fixtures/mastodon-post-activity.json")
55 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
57 {:ok, data} = ObjectAgePolicy.filter(data)
59 assert Visibility.get_visibility(%{data: data}) == "unlisted"
62 test "it allows a new post" do
63 Config.put([:mrf_object_age, :actions], [:delist])
66 File.read!("test/fixtures/mastodon-post-activity.json")
68 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
70 {:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
72 {:ok, ^data} = ObjectAgePolicy.filter(data)
76 describe "with strip_followers action" do
77 test "it strips followers collections from an old post" do
78 Config.put([:mrf_object_age, :actions], [:strip_followers])
81 File.read!("test/fixtures/mastodon-post-activity.json")
84 {:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
86 {:ok, data} = ObjectAgePolicy.filter(data)
88 refute user.follower_address in data["to"]
89 refute user.follower_address in data["cc"]
92 test "it allows a new post" do
93 Config.put([:mrf_object_age, :actions], [:strip_followers])
96 File.read!("test/fixtures/mastodon-post-activity.json")
98 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
100 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
102 {:ok, ^data} = ObjectAgePolicy.filter(data)