end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :media_removal], [{"*.remote.instance", "Whatever reason"}])
- media_message = build_media_message()
+ clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Whatever reason"}])
+ media_message = build_media_message("sub.remote.instance")
local_message = build_local_message()
assert SimplePolicy.filter(media_message) ==
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :media_nsfw], [{"*.remote.instance", "yeah yeah"}])
- media_message = build_media_message()
+ clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "yeah yeah"}])
+ media_message = build_media_message("sub.remote.instance")
local_message = build_local_message()
assert SimplePolicy.filter(media_message) ==
end
end
- defp build_media_message do
+ defp build_media_message(domain \\ "remote.instance") do
%{
- "actor" => "https://remote.instance/users/bob",
+ "actor" => "https://#{domain}/users/bob",
"type" => "Create",
"object" => %{
"attachment" => [%{}],
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :report_removal], [{"*.remote.instance", "suya"}])
- report_message = build_report_message()
+ clear_config([:mrf_simple, :report_removal], [{"remote.instance", "suya"}])
+ report_message = build_report_message("sub.remote.instance")
local_message = build_local_message()
assert {:reject, _} = SimplePolicy.filter(report_message)
end
end
- defp build_report_message do
+ defp build_report_message(domain \\ "remote.instance") do
%{
- "actor" => "https://remote.instance/users/bob",
+ "actor" => "https://#{domain}/users/bob",
"type" => "Flag"
}
end
describe "when :federated_timeline_removal" do
test "is empty" do
clear_config([:mrf_simple, :federated_timeline_removal], [])
- {_, ftl_message} = build_ftl_actor_and_message()
+ {_, ftl_message} = build_ftl_actor_and_message("https://remote.instance/users/bob")
local_message = build_local_message()
assert SimplePolicy.filter(ftl_message) == {:ok, ftl_message}
end
test "has a matching host" do
- {actor, ftl_message} = build_ftl_actor_and_message()
+ {actor, ftl_message} = build_ftl_actor_and_message("https://remote.instance/users/bob")
ftl_message_actor_host =
ftl_message
end
test "match with wildcard domain" do
- {actor, ftl_message} = build_ftl_actor_and_message()
+ {actor, ftl_message} = build_ftl_actor_and_message("https://sub.remote.instance/users/bob")
ftl_message_actor_host =
ftl_message
|> Map.fetch!(:host)
clear_config([:mrf_simple, :federated_timeline_removal], [
- {"*." <> ftl_message_actor_host, "owo"}
+ {ftl_message_actor_host, "owo"}
])
local_message = build_local_message()
end
test "has a matching host but only as:Public in to" do
- {_actor, ftl_message} = build_ftl_actor_and_message()
+ {_actor, ftl_message} = build_ftl_actor_and_message("https://remote.instance/users/bob")
ftl_message_actor_host =
ftl_message
end
end
- defp build_ftl_actor_and_message do
- actor = insert(:user)
+ defp build_ftl_actor_and_message(ap_id) do
+ actor = insert(:user, ap_id: ap_id)
{actor,
%{
end
test "activity matches with wildcard domain" do
- clear_config([:mrf_simple, :reject], [{"*.remote.instance", ""}])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
- remote_message = build_remote_message()
+ remote_message = build_remote_message("sub.remote.instance")
assert {:reject, _} = SimplePolicy.filter(remote_message)
end
describe "when :followers_only" do
test "is empty" do
clear_config([:mrf_simple, :followers_only], [])
- {_, ftl_message} = build_ftl_actor_and_message()
+ {_, ftl_message} = build_ftl_actor_and_message("https://remote.instance/users/alice")
local_message = build_local_message()
assert SimplePolicy.filter(ftl_message) == {:ok, ftl_message}
end
test "activity matches with wildcard domain" do
- clear_config([:mrf_simple, :accept], [{"*.remote.instance", ""}])
+ clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
local_message = build_local_message()
- remote_message = build_remote_message()
+ remote_message = build_remote_message("sub.remote.instance")
assert SimplePolicy.filter(local_message) == {:ok, local_message}
assert SimplePolicy.filter(remote_message) == {:ok, remote_message}
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :avatar_removal], [{"*.remote.instance", ""}])
+ clear_config([:mrf_simple, :avatar_removal], [{"remote.instance", ""}])
- remote_user = build_remote_user()
+ remote_user = build_remote_user("sub.remote.instance")
{:ok, filtered} = SimplePolicy.filter(remote_user)
refute filtered["icon"]
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :banner_removal], [{"*.remote.instance", ""}])
+ clear_config([:mrf_simple, :banner_removal], [{"remote.instance", ""}])
- remote_user = build_remote_user()
+ remote_user = build_remote_user("sub.remote.instance")
{:ok, filtered} = SimplePolicy.filter(remote_user)
refute filtered["image"]
end
describe "when :reject_deletes match with wildcard domain" do
- setup do: clear_config([:mrf_simple, :reject_deletes], [{"*.remote.instance", ""}])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [{"remote.instance", ""}])
test "it rejects the deletion" do
- deletion_message = build_remote_deletion_message()
+ deletion_message = build_remote_deletion_message("sub.remote.instance")
assert {:reject, _} = SimplePolicy.filter(deletion_message)
end
}
end
- defp build_remote_message do
- %{"actor" => "https://remote.instance/users/bob"}
+ defp build_remote_message(domain \\ "remote.instance") do
+ %{"actor" => "https://#{domain}/users/bob"}
end
- defp build_remote_user do
+ defp build_remote_user(domain \\ "remote.instance") do
%{
- "id" => "https://remote.instance/users/bob",
+ "id" => "https://#{domain}/users/bob",
"icon" => %{
"url" => "http://example.com/image.jpg",
"type" => "Image"
}
end
- defp build_remote_deletion_message do
+ defp build_remote_deletion_message(domain \\ "remote.instance") do
%{
"type" => "Delete",
- "actor" => "https://remote.instance/users/bob"
+ "actor" => "https://#{domain}/users/bob"
}
end
end
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
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")
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")
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")
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")