summaryrefslogtreecommitdiff
path: root/test/web/activity_pub/mrf/vocabulary_policy_test.exs
blob: c3b11d7a14543dd4b03fdcbbd43790a25a101e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 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
    test "it accepts based on parent activity type" do
      config = Pleroma.Config.get([:mrf_vocabulary, :accept])
      Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])

      message = %{
        "type" => "Like",
        "object" => "whatever"
      }

      {:ok, ^message} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :accept], config)
    end

    test "it accepts based on child object type" do
      config = Pleroma.Config.get([:mrf_vocabulary, :accept])
      Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])

      message = %{
        "type" => "Create",
        "object" => %{
          "type" => "Note",
          "content" => "whatever"
        }
      }

      {:ok, ^message} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :accept], config)
    end

    test "it does not accept disallowed child objects" do
      config = Pleroma.Config.get([:mrf_vocabulary, :accept])
      Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])

      message = %{
        "type" => "Create",
        "object" => %{
          "type" => "Article",
          "content" => "whatever"
        }
      }

      {:reject, nil} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :accept], config)
    end

    test "it does not accept disallowed parent types" do
      config = Pleroma.Config.get([:mrf_vocabulary, :accept])
      Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])

      message = %{
        "type" => "Create",
        "object" => %{
          "type" => "Note",
          "content" => "whatever"
        }
      }

      {:reject, nil} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :accept], config)
    end
  end

  describe "reject" do
    test "it rejects based on parent activity type" do
      config = Pleroma.Config.get([:mrf_vocabulary, :reject])
      Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])

      message = %{
        "type" => "Like",
        "object" => "whatever"
      }

      {:reject, nil} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :reject], config)
    end

    test "it rejects based on child object type" do
      config = Pleroma.Config.get([:mrf_vocabulary, :reject])
      Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])

      message = %{
        "type" => "Create",
        "object" => %{
          "type" => "Note",
          "content" => "whatever"
        }
      }

      {:reject, nil} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :reject], config)
    end

    test "it passes through objects that aren't disallowed" do
      config = Pleroma.Config.get([:mrf_vocabulary, :reject])
      Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])

      message = %{
        "type" => "Announce",
        "object" => "whatever"
      }

      {:ok, ^message} = VocabularyPolicy.filter(message)

      Pleroma.Config.put([:mrf_vocabulary, :reject], config)
    end
  end
end