X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fmrf_test.exs;h=f04c69afb693299d41bdaafd35e314d0ac4c1f98;hb=ec1d903f2ee1a65ae539c3258b4406e81ca73055;hp=e8cdde2e1f82a91c7f7bb6b8ed053b838da44f86;hpb=409f694e4f90d34285b43c7e7afc594bc386d893;p=akkoma
diff --git a/test/pleroma/web/activity_pub/mrf_test.exs b/test/pleroma/web/activity_pub/mrf_test.exs
index e8cdde2e1..f04c69afb 100644
--- a/test/pleroma/web/activity_pub/mrf_test.exs
+++ b/test/pleroma/web/activity_pub/mrf_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRFTest do
@@ -9,8 +9,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "subdomains_regex/1" do
assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
- ~r/^unsafe.tld$/i,
- ~r/^(.*\.)*unsafe.tld$/i
+ ~r/^(.+\.)?unsafe\.tld$/i,
+ ~r/^(.+\.)?unsafe\.tld$/i
]
end
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "common domains" do
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
- assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
+ assert regexes == [~r/^(.+\.)?unsafe\.tld$/i, ~r/^(.+\.)?unsafe2\.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
@@ -27,9 +27,9 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
test "wildcard domains with one subdomain" do
- regexes = MRF.subdomains_regex(["*.unsafe.tld"])
+ regexes = MRF.subdomains_regex(["unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
+ assert regexes == [~r/^(.+\.)?unsafe\.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
@@ -38,9 +38,9 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
test "wildcard domains with two subdomains" do
- regexes = MRF.subdomains_regex(["*.unsafe.tld"])
+ regexes = MRF.subdomains_regex(["unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
+ assert regexes == [~r/^(.+\.)?unsafe\.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
@@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
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 regexes == [~r/^(.+\.)?UnSafe\.TLD$/i, ~r/^(.+\.)?UnSAFE2\.Tld$/i]
assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
@@ -63,12 +63,26 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
end
+ describe "instance_list_from_tuples/1" do
+ test "returns a list of instances from a list of {instance, reason} tuples" do
+ list = [{"some.tld", "a reason"}, {"other.tld", "another reason"}]
+ expected = ["some.tld", "other.tld"]
+
+ assert MRF.instance_list_from_tuples(list) == expected
+ end
+ end
+
describe "describe/0" do
test "it works as expected with noop policy" do
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
expected = %{
- mrf_policies: ["NoOpPolicy"],
+ mrf_policies: ["NoOpPolicy", "HashtagPolicy", "InlineQuotePolicy"],
+ mrf_hashtag: %{
+ federated_timeline_removal: [],
+ reject: [],
+ sensitive: ["nsfw"]
+ },
exclusions: false
}
@@ -79,12 +93,33 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
clear_config([:mrf, :policies], [MRFModuleMock])
expected = %{
- mrf_policies: ["MRFModuleMock"],
+ mrf_policies: ["MRFModuleMock", "HashtagPolicy", "InlineQuotePolicy"],
mrf_module_mock: "some config data",
+ mrf_hashtag: %{
+ federated_timeline_removal: [],
+ reject: [],
+ sensitive: ["nsfw"]
+ },
exclusions: false
}
{:ok, ^expected} = MRF.describe()
end
end
+
+ test "config_descriptions/0" do
+ descriptions = MRF.config_descriptions()
+
+ good_mrf = Enum.find(descriptions, fn %{key: key} -> key == :good_mrf end)
+
+ assert good_mrf == %{
+ key: :good_mrf,
+ related_policy: "Fixtures.Modules.GoodMRF",
+ label: "Good MRF",
+ description: "Some description",
+ group: :pleroma,
+ tab: :mrf,
+ type: :group
+ }
+ end
end