CommonAPI: Fail when user sends report with posts not visible to them
This commit is contained in:
parent
a4e480a636
commit
2b76243ec8
6 changed files with 124 additions and 3 deletions
|
|
@ -1286,6 +1286,47 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
} = flag_activity
|
||||
end
|
||||
|
||||
test "doesn't create a report when post is not visible to user" do
|
||||
reporter = insert(:user)
|
||||
target_user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(target_user, %{status: "Eric", visibility: "private"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.private?(post)
|
||||
refute Pleroma.Web.ActivityPub.Visibility.visible_for_user?(post, reporter)
|
||||
|
||||
# Fails when all status are invisible
|
||||
report_data = %{
|
||||
account_id: target_user.id,
|
||||
comment: "foobar",
|
||||
status_ids: [post.id]
|
||||
}
|
||||
|
||||
assert {:error, :visibility} = CommonAPI.report(reporter, report_data)
|
||||
end
|
||||
|
||||
test "doesn't create a report when some posts are not visible to user" do
|
||||
reporter = insert(:user)
|
||||
target_user = insert(:user)
|
||||
|
||||
{:ok, visible_activity} = CommonAPI.post(target_user, %{status: "cofe"})
|
||||
|
||||
{:ok, invisibile_activity} =
|
||||
CommonAPI.post(target_user, %{status: "cawfee", visibility: "private"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.private?(invisibile_activity)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.public?(visible_activity)
|
||||
refute Pleroma.Web.ActivityPub.Visibility.visible_for_user?(invisibile_activity, reporter)
|
||||
|
||||
# Fails when some statuses are invisible
|
||||
report_data_partial = %{
|
||||
account_id: target_user.id,
|
||||
comment: "foobar",
|
||||
status_ids: [visible_activity.id, invisibile_activity.id]
|
||||
}
|
||||
|
||||
assert {:error, :visibility} = CommonAPI.report(reporter, report_data_partial)
|
||||
end
|
||||
|
||||
test "updates report state" do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
|
||||
test "returns error when account is not exist", %{
|
||||
test "returns error when account does not exist", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
|
|
@ -159,6 +159,51 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
|
||||
end
|
||||
|
||||
test "returns not found when post isn't visible to reporter", %{user: target_user} do
|
||||
%{conn: conn, user: reporter} = oauth_access(["write:reports"])
|
||||
|
||||
{:ok, invisible_activity} =
|
||||
CommonAPI.post(target_user, %{status: "Invisible!", visibility: "private"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.private?(invisible_activity)
|
||||
refute Pleroma.Web.ActivityPub.Visibility.visible_for_user?(invisible_activity, reporter)
|
||||
|
||||
assert %{"error" => "Record not found"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
"/api/v1/reports",
|
||||
%{"account_id" => target_user.id, "status_ids" => [invisible_activity.id]}
|
||||
)
|
||||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
|
||||
test "returns not found when some post aren't visible to reporter", %{
|
||||
activity: activity,
|
||||
user: target_user
|
||||
} do
|
||||
%{conn: conn, user: reporter} = oauth_access(["write:reports"])
|
||||
|
||||
{:ok, invisible_activity} =
|
||||
CommonAPI.post(target_user, %{status: "Invisible!", visibility: "private"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.private?(invisible_activity)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.visible_for_user?(activity, reporter)
|
||||
refute Pleroma.Web.ActivityPub.Visibility.visible_for_user?(invisible_activity, reporter)
|
||||
|
||||
assert %{"error" => "Record not found"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
"/api/v1/reports",
|
||||
%{
|
||||
"account_id" => target_user.id,
|
||||
"status_ids" => [activity.id, invisible_activity.id]
|
||||
}
|
||||
)
|
||||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
|
||||
test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
|
||||
insert(:user, %{is_admin: true, email: nil})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue