diff options
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 8 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 44 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 56 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 5 | 
4 files changed, 78 insertions, 35 deletions
| diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 7b1c60f15..30adfda36 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          |> put_req_header("accept", "application/json")          |> get("/users/#{user.nickname}") -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          |> put_req_header("accept", "application/activity+json")          |> get("/users/#{user.nickname}") -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -83,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          )          |> get("/users/#{user.nickname}") -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -572,7 +572,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        user = insert(:user)        Enum.each(1..15, fn _ -> -        user = User.get_by_id(user.id) +        user = User.get_cached_by_id(user.id)          other_user = insert(:user)          User.follow(user, other_user)        end) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 389aa02a1..f8e987e58 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -228,18 +228,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        user = insert(:user)        {:ok, _} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "1", "visibility" => "public"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "1", +          "visibility" => "public" +        })        {:ok, _} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "unlisted"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "2", +          "visibility" => "unlisted" +        })        {:ok, _} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "private"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "2", +          "visibility" => "private" +        })        {:ok, _} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "3", "visibility" => "direct"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "3", +          "visibility" => "direct" +        }) -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert user.info.note_count == 2      end @@ -772,23 +784,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        user = insert(:user, info: %{note_count: 10})        {:ok, a1} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "public"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "yeah", +          "visibility" => "public" +        })        {:ok, a2} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "unlisted"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "yeah", +          "visibility" => "unlisted" +        })        {:ok, a3} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "private"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "yeah", +          "visibility" => "private" +        })        {:ok, a4} = -        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "direct"}) +        CommonAPI.post(User.get_cached_by_id(user.id), %{ +          "status" => "yeah", +          "visibility" => "direct" +        })        {:ok, _} = Object.normalize(a1) |> ActivityPub.delete()        {:ok, _} = Object.normalize(a2) |> ActivityPub.delete()        {:ok, _} = Object.normalize(a3) |> ActivityPub.delete()        {:ok, _} = Object.normalize(a4) |> ActivityPub.delete() -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert user.info.note_count == 10      end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 7d301b0d4..78429c7c6 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert object["sensitive"] == true -      user = User.get_by_ap_id(object["actor"]) +      user = User.get_cached_by_ap_id(object["actor"])        assert user.info.note_count == 1      end @@ -212,7 +212,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["actor"] == "http://mastodon.example.org/users/admin"        assert data["type"] == "Follow"        assert data["id"] == "http://mastodon.example.org/users/admin#follows/2" -      assert User.following?(User.get_by_ap_id(data["actor"]), user) +      assert User.following?(User.get_cached_by_ap_id(data["actor"]), user) +    end + +    test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do +      Pleroma.Config.put([:user, :deny_follow_blocked], true) + +      user = insert(:user) +      target = User.get_or_fetch("http://mastodon.example.org/users/admin") + +      {:ok, user} = User.block(user, target) + +      data = +        File.read!("test/fixtures/mastodon-follow-activity.json") +        |> Poison.decode!() +        |> Map.put("object", user.ap_id) + +      {:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data) + +      %Activity{} = activity = Activity.get_by_ap_id(id) + +      assert activity.data["state"] == "reject"      end      test "it works for incoming follow requests from hubzilla" do @@ -229,7 +249,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"        assert data["type"] == "Follow"        assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2" -      assert User.following?(User.get_by_ap_id(data["actor"]), user) +      assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)      end      test "it works for incoming likes" do @@ -540,7 +560,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["object"]["object"] == user.ap_id        assert data["actor"] == "http://mastodon.example.org/users/admin" -      refute User.following?(User.get_by_ap_id(data["actor"]), user) +      refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)      end      test "it works for incoming blocks" do @@ -557,7 +577,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["object"] == user.ap_id        assert data["actor"] == "http://mastodon.example.org/users/admin" -      blocker = User.get_by_ap_id(data["actor"]) +      blocker = User.get_cached_by_ap_id(data["actor"])        assert User.blocks?(blocker, user)      end @@ -584,8 +604,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["object"] == blocked.ap_id        assert data["actor"] == blocker.ap_id -      blocker = User.get_by_ap_id(data["actor"]) -      blocked = User.get_by_ap_id(data["object"]) +      blocker = User.get_cached_by_ap_id(data["actor"]) +      blocked = User.get_cached_by_ap_id(data["object"])        assert User.blocks?(blocker, blocked) @@ -614,7 +634,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["object"]["object"] == user.ap_id        assert data["actor"] == "http://mastodon.example.org/users/admin" -      blocker = User.get_by_ap_id(data["actor"]) +      blocker = User.get_cached_by_ap_id(data["actor"])        refute User.blocks?(blocker, user)      end @@ -645,7 +665,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert activity.data["object"] == follow_activity.data["id"] -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -667,7 +687,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(accept_data)        assert activity.data["object"] == follow_activity.data["id"] -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -687,7 +707,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(accept_data)        assert activity.data["object"] == follow_activity.data["id"] -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -706,7 +726,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(accept_data) -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        refute User.following?(follower, followed) == true      end @@ -725,7 +745,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(accept_data) -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        refute User.following?(follower, followed) == true      end @@ -750,7 +770,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(reject_data)        refute activity.local -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        assert User.following?(follower, followed) == false      end @@ -772,7 +792,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) -      follower = User.get_by_id(follower.id) +      follower = User.get_cached_by_id(follower.id)        assert User.following?(follower, followed) == false      end @@ -1026,7 +1046,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})        assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert user.info.note_count == 1        {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye") @@ -1034,7 +1054,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert user.info.note_count == 1        assert user.follower_address == "https://niu.moe/users/rye/followers" -      user = User.get_by_id(user.id) +      user = User.get_cached_by_id(user.id)        assert user.info.note_count == 1        activity = Activity.get_by_id(activity.id) @@ -1063,7 +1083,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        unrelated_activity = Activity.get_by_id(unrelated_activity.id)        refute user.follower_address in unrelated_activity.recipients -      user_two = User.get_by_id(user_two.id) +      user_two = User.get_cached_by_id(user_two.id)        assert user.follower_address in user_two.following        refute "..." in user_two.following      end diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 758214e68..c57fae437 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -1,7 +1,6 @@  defmodule Pleroma.Web.ActivityPub.UtilsTest do    use Pleroma.DataCase    alias Pleroma.Activity -  alias Pleroma.Repo    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Utils @@ -12,8 +11,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do    describe "fetch the latest Follow" do      test "fetches the latest Follow activity" do        %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) -      follower = Repo.get_by(User, ap_id: activity.data["actor"]) -      followed = Repo.get_by(User, ap_id: activity.data["object"]) +      follower = User.get_cached_by_ap_id(activity.data["actor"]) +      followed = User.get_cached_by_ap_id(activity.data["object"])        assert activity == Utils.fetch_latest_follow(follower, followed)      end | 
