logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

activity_expiration_policy_test.exs (2928B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
  5. use ExUnit.Case, async: true
  6. alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
  7. @id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
  8. @local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
  9. test "adds `expires_at` property" do
  10. assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
  11. ActivityExpirationPolicy.filter(%{
  12. "id" => @id,
  13. "actor" => @local_actor,
  14. "type" => "Create",
  15. "object" => %{"type" => "Note"}
  16. })
  17. assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
  18. end
  19. test "keeps existing `expires_at` if it less than the config setting" do
  20. expires_at = DateTime.utc_now() |> Timex.shift(days: 1)
  21. assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
  22. ActivityExpirationPolicy.filter(%{
  23. "id" => @id,
  24. "actor" => @local_actor,
  25. "type" => "Create",
  26. "expires_at" => expires_at,
  27. "object" => %{"type" => "Note"}
  28. })
  29. end
  30. test "overwrites existing `expires_at` if it greater than the config setting" do
  31. too_distant_future = DateTime.utc_now() |> Timex.shift(years: 2)
  32. assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
  33. ActivityExpirationPolicy.filter(%{
  34. "id" => @id,
  35. "actor" => @local_actor,
  36. "type" => "Create",
  37. "expires_at" => too_distant_future,
  38. "object" => %{"type" => "Note"}
  39. })
  40. assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
  41. end
  42. test "ignores remote activities" do
  43. assert {:ok, activity} =
  44. ActivityExpirationPolicy.filter(%{
  45. "id" => "https://example.com/123",
  46. "actor" => "https://example.com/users/cofe",
  47. "type" => "Create",
  48. "object" => %{"type" => "Note"}
  49. })
  50. refute Map.has_key?(activity, "expires_at")
  51. end
  52. test "ignores non-Create/Note activities" do
  53. assert {:ok, activity} =
  54. ActivityExpirationPolicy.filter(%{
  55. "id" => "https://example.com/123",
  56. "actor" => "https://example.com/users/cofe",
  57. "type" => "Follow"
  58. })
  59. refute Map.has_key?(activity, "expires_at")
  60. assert {:ok, activity} =
  61. ActivityExpirationPolicy.filter(%{
  62. "id" => "https://example.com/123",
  63. "actor" => "https://example.com/users/cofe",
  64. "type" => "Create",
  65. "object" => %{"type" => "Cofe"}
  66. })
  67. refute Map.has_key?(activity, "expires_at")
  68. end
  69. end