2020-02-11 09:53:24 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 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"
|
2020-08-04 14:26:37 +00:00
|
|
|
@local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
|
2020-02-11 09:53:24 +00:00
|
|
|
|
|
|
|
test "adds `expires_at` property" do
|
2020-02-20 18:04:02 +00:00
|
|
|
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
2020-06-08 13:56:34 +00:00
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => @id,
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => @local_actor,
|
2020-06-08 13:56:34 +00:00
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{"type" => "Note"}
|
|
|
|
})
|
2020-02-11 09:53:24 +00:00
|
|
|
|
2020-08-22 17:46:01 +00:00
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
2020-02-11 09:53:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "keeps existing `expires_at` if it less than the config setting" do
|
2020-08-22 17:46:01 +00:00
|
|
|
expires_at = DateTime.utc_now() |> Timex.shift(days: 1)
|
2020-02-11 09:53:24 +00:00
|
|
|
|
2020-02-20 18:04:02 +00:00
|
|
|
assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
|
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => @id,
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => @local_actor,
|
2020-02-20 18:04:02 +00:00
|
|
|
"type" => "Create",
|
2020-06-08 13:56:34 +00:00
|
|
|
"expires_at" => expires_at,
|
|
|
|
"object" => %{"type" => "Note"}
|
2020-02-20 18:04:02 +00:00
|
|
|
})
|
2020-02-11 09:53:24 +00:00
|
|
|
end
|
|
|
|
|
2020-02-14 11:19:23 +00:00
|
|
|
test "overwrites existing `expires_at` if it greater than the config setting" do
|
2020-08-22 17:46:01 +00:00
|
|
|
too_distant_future = DateTime.utc_now() |> Timex.shift(years: 2)
|
2020-02-11 09:53:24 +00:00
|
|
|
|
2020-02-20 18:04:02 +00:00
|
|
|
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => @id,
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => @local_actor,
|
2020-02-20 18:04:02 +00:00
|
|
|
"type" => "Create",
|
2020-06-08 13:56:34 +00:00
|
|
|
"expires_at" => too_distant_future,
|
|
|
|
"object" => %{"type" => "Note"}
|
2020-02-20 18:04:02 +00:00
|
|
|
})
|
2020-02-11 09:53:24 +00:00
|
|
|
|
2020-08-22 17:46:01 +00:00
|
|
|
assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
|
2020-02-11 09:53:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "ignores remote activities" do
|
2020-02-20 18:04:02 +00:00
|
|
|
assert {:ok, activity} =
|
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => "https://example.com/123",
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => "https://example.com/users/cofe",
|
2020-06-08 13:56:34 +00:00
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{"type" => "Note"}
|
2020-02-20 18:04:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
|
|
|
end
|
|
|
|
|
2020-06-08 13:56:34 +00:00
|
|
|
test "ignores non-Create/Note activities" do
|
2020-02-20 18:04:02 +00:00
|
|
|
assert {:ok, activity} =
|
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => "https://example.com/123",
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => "https://example.com/users/cofe",
|
2020-02-20 18:04:02 +00:00
|
|
|
"type" => "Follow"
|
|
|
|
})
|
2020-02-11 09:53:24 +00:00
|
|
|
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
2020-06-08 13:56:34 +00:00
|
|
|
|
|
|
|
assert {:ok, activity} =
|
|
|
|
ActivityExpirationPolicy.filter(%{
|
|
|
|
"id" => "https://example.com/123",
|
2020-08-04 14:26:37 +00:00
|
|
|
"actor" => "https://example.com/users/cofe",
|
2020-06-08 13:56:34 +00:00
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{"type" => "Cofe"}
|
|
|
|
})
|
|
|
|
|
|
|
|
refute Map.has_key?(activity, "expires_at")
|
2020-02-11 09:53:24 +00:00
|
|
|
end
|
|
|
|
end
|