forked from AkkomaGang/akkoma
1f863f0a36
Objects who got updated would just pass through several of the MRF policies, undoing moderation in some situations. In the relevant cases we now check not only for Create activities, but also Update activities. I checked which ones checked explicitly on type Create using `grep '"type" => "Create"' lib/pleroma/web/activity_pub/mrf/*`. The following from that list have not been changed: * lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex * Not relevant for moderation * lib/pleroma/web/activity_pub/mrf/keyword_policy.ex * Already had a test for Update * lib/pleroma/web/activity_pub/mrf/object_age_policy.ex * In practice only relevant when fetching old objects (e.g. through Like or Announce). These are always wrapped in a Create. * lib/pleroma/web/activity_pub/mrf/reject_non_public.ex * We don't allow changing scope with Update, so not relevant here
125 lines
4.3 KiB
Elixir
125 lines
4.3 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|
use ExUnit.Case, async: true
|
|
alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
|
|
|
|
@id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
|
|
@local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
|
|
|
|
test "adds `expires_at` property" do
|
|
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Create",
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
|
|
|
assert {:ok, %{"type" => "Update", "expires_at" => expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Update",
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
|
end
|
|
|
|
test "keeps existing `expires_at` if it less than the config setting" do
|
|
expires_at = DateTime.utc_now() |> Timex.shift(days: 1)
|
|
|
|
assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Create",
|
|
"expires_at" => expires_at,
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
assert {:ok, %{"type" => "Update", "expires_at" => ^expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Update",
|
|
"expires_at" => expires_at,
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
end
|
|
|
|
test "overwrites existing `expires_at` if it greater than the config setting" do
|
|
too_distant_future = DateTime.utc_now() |> Timex.shift(years: 2)
|
|
|
|
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Create",
|
|
"expires_at" => too_distant_future,
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
|
|
|
assert {:ok, %{"type" => "Update", "expires_at" => expires_at}} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => @id,
|
|
"actor" => @local_actor,
|
|
"type" => "Update",
|
|
"expires_at" => too_distant_future,
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
|
end
|
|
|
|
test "ignores remote activities" do
|
|
assert {:ok, activity} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => "https://example.com/123",
|
|
"actor" => "https://example.com/users/cofe",
|
|
"type" => "Create",
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
|
|
|
assert {:ok, activity} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => "https://example.com/123",
|
|
"actor" => "https://example.com/users/cofe",
|
|
"type" => "Update",
|
|
"object" => %{"type" => "Note"}
|
|
})
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
|
end
|
|
|
|
test "ignores non-Create/Update/Note activities" do
|
|
assert {:ok, activity} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => "https://example.com/123",
|
|
"actor" => "https://example.com/users/cofe",
|
|
"type" => "Follow"
|
|
})
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
|
|
|
assert {:ok, activity} =
|
|
ActivityExpirationPolicy.filter(%{
|
|
"id" => "https://example.com/123",
|
|
"actor" => "https://example.com/users/cofe",
|
|
"type" => "Create",
|
|
"object" => %{"type" => "Cofe"}
|
|
})
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
|
end
|
|
end
|