2021-07-17 18:05:25 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-26 06:11:42 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2021-07-17 18:05:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.InstanceControllerTest do
|
2022-06-11 07:38:43 +00:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2021-07-17 18:05:25 +00:00
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2021-07-17 19:55:05 +00:00
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2021-07-17 18:05:25 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
admin = insert(:user, is_admin: true)
|
|
|
|
token = insert(:oauth_admin_token, user: admin)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, token)
|
|
|
|
|
|
|
|
{:ok, %{admin: admin, token: token, conn: conn}}
|
|
|
|
end
|
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
test "GET /instances/:instance/statuses", %{conn: conn} do
|
2022-06-11 07:38:43 +00:00
|
|
|
clear_config([:instance, :admin_privileges], [:statuses_read])
|
2021-07-17 20:00:15 +00:00
|
|
|
user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
|
|
|
|
user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
|
|
|
|
insert_pair(:note_activity, user: user)
|
|
|
|
activity = insert(:note_activity, user: user2)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
%{"total" => 2, "activities" => activities} =
|
|
|
|
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
assert length(activities) == 2
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
%{"total" => 1, "activities" => [_]} =
|
|
|
|
conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
%{"total" => 0, "activities" => []} =
|
|
|
|
conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
CommonAPI.repeat(activity.id, user)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
%{"total" => 2, "activities" => activities} =
|
|
|
|
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
assert length(activities) == 2
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
%{"total" => 3, "activities" => activities} =
|
|
|
|
conn
|
|
|
|
|> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
|
|
|
|> json_response(200)
|
2021-07-17 18:05:25 +00:00
|
|
|
|
2021-07-17 20:00:15 +00:00
|
|
|
assert length(activities) == 3
|
2022-06-11 07:38:43 +00:00
|
|
|
|
|
|
|
clear_config([:instance, :admin_privileges], [])
|
|
|
|
|
|
|
|
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(:forbidden)
|
2021-07-17 18:05:25 +00:00
|
|
|
end
|
2021-07-17 19:55:05 +00:00
|
|
|
|
|
|
|
test "DELETE /instances/:instance", %{conn: conn} do
|
2022-06-12 08:07:33 +00:00
|
|
|
clear_config([:instance, :admin_privileges], [:instance_delete])
|
2021-07-17 19:55:05 +00:00
|
|
|
user = insert(:user, nickname: "lain@lain.com")
|
|
|
|
post = insert(:note_activity, user: user)
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> delete("/api/pleroma/admin/instances/lain.com")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
[:ok] = ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert response == "lain.com"
|
|
|
|
refute Repo.reload(user).is_active
|
|
|
|
refute Repo.reload(post)
|
2022-06-12 08:07:33 +00:00
|
|
|
|
|
|
|
clear_config([:instance, :admin_privileges], [])
|
|
|
|
|
2022-06-13 09:00:49 +00:00
|
|
|
conn
|
|
|
|
|> delete("/api/pleroma/admin/instances/lain.com")
|
|
|
|
|> json_response(:forbidden)
|
2021-07-17 19:55:05 +00:00
|
|
|
end
|
2021-07-17 18:05:25 +00:00
|
|
|
end
|