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.

91 lines
2.8KB

  1. defmodule Pleroma.Object.FetcherTest do
  2. use Pleroma.DataCase
  3. alias Pleroma.Activity
  4. alias Pleroma.Object
  5. alias Pleroma.Object.Fetcher
  6. import Tesla.Mock
  7. setup do
  8. mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
  9. :ok
  10. end
  11. describe "actor origin containment" do
  12. test "it rejects objects with a bogus origin" do
  13. {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
  14. end
  15. test "it rejects objects when attributedTo is wrong (variant 1)" do
  16. {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
  17. end
  18. test "it rejects objects when attributedTo is wrong (variant 2)" do
  19. {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
  20. end
  21. end
  22. describe "fetching an object" do
  23. test "it fetches an object" do
  24. {:ok, object} =
  25. Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
  26. assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
  27. assert activity.data["id"]
  28. {:ok, object_again} =
  29. Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
  30. assert [attachment] = object.data["attachment"]
  31. assert is_list(attachment["url"])
  32. assert object == object_again
  33. end
  34. test "it works with objects only available via Ostatus" do
  35. {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
  36. assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
  37. assert activity.data["id"]
  38. {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
  39. assert object == object_again
  40. end
  41. test "it correctly stitches up conversations between ostatus and ap" do
  42. last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
  43. {:ok, object} = Fetcher.fetch_object_from_id(last)
  44. object = Object.get_by_ap_id(object.data["inReplyTo"])
  45. assert object
  46. end
  47. end
  48. describe "implementation quirks" do
  49. test "it can fetch plume articles" do
  50. {:ok, object} =
  51. Fetcher.fetch_object_from_id(
  52. "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
  53. )
  54. assert object
  55. end
  56. test "it can fetch peertube videos" do
  57. {:ok, object} =
  58. Fetcher.fetch_object_from_id(
  59. "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
  60. )
  61. assert object
  62. end
  63. test "all objects with fake directions are rejected by the object fetcher" do
  64. {:error, _} =
  65. Fetcher.fetch_and_contain_remote_object_from_id(
  66. "https://info.pleroma.site/activity4.json"
  67. )
  68. end
  69. end
  70. end