logo

pleroma

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

report_view_test.exs (4243B)


  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.AdminAPI.ReportViewTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Web.AdminAPI
  8. alias Pleroma.Web.AdminAPI.Report
  9. alias Pleroma.Web.AdminAPI.ReportView
  10. alias Pleroma.Web.CommonAPI
  11. alias Pleroma.Web.MastodonAPI
  12. alias Pleroma.Web.MastodonAPI.StatusView
  13. test "renders a report" do
  14. user = insert(:user)
  15. other_user = insert(:user)
  16. {:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
  17. expected = %{
  18. content: nil,
  19. actor:
  20. Map.merge(
  21. MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
  22. AdminAPI.AccountView.render("show.json", %{user: user})
  23. ),
  24. account:
  25. Map.merge(
  26. MastodonAPI.AccountView.render("show.json", %{
  27. user: other_user,
  28. skip_visibility_check: true
  29. }),
  30. AdminAPI.AccountView.render("show.json", %{user: other_user})
  31. ),
  32. statuses: [],
  33. notes: [],
  34. state: "open",
  35. id: activity.id
  36. }
  37. result =
  38. ReportView.render("show.json", Report.extract_report_info(activity))
  39. |> Map.delete(:created_at)
  40. assert result == expected
  41. end
  42. test "includes reported statuses" do
  43. user = insert(:user)
  44. other_user = insert(:user)
  45. {:ok, activity} = CommonAPI.post(other_user, %{status: "toot"})
  46. {:ok, report_activity} =
  47. CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
  48. other_user = Pleroma.User.get_by_id(other_user.id)
  49. expected = %{
  50. content: nil,
  51. actor:
  52. Map.merge(
  53. MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
  54. AdminAPI.AccountView.render("show.json", %{user: user})
  55. ),
  56. account:
  57. Map.merge(
  58. MastodonAPI.AccountView.render("show.json", %{
  59. user: other_user,
  60. skip_visibility_check: true
  61. }),
  62. AdminAPI.AccountView.render("show.json", %{user: other_user})
  63. ),
  64. statuses: [StatusView.render("show.json", %{activity: activity})],
  65. state: "open",
  66. notes: [],
  67. id: report_activity.id
  68. }
  69. result =
  70. ReportView.render("show.json", Report.extract_report_info(report_activity))
  71. |> Map.delete(:created_at)
  72. assert result == expected
  73. end
  74. test "renders report's state" do
  75. user = insert(:user)
  76. other_user = insert(:user)
  77. {:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
  78. {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
  79. assert %{state: "closed"} =
  80. ReportView.render("show.json", Report.extract_report_info(activity))
  81. end
  82. test "renders report description" do
  83. user = insert(:user)
  84. other_user = insert(:user)
  85. {:ok, activity} =
  86. CommonAPI.report(user, %{
  87. account_id: other_user.id,
  88. comment: "posts are too good for this instance"
  89. })
  90. assert %{content: "posts are too good for this instance"} =
  91. ReportView.render("show.json", Report.extract_report_info(activity))
  92. end
  93. test "sanitizes report description" do
  94. user = insert(:user)
  95. other_user = insert(:user)
  96. {:ok, activity} =
  97. CommonAPI.report(user, %{
  98. account_id: other_user.id,
  99. comment: ""
  100. })
  101. data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
  102. activity = Map.put(activity, :data, data)
  103. refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
  104. ReportView.render("show.json", Report.extract_report_info(activity))[:content]
  105. end
  106. test "doesn't error out when the user doesn't exists" do
  107. user = insert(:user)
  108. other_user = insert(:user)
  109. {:ok, activity} =
  110. CommonAPI.report(user, %{
  111. account_id: other_user.id,
  112. comment: ""
  113. })
  114. Pleroma.User.delete(other_user)
  115. Pleroma.User.invalidate_cache(other_user)
  116. assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))
  117. end
  118. end