2019-06-15 22:30:14 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 22:44:49 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-06-15 22:30:14 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|
|
|
use Pleroma.DataCase
|
2020-07-22 16:06:00 +00:00
|
|
|
|
2019-06-15 22:30:14 +00:00
|
|
|
import Pleroma.Factory
|
2020-07-22 16:06:00 +00:00
|
|
|
|
|
|
|
alias Pleroma.Web.AdminAPI
|
2019-09-23 22:33:59 +00:00
|
|
|
alias Pleroma.Web.AdminAPI.Report
|
2019-06-15 22:30:14 +00:00
|
|
|
alias Pleroma.Web.AdminAPI.ReportView
|
2019-06-15 22:35:45 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-07-22 16:06:00 +00:00
|
|
|
alias Pleroma.Web.MastodonAPI
|
2019-06-15 22:30:14 +00:00
|
|
|
alias Pleroma.Web.MastodonAPI.StatusView
|
|
|
|
|
|
|
|
test "renders a report" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-04-28 12:50:37 +00:00
|
|
|
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
2019-06-15 22:30:14 +00:00
|
|
|
|
|
|
|
expected = %{
|
2019-06-16 09:57:58 +00:00
|
|
|
content: nil,
|
2019-06-28 12:15:32 +00:00
|
|
|
actor:
|
|
|
|
Map.merge(
|
2020-07-23 12:08:30 +00:00
|
|
|
MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
|
2020-07-22 16:06:00 +00:00
|
|
|
AdminAPI.AccountView.render("show.json", %{user: user})
|
2019-06-28 12:15:32 +00:00
|
|
|
),
|
|
|
|
account:
|
|
|
|
Map.merge(
|
2020-07-23 12:08:30 +00:00
|
|
|
MastodonAPI.AccountView.render("show.json", %{
|
|
|
|
user: other_user,
|
|
|
|
skip_visibility_check: true
|
|
|
|
}),
|
2020-07-22 16:06:00 +00:00
|
|
|
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
2019-06-28 12:15:32 +00:00
|
|
|
),
|
2019-06-15 22:30:14 +00:00
|
|
|
statuses: [],
|
2019-12-03 14:54:07 +00:00
|
|
|
notes: [],
|
2019-06-15 22:30:14 +00:00
|
|
|
state: "open",
|
|
|
|
id: activity.id
|
|
|
|
}
|
|
|
|
|
|
|
|
result =
|
2019-09-23 22:33:59 +00:00
|
|
|
ReportView.render("show.json", Report.extract_report_info(activity))
|
2019-06-15 22:30:14 +00:00
|
|
|
|> Map.delete(:created_at)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "includes reported statuses" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "toot"})
|
2019-06-15 22:30:14 +00:00
|
|
|
|
|
|
|
{:ok, report_activity} =
|
2020-04-28 12:50:37 +00:00
|
|
|
CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
|
2019-06-15 22:30:14 +00:00
|
|
|
|
2019-10-16 18:59:21 +00:00
|
|
|
other_user = Pleroma.User.get_by_id(other_user.id)
|
|
|
|
|
2019-06-15 22:30:14 +00:00
|
|
|
expected = %{
|
2019-06-16 09:57:58 +00:00
|
|
|
content: nil,
|
2019-06-28 12:15:32 +00:00
|
|
|
actor:
|
|
|
|
Map.merge(
|
2020-07-23 12:08:30 +00:00
|
|
|
MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
|
2020-07-22 16:06:00 +00:00
|
|
|
AdminAPI.AccountView.render("show.json", %{user: user})
|
2019-06-28 12:15:32 +00:00
|
|
|
),
|
|
|
|
account:
|
|
|
|
Map.merge(
|
2020-07-23 12:08:30 +00:00
|
|
|
MastodonAPI.AccountView.render("show.json", %{
|
|
|
|
user: other_user,
|
|
|
|
skip_visibility_check: true
|
|
|
|
}),
|
2020-07-22 16:06:00 +00:00
|
|
|
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
2019-06-28 12:15:32 +00:00
|
|
|
),
|
2019-09-09 14:49:02 +00:00
|
|
|
statuses: [StatusView.render("show.json", %{activity: activity})],
|
2019-06-15 22:30:14 +00:00
|
|
|
state: "open",
|
2019-12-03 14:54:07 +00:00
|
|
|
notes: [],
|
2019-06-15 22:30:14 +00:00
|
|
|
id: report_activity.id
|
|
|
|
}
|
|
|
|
|
|
|
|
result =
|
2019-09-23 22:33:59 +00:00
|
|
|
ReportView.render("show.json", Report.extract_report_info(report_activity))
|
2019-06-15 22:30:14 +00:00
|
|
|
|> Map.delete(:created_at)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "renders report's state" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-04-28 12:50:37 +00:00
|
|
|
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
2019-06-15 22:30:14 +00:00
|
|
|
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
2019-09-23 22:33:59 +00:00
|
|
|
|
|
|
|
assert %{state: "closed"} =
|
|
|
|
ReportView.render("show.json", Report.extract_report_info(activity))
|
2019-06-15 22:30:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "renders report description" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.report(user, %{
|
2020-04-28 12:50:37 +00:00
|
|
|
account_id: other_user.id,
|
|
|
|
comment: "posts are too good for this instance"
|
2019-06-15 22:30:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assert %{content: "posts are too good for this instance"} =
|
2019-09-23 22:33:59 +00:00
|
|
|
ReportView.render("show.json", Report.extract_report_info(activity))
|
2019-06-15 22:30:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "sanitizes report description" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.report(user, %{
|
2020-04-28 12:50:37 +00:00
|
|
|
account_id: other_user.id,
|
|
|
|
comment: ""
|
2019-06-15 22:30:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
|
|
|
|
activity = Map.put(activity, :data, data)
|
|
|
|
|
2019-06-16 09:57:58 +00:00
|
|
|
refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
|
2019-09-23 22:33:59 +00:00
|
|
|
ReportView.render("show.json", Report.extract_report_info(activity))[:content]
|
2019-06-15 22:30:14 +00:00
|
|
|
end
|
2019-07-02 01:27:00 +00:00
|
|
|
|
|
|
|
test "doesn't error out when the user doesn't exists" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.report(user, %{
|
2020-04-28 12:50:37 +00:00
|
|
|
account_id: other_user.id,
|
|
|
|
comment: ""
|
2019-07-02 01:27:00 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Pleroma.User.delete(other_user)
|
|
|
|
Pleroma.User.invalidate_cache(other_user)
|
|
|
|
|
2019-09-23 22:33:59 +00:00
|
|
|
assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))
|
2019-07-02 01:27:00 +00:00
|
|
|
end
|
2019-06-15 22:30:14 +00:00
|
|
|
end
|