summaryrefslogtreecommitdiff
path: root/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs')
-rw-r--r--test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
new file mode 100644
index 000000000..2bceb67ee
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -0,0 +1,106 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
+
+ describe "accept" do
+ setup do: clear_config([:mrf_vocabulary, :accept])
+
+ test "it accepts based on parent activity type" do
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
+
+ message = %{
+ "type" => "Like",
+ "object" => "whatever"
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+ end
+
+ test "it accepts based on child object type" do
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+ end
+
+ test "it does not accept disallowed child objects" do
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Article",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, _} = VocabularyPolicy.filter(message)
+ end
+
+ test "it does not accept disallowed parent types" do
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, _} = VocabularyPolicy.filter(message)
+ end
+ end
+
+ describe "reject" do
+ setup do: clear_config([:mrf_vocabulary, :reject])
+
+ test "it rejects based on parent activity type" do
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+
+ message = %{
+ "type" => "Like",
+ "object" => "whatever"
+ }
+
+ {:reject, _} = VocabularyPolicy.filter(message)
+ end
+
+ test "it rejects based on child object type" do
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, _} = VocabularyPolicy.filter(message)
+ end
+
+ test "it passes through objects that aren't disallowed" do
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+
+ message = %{
+ "type" => "Announce",
+ "object" => "whatever"
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+ end
+ end
+end