Make sure suspended actors are not in the AP cache anymore

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
chapril
Thomas Citharel 6 months ago
parent 501e0d12e4
commit da2254089c
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
  1. 10
      lib/web/cache/activity_pub.ex
  2. 19
      test/web/controllers/activity_pub_controller_test.exs
  3. 14
      test/web/controllers/page_controller_test.exs

@ -29,9 +29,12 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
@spec do_get_actor(String.t()) :: {:commit, Actor.t()} | {:ignore, nil}
defp do_get_actor("actor_" <> name) do
case Actor.find_or_make_actor_from_nickname(name) do
{:ok, %ActorModel{} = actor} ->
{:ok, %ActorModel{suspended: false} = actor} ->
{:commit, actor}
{:ok, %ActorModel{}} ->
{:ignore, nil}
{:error, _err} ->
{:ignore, nil}
end
@ -45,9 +48,12 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
def get_local_actor_by_name(name) do
Cachex.fetch(@cache, "local_actor_" <> name, fn "local_actor_" <> name ->
case Actors.get_local_actor_by_name(name) do
%ActorModel{} = actor ->
%ActorModel{suspended: false} = actor ->
{:commit, actor}
{:ok, %ActorModel{}} ->
{:ignore, nil}
nil ->
{:ignore, nil}
end

@ -14,6 +14,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Service.ActorSuspension
alias Mobilizon.Service.HTTP.ActivityPub.Mock
alias Mobilizon.Web.ActivityPub.ActorView
alias Mobilizon.Web.{Endpoint, PageView}
@ -44,6 +45,24 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|> Jason.encode!()
|> Jason.decode!()
end
test "it returns nothing if the actor is suspended", %{conn: conn} do
suspended = insert(:actor)
conn = get(conn, Actor.build_url(suspended.preferred_username, :page))
assert json_response(conn, 200)
assert {:ok, true} ==
Cachex.exists?(:activity_pub, "actor_" <> suspended.preferred_username)
ActorSuspension.suspend_actor(suspended)
assert {:ok, false} ==
Cachex.exists?(:activity_pub, "actor_" <> suspended.preferred_username)
conn = get(conn, Actor.build_url(suspended.preferred_username, :page))
assert json_response(conn, 404)
end
end
describe "/events/:uuid" do

@ -4,7 +4,7 @@ defmodule Mobilizon.Web.PageControllerTest do
import Mobilizon.Factory
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActorSuspension
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
@ -37,6 +37,18 @@ defmodule Mobilizon.Web.PageControllerTest do
conn = get(conn, Actor.build_url("not_existing", :page))
assert html_response(conn, 404)
end
test "GET /@actor when suspended", %{conn: conn} do
suspended = insert(:actor)
conn = get(conn, Actor.build_url(suspended.preferred_username, :page))
assert html_response(conn, 200)
ActorSuspension.suspend_actor(suspended)
conn = get(conn, Actor.build_url(suspended.preferred_username, :page))
assert html_response(conn, 404)
end
end
test "GET /events/:uuid", %{conn: conn} do

Loading…
Cancel
Save