Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

100 Zeilen
3.1KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 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. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  32. assert_receive {:mix_shell, :info, ["mastodon.example.org (no Accept received)"]}
  33. end
  34. end
  35. describe "running unfollow" do
  36. test "relay is unfollowed" do
  37. target_instance = "http://mastodon.example.org/users/admin"
  38. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  39. %User{ap_id: follower_id} = local_user = Relay.get_actor()
  40. target_user = User.get_cached_by_ap_id(target_instance)
  41. follow_activity = Utils.fetch_latest_follow(local_user, target_user)
  42. User.follow(local_user, target_user)
  43. assert "#{target_instance}/followers" in User.following(local_user)
  44. Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
  45. cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
  46. assert cancelled_activity.data["state"] == "cancelled"
  47. [undo_activity] =
  48. ActivityPub.fetch_activities([], %{
  49. type: "Undo",
  50. actor_id: follower_id,
  51. limit: 1,
  52. skip_preload: true,
  53. invisible_actors: true
  54. })
  55. assert undo_activity.data["type"] == "Undo"
  56. assert undo_activity.data["actor"] == local_user.ap_id
  57. assert undo_activity.data["object"] == cancelled_activity.data
  58. refute "#{target_instance}/followers" in User.following(local_user)
  59. end
  60. end
  61. describe "mix pleroma.relay list" do
  62. test "Prints relay subscription list" do
  63. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  64. refute_receive {:mix_shell, :info, _}
  65. relay_user = Relay.get_actor()
  66. ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
  67. |> Enum.each(fn ap_id ->
  68. {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
  69. User.follow(relay_user, user)
  70. end)
  71. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  72. assert_receive {:mix_shell, :info, ["mstdn.io"]}
  73. assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
  74. end
  75. end
  76. end