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,
14 actions: [:delist, :strip_followers]
18 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
22 describe "with reject action" do
23 test "it rejects an old post" do
24 Config.put([:mrf_object_age, :actions], [:reject])
27 File.read!("test/fixtures/mastodon-post-activity.json")
30 {:reject, _} = ObjectAgePolicy.filter(data)
33 test "it allows a new post" do
34 Config.put([:mrf_object_age, :actions], [:reject])
37 File.read!("test/fixtures/mastodon-post-activity.json")
39 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
41 {:ok, _} = ObjectAgePolicy.filter(data)
45 describe "with delist action" do
46 test "it delists an old post" do
47 Config.put([:mrf_object_age, :actions], [:delist])
50 File.read!("test/fixtures/mastodon-post-activity.json")
53 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
55 {:ok, data} = ObjectAgePolicy.filter(data)
57 assert Visibility.get_visibility(%{data: data}) == "unlisted"
60 test "it allows a new post" do
61 Config.put([:mrf_object_age, :actions], [:delist])
64 File.read!("test/fixtures/mastodon-post-activity.json")
66 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
68 {:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
70 {:ok, ^data} = ObjectAgePolicy.filter(data)
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])
79 File.read!("test/fixtures/mastodon-post-activity.json")
82 {:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
84 {:ok, data} = ObjectAgePolicy.filter(data)
86 refute user.follower_address in data["to"]
87 refute user.follower_address in data["cc"]
90 test "it allows a new post" do
91 Config.put([:mrf_object_age, :actions], [:strip_followers])
94 File.read!("test/fixtures/mastodon-post-activity.json")
96 |> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
98 {:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
100 {:ok, ^data} = ObjectAgePolicy.filter(data)