c3b11d7a14543dd4b03fdcbbd43790a25a101e7d
[akkoma] / test / web / activity_pub / mrf / vocabulary_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
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 test "it accepts based on parent activity type" do
12 config = Pleroma.Config.get([:mrf_vocabulary, :accept])
13 Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
14
15 message = %{
16 "type" => "Like",
17 "object" => "whatever"
18 }
19
20 {:ok, ^message} = VocabularyPolicy.filter(message)
21
22 Pleroma.Config.put([:mrf_vocabulary, :accept], config)
23 end
24
25 test "it accepts based on child object type" do
26 config = Pleroma.Config.get([:mrf_vocabulary, :accept])
27 Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
28
29 message = %{
30 "type" => "Create",
31 "object" => %{
32 "type" => "Note",
33 "content" => "whatever"
34 }
35 }
36
37 {:ok, ^message} = VocabularyPolicy.filter(message)
38
39 Pleroma.Config.put([:mrf_vocabulary, :accept], config)
40 end
41
42 test "it does not accept disallowed child objects" do
43 config = Pleroma.Config.get([:mrf_vocabulary, :accept])
44 Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
45
46 message = %{
47 "type" => "Create",
48 "object" => %{
49 "type" => "Article",
50 "content" => "whatever"
51 }
52 }
53
54 {:reject, nil} = VocabularyPolicy.filter(message)
55
56 Pleroma.Config.put([:mrf_vocabulary, :accept], config)
57 end
58
59 test "it does not accept disallowed parent types" do
60 config = Pleroma.Config.get([:mrf_vocabulary, :accept])
61 Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
62
63 message = %{
64 "type" => "Create",
65 "object" => %{
66 "type" => "Note",
67 "content" => "whatever"
68 }
69 }
70
71 {:reject, nil} = VocabularyPolicy.filter(message)
72
73 Pleroma.Config.put([:mrf_vocabulary, :accept], config)
74 end
75 end
76
77 describe "reject" do
78 test "it rejects based on parent activity type" do
79 config = Pleroma.Config.get([:mrf_vocabulary, :reject])
80 Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
81
82 message = %{
83 "type" => "Like",
84 "object" => "whatever"
85 }
86
87 {:reject, nil} = VocabularyPolicy.filter(message)
88
89 Pleroma.Config.put([:mrf_vocabulary, :reject], config)
90 end
91
92 test "it rejects based on child object type" do
93 config = Pleroma.Config.get([:mrf_vocabulary, :reject])
94 Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
95
96 message = %{
97 "type" => "Create",
98 "object" => %{
99 "type" => "Note",
100 "content" => "whatever"
101 }
102 }
103
104 {:reject, nil} = VocabularyPolicy.filter(message)
105
106 Pleroma.Config.put([:mrf_vocabulary, :reject], config)
107 end
108
109 test "it passes through objects that aren't disallowed" do
110 config = Pleroma.Config.get([:mrf_vocabulary, :reject])
111 Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
112
113 message = %{
114 "type" => "Announce",
115 "object" => "whatever"
116 }
117
118 {:ok, ^message} = VocabularyPolicy.filter(message)
119
120 Pleroma.Config.put([:mrf_vocabulary, :reject], config)
121 end
122 end
123 end