1 defmodule Pleroma.Web.ActivityPub.MRFTest do
2 use ExUnit.Case, async: true
3 use Pleroma.Tests.Helpers
4 alias Pleroma.Web.ActivityPub.MRF
6 test "subdomains_regex/1" do
7 assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
9 ~r/^(.*\.)*unsafe.tld$/i
13 describe "subdomain_match/2" do
14 test "common domains" do
15 regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
17 assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
19 assert MRF.subdomain_match?(regexes, "unsafe.tld")
20 assert MRF.subdomain_match?(regexes, "unsafe2.tld")
22 refute MRF.subdomain_match?(regexes, "example.com")
25 test "wildcard domains with one subdomain" do
26 regexes = MRF.subdomains_regex(["*.unsafe.tld"])
28 assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
30 assert MRF.subdomain_match?(regexes, "unsafe.tld")
31 assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
32 refute MRF.subdomain_match?(regexes, "anotherunsafe.tld")
33 refute MRF.subdomain_match?(regexes, "unsafe.tldanother")
36 test "wildcard domains with two subdomains" do
37 regexes = MRF.subdomains_regex(["*.unsafe.tld"])
39 assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
41 assert MRF.subdomain_match?(regexes, "unsafe.tld")
42 assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
43 refute MRF.subdomain_match?(regexes, "sub.anotherunsafe.tld")
44 refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
47 test "matches are case-insensitive" do
48 regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
50 assert regexes == [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i]
52 assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
53 assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
54 assert MRF.subdomain_match?(regexes, "unsafe.tld")
55 assert MRF.subdomain_match?(regexes, "unsafe2.tld")
57 refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
58 refute MRF.subdomain_match?(regexes, "example.com")
62 describe "describe/0" do
63 test "it works as expected with noop policy" do
65 mrf_policies: ["NoOpPolicy"],
69 {:ok, ^expected} = MRF.describe()
72 test "it works as expected with mock policy" do
73 clear_config([:mrf, :policies], [MRFModuleMock])
76 mrf_policies: ["MRFModuleMock"],
77 mrf_module_mock: "some config data",
81 {:ok, ^expected} = MRF.describe()