merge develop
[akkoma] / test / web / activity_pub / mrf / user_allowlist_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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
11 policy = Pleroma.Config.get([:mrf_user_allowlist]) || []
12 on_exit(fn -> Pleroma.Config.put([:mrf_user_allowlist], policy) end)
13
14 :ok
15 end
16
17 test "pass filter if allow list is empty" do
18 actor = insert(:user)
19 message = %{"actor" => actor.ap_id}
20 assert UserAllowListPolicy.filter(message) == {:ok, message}
21 end
22
23 test "pass filter if allow list isn't empty and user in allow list" do
24 actor = insert(:user)
25 Pleroma.Config.put([:mrf_user_allowlist, :localhost], [actor.ap_id, "test-ap-id"])
26 message = %{"actor" => actor.ap_id}
27 assert UserAllowListPolicy.filter(message) == {:ok, message}
28 end
29
30 test "rejected if allow list isn't empty and user not in allow list" do
31 actor = insert(:user)
32 Pleroma.Config.put([:mrf_user_allowlist, :localhost], ["test-ap-id"])
33 message = %{"actor" => actor.ap_id}
34 assert UserAllowListPolicy.filter(message) == {:reject, nil}
35 end
36 end