Fix ObjectAgePolicyTest
The policy didn't block old posts as it should. * I fixed it and tested on a test server * I added the settings to description so that this information is shown in nodeinfo * TODO: I didn't work TTD and still need to fix the tests
This commit is contained in:
parent
918a8094fc
commit
8b4de61d64
@ -28,8 +28,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
### Fixed
|
### Fixed
|
||||||
- Logger configuration through AdminFE
|
- Logger configuration through AdminFE
|
||||||
- HTTP Basic Authentication permissions issue
|
- HTTP Basic Authentication permissions issue
|
||||||
|
- ObjectAgePolicy didn't filter out old messages
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- NodeInfo: ObjectAgePolicy settings to the `federation` list.
|
||||||
<details>
|
<details>
|
||||||
<summary>API Changes</summary>
|
<summary>API Changes</summary>
|
||||||
- Admin API: `GET /api/pleroma/admin/need_reboot`.
|
- Admin API: `GET /api/pleroma/admin/need_reboot`.
|
||||||
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
|
|||||||
@moduledoc "Filter activities depending on their age"
|
@moduledoc "Filter activities depending on their age"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
defp check_date(%{"published" => published} = message) do
|
defp check_date(%{"object" => %{"published" => published}} = message) do
|
||||||
with %DateTime{} = now <- DateTime.utc_now(),
|
with %DateTime{} = now <- DateTime.utc_now(),
|
||||||
{:ok, %DateTime{} = then, _} <- DateTime.from_iso8601(published),
|
{:ok, %DateTime{} = then, _} <- DateTime.from_iso8601(published),
|
||||||
max_ttl <- Config.get([:mrf_object_age, :threshold]),
|
max_ttl <- Config.get([:mrf_object_age, :threshold]),
|
||||||
@ -96,5 +96,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
|
|||||||
def filter(message), do: {:ok, message}
|
def filter(message), do: {:ok, message}
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def describe, do: {:ok, %{}}
|
def describe do
|
||||||
|
mrf_object_age =
|
||||||
|
Pleroma.Config.get(:mrf_object_age)
|
||||||
|
|> Enum.into(%{})
|
||||||
|
|
||||||
|
{:ok, %{mrf_object_age: mrf_object_age}}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,26 +20,38 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_old_message do
|
||||||
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_new_message do
|
||||||
|
old_message = get_old_message()
|
||||||
|
|
||||||
|
new_object =
|
||||||
|
old_message
|
||||||
|
|> Map.get("object")
|
||||||
|
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
||||||
|
|
||||||
|
old_message
|
||||||
|
|> Map.put("object", new_object)
|
||||||
|
end
|
||||||
|
|
||||||
describe "with reject action" do
|
describe "with reject action" do
|
||||||
test "it rejects an old post" do
|
test "it rejects an old post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:reject])
|
Config.put([:mrf_object_age, :actions], [:reject])
|
||||||
|
|
||||||
data =
|
data = get_old_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|
|
||||||
{:reject, _} = ObjectAgePolicy.filter(data)
|
assert match?({:reject, _}, ObjectAgePolicy.filter(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it allows a new post" do
|
test "it allows a new post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:reject])
|
Config.put([:mrf_object_age, :actions], [:reject])
|
||||||
|
|
||||||
data =
|
data = get_new_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
|
||||||
|
|
||||||
{:ok, _} = ObjectAgePolicy.filter(data)
|
assert match?({:ok, _}, ObjectAgePolicy.filter(data))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,9 +59,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||||||
test "it delists an old post" do
|
test "it delists an old post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:delist])
|
Config.put([:mrf_object_age, :actions], [:delist])
|
||||||
|
|
||||||
data =
|
data = get_old_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|
|
||||||
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||||
|
|
||||||
@ -61,14 +71,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||||||
test "it allows a new post" do
|
test "it allows a new post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:delist])
|
Config.put([:mrf_object_age, :actions], [:delist])
|
||||||
|
|
||||||
data =
|
data = get_new_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
|
||||||
|
|
||||||
{:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
|
{:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||||
|
|
||||||
{:ok, ^data} = ObjectAgePolicy.filter(data)
|
assert match?({:ok, ^data}, ObjectAgePolicy.filter(data))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,9 +83,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||||||
test "it strips followers collections from an old post" do
|
test "it strips followers collections from an old post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||||
|
|
||||||
data =
|
data = get_old_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|
|
||||||
{:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
|
{:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||||
|
|
||||||
@ -91,14 +96,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||||||
test "it allows a new post" do
|
test "it allows a new post" do
|
||||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||||
|
|
||||||
data =
|
data = get_new_message()
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
||||||
|> Poison.decode!()
|
|
||||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
|
||||||
|
|
||||||
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||||
|
|
||||||
{:ok, ^data} = ObjectAgePolicy.filter(data)
|
assert match?({:ok, ^data}, ObjectAgePolicy.filter(data))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user