1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
6 use Pleroma.Web.ConnCase, async: true
10 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
14 setup do: oauth_access(["write:reports"])
17 target_user = insert(:user)
19 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
21 [target_user: target_user, activity: activity]
24 test "submit a basic report", %{conn: conn, target_user: target_user} do
25 assert %{"action_taken" => false, "id" => _} =
27 |> put_req_header("content-type", "application/json")
28 |> post("/api/v1/reports", %{"account_id" => target_user.id})
29 |> json_response_and_validate_schema(200)
32 test "submit a report with a fake Create", %{
35 target_user = insert(:user)
37 note = insert(:note, user: target_user)
40 "object" => note.data["id"],
41 "actor" => note.data["actor"],
42 "to" => note.data["to"] || [],
43 "cc" => note.data["cc"] || [],
47 {:ok, fake_activity} =
48 Repo.insert(%Activity{
49 data: activity_params,
50 recipients: activity_params["to"] ++ activity_params["cc"],
52 actor: activity_params["actor"]
55 assert %{"action_taken" => false, "id" => _} =
57 |> put_req_header("content-type", "application/json")
58 |> post("/api/v1/reports", %{
59 "account_id" => target_user.id,
60 "status_ids" => [fake_activity.id],
61 "comment" => "bad status!",
64 |> json_response_and_validate_schema(200)
67 test "submit a report with statuses and comment", %{
69 target_user: target_user,
72 assert %{"action_taken" => false, "id" => _} =
74 |> put_req_header("content-type", "application/json")
75 |> post("/api/v1/reports", %{
76 "account_id" => target_user.id,
77 "status_ids" => [activity.id],
78 "comment" => "bad status!",
81 |> json_response_and_validate_schema(200)
84 test "account_id is required", %{
88 assert %{"error" => "Missing field: account_id."} =
90 |> put_req_header("content-type", "application/json")
91 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
92 |> json_response_and_validate_schema(400)
95 test "comment must be up to the size specified in the config", %{
97 target_user: target_user
99 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
100 comment = String.pad_trailing("a", max_size + 1, "a")
102 error = %{"error" => "Comment must be up to #{max_size} characters"}
106 |> put_req_header("content-type", "application/json")
107 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
108 |> json_response_and_validate_schema(400)
111 test "returns error when account is not exist", %{
117 |> put_req_header("content-type", "application/json")
118 |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
120 assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
123 test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
124 insert(:user, %{is_admin: true, email: nil})
126 assert %{"action_taken" => false, "id" => _} =
128 |> put_req_header("content-type", "application/json")
129 |> post("/api/v1/reports", %{"account_id" => target_user.id})
130 |> json_response_and_validate_schema(200)