Make quarentine work with list of tuples instead of strings
This commit is contained in:
parent
dd947d9bc8
commit
27fe7b0274
5 changed files with 18 additions and 5 deletions
|
@ -100,6 +100,11 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
Enum.any?(domains, fn domain -> Regex.match?(domain, host) end)
|
Enum.any?(domains, fn domain -> Regex.match?(domain, host) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec instance_list_from_tuples([{String.t(), String.t()}]) :: [String.t()]
|
||||||
|
def instance_list_from_tuples(list) do
|
||||||
|
Enum.map(list, fn {instance, _} -> instance end)
|
||||||
|
end
|
||||||
|
|
||||||
def describe(policies) do
|
def describe(policies) do
|
||||||
{:ok, policy_configs} =
|
{:ok, policy_configs} =
|
||||||
policies
|
policies
|
||||||
|
|
|
@ -187,9 +187,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
|
|
||||||
defp instance_list(config_key) do
|
defp instance_list(config_key) do
|
||||||
Config.get([:mrf_simple, config_key])
|
Config.get([:mrf_simple, config_key])
|
||||||
|> Enum.map(fn
|
|> MRF.instance_list_from_tuples()
|
||||||
{instance, _} -> instance
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -112,6 +112,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||||
|
|
||||||
quarantined_instances =
|
quarantined_instances =
|
||||||
Config.get([:instance, :quarantined_instances], [])
|
Config.get([:instance, :quarantined_instances], [])
|
||||||
|
|> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples()
|
||||||
|> Pleroma.Web.ActivityPub.MRF.subdomains_regex()
|
|> Pleroma.Web.ActivityPub.MRF.subdomains_regex()
|
||||||
|
|
||||||
!Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host)
|
!Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host)
|
||||||
|
|
|
@ -63,6 +63,15 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
end
|
end
|
||||||
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
|
describe "describe/0" do
|
||||||
test "it works as expected with noop policy" do
|
test "it works as expected with noop policy" do
|
||||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
||||||
|
|
|
@ -271,7 +271,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Pleroma.Web.Federator.Publisher,
|
Pleroma.Web.Federator.Publisher,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
Config.put([:instance, :quarantined_instances], ["domain.com"])
|
Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}])
|
||||||
|
|
||||||
follower =
|
follower =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
|
@ -308,7 +308,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Pleroma.Web.Federator.Publisher,
|
Pleroma.Web.Federator.Publisher,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
Config.put([:instance, :quarantined_instances], ["somedomain.com"])
|
Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}])
|
||||||
|
|
||||||
follower =
|
follower =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
|
|
Loading…
Reference in a new issue