logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

user_update_handling_test.exs (4587B)


  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 Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.User
  8. alias Pleroma.Web.ActivityPub.Transmogrifier
  9. import Pleroma.Factory
  10. test "it works for incoming update activities" do
  11. user = insert(:user, local: false)
  12. update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
  13. object =
  14. update_data["object"]
  15. |> Map.put("actor", user.ap_id)
  16. |> Map.put("id", user.ap_id)
  17. update_data =
  18. update_data
  19. |> Map.put("actor", user.ap_id)
  20. |> Map.put("object", object)
  21. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
  22. assert data["id"] == update_data["id"]
  23. user = User.get_cached_by_ap_id(data["actor"])
  24. assert user.name == "gargle"
  25. assert user.avatar["url"] == [
  26. %{
  27. "href" =>
  28. "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
  29. }
  30. ]
  31. assert user.banner["url"] == [
  32. %{
  33. "href" =>
  34. "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
  35. }
  36. ]
  37. assert user.bio == "<p>Some bio</p>"
  38. end
  39. test "it works with alsoKnownAs" do
  40. %{ap_id: actor} = insert(:user, local: false)
  41. assert User.get_cached_by_ap_id(actor).also_known_as == []
  42. {:ok, _activity} =
  43. "test/fixtures/mastodon-update.json"
  44. |> File.read!()
  45. |> Poison.decode!()
  46. |> Map.put("actor", actor)
  47. |> Map.update!("object", fn object ->
  48. object
  49. |> Map.put("actor", actor)
  50. |> Map.put("id", actor)
  51. |> Map.put("alsoKnownAs", [
  52. "http://mastodon.example.org/users/foo",
  53. "http://example.org/users/bar"
  54. ])
  55. end)
  56. |> Transmogrifier.handle_incoming()
  57. assert User.get_cached_by_ap_id(actor).also_known_as == [
  58. "http://mastodon.example.org/users/foo",
  59. "http://example.org/users/bar"
  60. ]
  61. end
  62. test "it works with custom profile fields" do
  63. user = insert(:user, local: false)
  64. assert user.fields == []
  65. update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
  66. object =
  67. update_data["object"]
  68. |> Map.put("actor", user.ap_id)
  69. |> Map.put("id", user.ap_id)
  70. update_data =
  71. update_data
  72. |> Map.put("actor", user.ap_id)
  73. |> Map.put("object", object)
  74. {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
  75. user = User.get_cached_by_ap_id(user.ap_id)
  76. assert user.fields == [
  77. %{"name" => "foo", "value" => "updated"},
  78. %{"name" => "foo1", "value" => "updated"}
  79. ]
  80. Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
  81. update_data =
  82. update_data
  83. |> put_in(["object", "attachment"], [
  84. %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
  85. %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
  86. %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
  87. ])
  88. |> Map.put("id", update_data["id"] <> ".")
  89. {:ok, _} = Transmogrifier.handle_incoming(update_data)
  90. user = User.get_cached_by_ap_id(user.ap_id)
  91. assert user.fields == [
  92. %{"name" => "foo", "value" => "updated"},
  93. %{"name" => "foo1", "value" => "updated"}
  94. ]
  95. update_data =
  96. update_data
  97. |> put_in(["object", "attachment"], [])
  98. |> Map.put("id", update_data["id"] <> ".")
  99. {:ok, _} = Transmogrifier.handle_incoming(update_data)
  100. user = User.get_cached_by_ap_id(user.ap_id)
  101. assert user.fields == []
  102. end
  103. test "it works for incoming update activities which lock the account" do
  104. user = insert(:user, local: false)
  105. update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
  106. object =
  107. update_data["object"]
  108. |> Map.put("actor", user.ap_id)
  109. |> Map.put("id", user.ap_id)
  110. |> Map.put("manuallyApprovesFollowers", true)
  111. update_data =
  112. update_data
  113. |> Map.put("actor", user.ap_id)
  114. |> Map.put("object", object)
  115. {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
  116. user = User.get_cached_by_ap_id(user.ap_id)
  117. assert user.locked == true
  118. end
  119. end