fix issue with API cascading domain blocks but not honouring them

This commit is contained in:
FloatingGhost 2023-08-25 11:00:49 +01:00
parent 5c164028cf
commit c8e08e9cc3
2 changed files with 27 additions and 21 deletions

View file

@ -1605,9 +1605,13 @@ defmodule Pleroma.User do
def blocks_user?(_, _), do: false
def blocks_domain?(%User{} = user, %User{} = target) do
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
%{host: host} = URI.parse(target.ap_id)
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
Enum.member?(user.domain_blocks, host)
# TODO: functionality should probably be changed such that subdomains block as well,
# but as it stands, this just hecks up the relationships endpoint
# domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
# %{host: host} = URI.parse(target.ap_id)
# Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
end
def blocks_domain?(_, _), do: false

View file

@ -1353,25 +1353,27 @@ defmodule Pleroma.UserTest do
refute User.blocks?(user, collateral_user)
end
test "blocks domain with wildcard for subdomain" do
user = insert(:user)
user_from_subdomain =
insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
user_with_two_subdomains =
insert(:user, %{
ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
})
user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
{:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
assert User.blocks?(user, user_from_subdomain)
assert User.blocks?(user, user_with_two_subdomains)
assert User.blocks?(user, user_domain)
end
# This behaviour is not honoured by the timeline query
# re-add at a later date when UX is established
# test "blocks domain with wildcard for subdomain" do
# user = insert(:user)
#
# user_from_subdomain =
# insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
#
# user_with_two_subdomains =
# insert(:user, %{
# ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
# })
#
# user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
#
# {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
#
# assert User.blocks?(user, user_from_subdomain)
# assert User.blocks?(user, user_with_two_subdomains)
# assert User.blocks?(user, user_domain)
# end
test "unblocks domains" do
user = insert(:user)