First
[anni] / test / pleroma / web / activity_pub / mrf / user_allow_list_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
5   use Pleroma.DataCase
6   import Pleroma.Factory
7
8   alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
9
10   setup do: clear_config(:mrf_user_allowlist)
11
12   test "pass filter if allow list is empty" do
13     actor = insert(:user)
14     message = %{"actor" => actor.ap_id}
15     assert UserAllowListPolicy.filter(message) == {:ok, message}
16   end
17
18   test "pass filter if allow list isn't empty and user in allow list" do
19     actor = insert(:user)
20     clear_config([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
21     message = %{"actor" => actor.ap_id}
22     assert UserAllowListPolicy.filter(message) == {:ok, message}
23   end
24
25   test "rejected if allow list isn't empty and user not in allow list" do
26     actor = insert(:user)
27     clear_config([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
28     message = %{"actor" => actor.ap_id}
29     assert {:reject, _} = UserAllowListPolicy.filter(message)
30   end
31 end