summaryrefslogtreecommitdiff
path: root/test/web/activity_pub/mrf
diff options
context:
space:
mode:
authorMaxim Filippov <colixer@gmail.com>2019-08-14 22:45:32 +0000
committerMaxim Filippov <colixer@gmail.com>2019-08-14 22:45:32 +0000
commitec969eec5149c5fe2a3e676ea07384b4597487f1 (patch)
treeb725022b93c7f354116e50d54009e0dc5dc19eaf /test/web/activity_pub/mrf
parentb27fafe161241c954b713281bebd6ffe1e990884 (diff)
parent27b747546a7796de57e88f454b2c2810c7523f97 (diff)
downloadpleroma-ec969eec5149c5fe2a3e676ea07384b4597487f1.tar.gz
pleroma-ec969eec5149c5fe2a3e676ea07384b4597487f1.zip
Merge branch 'develop' into 'fix/admin-api-user-deletion'
# Conflicts: # CHANGELOG.md
Diffstat (limited to 'test/web/activity_pub/mrf')
-rw-r--r--test/web/activity_pub/mrf/mrf_test.exs50
-rw-r--r--test/web/activity_pub/mrf/vocabulary_policy_test.exs123
2 files changed, 168 insertions, 5 deletions
diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs
index a9cdf5317..19e172939 100644
--- a/test/web/activity_pub/mrf/mrf_test.exs
+++ b/test/web/activity_pub/mrf/mrf_test.exs
@@ -4,8 +4,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "subdomains_regex/1" do
assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
- ~r/^unsafe.tld$/,
- ~r/^(.*\.)*unsafe.tld$/
+ ~r/^unsafe.tld$/i,
+ ~r/^(.*\.)*unsafe.tld$/i
]
end
@@ -13,7 +13,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "common domains" do
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
- assert regexes == [~r/^unsafe.tld$/, ~r/^unsafe2.tld$/]
+ assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "wildcard domains with one subdomain" do
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/]
+ assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
@@ -35,12 +35,52 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "wildcard domains with two subdomains" do
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/]
+ assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
refute MRF.subdomain_match?(regexes, "sub.anotherunsafe.tld")
refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
end
+
+ test "matches are case-insensitive" do
+ regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
+
+ assert regexes == [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i]
+
+ assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
+ assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
+ assert MRF.subdomain_match?(regexes, "unsafe.tld")
+ assert MRF.subdomain_match?(regexes, "unsafe2.tld")
+
+ refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
+ refute MRF.subdomain_match?(regexes, "example.com")
+ end
+ end
+
+ describe "describe/0" do
+ test "it works as expected with noop policy" do
+ expected = %{
+ mrf_policies: ["NoOpPolicy"],
+ exclusions: false
+ }
+
+ {:ok, ^expected} = MRF.describe()
+ end
+
+ test "it works as expected with mock policy" do
+ config = Pleroma.Config.get([:instance, :rewrite_policy])
+ Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
+
+ expected = %{
+ mrf_policies: ["MRFModuleMock"],
+ mrf_module_mock: "some config data",
+ exclusions: false
+ }
+
+ {:ok, ^expected} = MRF.describe()
+
+ Pleroma.Config.put([:instance, :rewrite_policy], config)
+ end
end
end
diff --git a/test/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
new file mode 100644
index 000000000..c3b11d7a1
--- /dev/null
+++ b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -0,0 +1,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