Fix MRF policies to also work with Update
[akkoma] / test / pleroma / web / activity_pub / mrf / vocabulary_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
9
10 describe "accept" do
11 setup do: clear_config([:mrf_vocabulary, :accept])
12
13 test "it accepts based on parent activity type" do
14 clear_config([:mrf_vocabulary, :accept], ["Like"])
15
16 message = %{
17 "type" => "Like",
18 "object" => "whatever"
19 }
20
21 {:ok, ^message} = VocabularyPolicy.filter(message)
22 end
23
24 test "it accepts based on child object type" do
25 clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
26
27 message = %{
28 "type" => "Create",
29 "object" => %{
30 "type" => "Note",
31 "content" => "whatever"
32 }
33 }
34
35 {:ok, ^message} = VocabularyPolicy.filter(message)
36 end
37
38 test "it does not accept disallowed child objects" do
39 clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
40
41 message = %{
42 "type" => "Create",
43 "object" => %{
44 "type" => "Article",
45 "content" => "whatever"
46 }
47 }
48
49 {:reject, _} = VocabularyPolicy.filter(message)
50 end
51
52 test "it does not accept disallowed parent types" do
53 clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
54
55 message = %{
56 "type" => "Create",
57 "object" => %{
58 "type" => "Note",
59 "content" => "whatever"
60 }
61 }
62
63 {:reject, _} = VocabularyPolicy.filter(message)
64 end
65 end
66
67 describe "reject" do
68 setup do: clear_config([:mrf_vocabulary, :reject])
69
70 test "it rejects based on parent activity type" do
71 clear_config([:mrf_vocabulary, :reject], ["Like"])
72
73 message = %{
74 "type" => "Like",
75 "object" => "whatever"
76 }
77
78 {:reject, _} = VocabularyPolicy.filter(message)
79 end
80
81 test "it rejects based on child object type" do
82 clear_config([:mrf_vocabulary, :reject], ["Note"])
83
84 message = %{
85 "type" => "Create",
86 "object" => %{
87 "type" => "Note",
88 "content" => "whatever"
89 }
90 }
91
92 {:reject, _} = VocabularyPolicy.filter(message)
93 end
94
95 test "it passes through objects that aren't disallowed" do
96 clear_config([:mrf_vocabulary, :reject], ["Like"])
97
98 message = %{
99 "type" => "Announce",
100 "object" => "whatever"
101 }
102
103 {:ok, ^message} = VocabularyPolicy.filter(message)
104 end
105 end
106 end