Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.0KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.RelayTest do
  5. alias Pleroma.Activity
  6. alias Pleroma.User
  7. alias Pleroma.Web.ActivityPub.ActivityPub
  8. alias Pleroma.Web.ActivityPub.Relay
  9. alias Pleroma.Web.ActivityPub.Utils
  10. use Pleroma.DataCase
  11. setup_all do
  12. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  13. Mix.shell(Mix.Shell.Process)
  14. on_exit(fn ->
  15. Mix.shell(Mix.Shell.IO)
  16. end)
  17. :ok
  18. end
  19. describe "running follow" do
  20. test "relay is followed" do
  21. target_instance = "http://mastodon.example.org/users/admin"
  22. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  23. local_user = Relay.get_actor()
  24. assert local_user.ap_id =~ "/relay"
  25. target_user = User.get_cached_by_ap_id(target_instance)
  26. refute target_user.local
  27. activity = Utils.fetch_latest_follow(local_user, target_user)
  28. assert activity.data["type"] == "Follow"
  29. assert activity.data["actor"] == local_user.ap_id
  30. assert activity.data["object"] == target_user.ap_id
  31. end
  32. end
  33. describe "running unfollow" do
  34. test "relay is unfollowed" do
  35. target_instance = "http://mastodon.example.org/users/admin"
  36. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  37. %User{ap_id: follower_id} = local_user = Relay.get_actor()
  38. target_user = User.get_cached_by_ap_id(target_instance)
  39. follow_activity = Utils.fetch_latest_follow(local_user, target_user)
  40. User.follow(local_user, target_user)
  41. assert "#{target_instance}/followers" in User.following(local_user)
  42. Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
  43. cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
  44. assert cancelled_activity.data["state"] == "cancelled"
  45. [undo_activity] =
  46. ActivityPub.fetch_activities([], %{
  47. "type" => "Undo",
  48. "actor_id" => follower_id,
  49. "limit" => 1,
  50. "skip_preload" => true
  51. })
  52. assert undo_activity.data["type"] == "Undo"
  53. assert undo_activity.data["actor"] == local_user.ap_id
  54. assert undo_activity.data["object"] == cancelled_activity.data
  55. refute "#{target_instance}/followers" in User.following(local_user)
  56. end
  57. end
  58. describe "mix pleroma.relay list" do
  59. test "Prints relay subscription list" do
  60. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  61. refute_receive {:mix_shell, :info, _}
  62. relay_user = Relay.get_actor()
  63. ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
  64. |> Enum.each(fn ap_id ->
  65. {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
  66. User.follow(relay_user, user)
  67. end)
  68. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  69. assert_receive {:mix_shell, :info, ["mstdn.io"]}
  70. assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
  71. end
  72. end
  73. end