Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

103 satır
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. import Pleroma.Factory
  12. setup_all do
  13. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  14. Mix.shell(Mix.Shell.Process)
  15. on_exit(fn ->
  16. Mix.shell(Mix.Shell.IO)
  17. end)
  18. :ok
  19. end
  20. describe "running follow" do
  21. test "relay is followed" do
  22. target_instance = "http://mastodon.example.org/users/admin"
  23. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  24. local_user = Relay.get_actor()
  25. assert local_user.ap_id =~ "/relay"
  26. target_user = User.get_cached_by_ap_id(target_instance)
  27. refute target_user.local
  28. activity = Utils.fetch_latest_follow(local_user, target_user)
  29. assert activity.data["type"] == "Follow"
  30. assert activity.data["actor"] == local_user.ap_id
  31. assert activity.data["object"] == target_user.ap_id
  32. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  33. assert_receive {:mix_shell, :info, ["mastodon.example.org (no Accept received)"]}
  34. end
  35. end
  36. describe "running unfollow" do
  37. test "relay is unfollowed" do
  38. user = insert(:user)
  39. target_instance = user.ap_id
  40. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  41. %User{ap_id: follower_id} = local_user = Relay.get_actor()
  42. target_user = User.get_cached_by_ap_id(target_instance)
  43. follow_activity = Utils.fetch_latest_follow(local_user, target_user)
  44. User.follow(local_user, target_user)
  45. assert "#{target_instance}/followers" in User.following(local_user)
  46. Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
  47. cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
  48. assert cancelled_activity.data["state"] == "cancelled"
  49. [undo_activity] =
  50. ActivityPub.fetch_activities([], %{
  51. type: "Undo",
  52. actor_id: follower_id,
  53. limit: 1,
  54. skip_preload: true,
  55. invisible_actors: true
  56. })
  57. assert undo_activity.data["type"] == "Undo"
  58. assert undo_activity.data["actor"] == local_user.ap_id
  59. assert undo_activity.data["object"]["id"] == cancelled_activity.data["id"]
  60. refute "#{target_instance}/followers" in User.following(local_user)
  61. end
  62. end
  63. describe "mix pleroma.relay list" do
  64. test "Prints relay subscription list" do
  65. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  66. refute_receive {:mix_shell, :info, _}
  67. relay_user = Relay.get_actor()
  68. ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
  69. |> Enum.each(fn ap_id ->
  70. {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
  71. User.follow(relay_user, user)
  72. end)
  73. :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
  74. assert_receive {:mix_shell, :info, ["mstdn.io"]}
  75. assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
  76. end
  77. end
  78. end