Merge branch 'develop' into issue/1975
This commit is contained in:
commit
72d2b34d3b
525 changed files with 10701 additions and 10027 deletions
|
|
@ -100,7 +100,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> post("/api/v1/pleroma/chats/#{chat.id}/messages")
|
||||
|> json_response_and_validate_schema(400)
|
||||
|
||||
assert result
|
||||
assert %{"error" => "no_content"} == result
|
||||
end
|
||||
|
||||
test "it works with an attachment", %{conn: conn, user: user} do
|
||||
|
|
@ -126,6 +126,23 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|
||||
assert result["attachment"]
|
||||
end
|
||||
|
||||
test "gets MRF reason when rejected", %{conn: conn, user: user} do
|
||||
clear_config([:mrf_keyword, :reject], ["GNO"])
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/chats/#{chat.id}/messages", %{"content" => "GNO/Linux"})
|
||||
|> json_response_and_validate_schema(422)
|
||||
|
||||
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} == result
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /api/v1/pleroma/chats/:id/messages/:message_id" do
|
||||
|
|
@ -267,6 +284,21 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
describe "GET /api/v1/pleroma/chats" do
|
||||
setup do: oauth_access(["read:chats"])
|
||||
|
||||
test "it does not return chats with deleted users", %{conn: conn, user: user} do
|
||||
recipient = insert(:user)
|
||||
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
|
||||
|
||||
Pleroma.Repo.delete(recipient)
|
||||
User.invalidate_cache(recipient)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/chats")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 0
|
||||
end
|
||||
|
||||
test "it does not return chats with users you blocked", %{conn: conn, user: user} do
|
||||
recipient = insert(:user)
|
||||
|
||||
|
|
|
|||
235
test/web/pleroma_api/controllers/user_import_controller_test.exs
Normal file
235
test/web/pleroma_api/controllers/user_import_controller_test.exs
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/follow_import" do
|
||||
setup do: oauth_access(["follow"])
|
||||
|
||||
test "it returns HTTP 200", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "it imports follow lists from file", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
with_mocks([
|
||||
{File, [],
|
||||
read!: fn "follow_list.txt" ->
|
||||
"Account address,Show boosts\n#{user2.ap_id},true"
|
||||
end}
|
||||
]) do
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{
|
||||
"list" => %Plug.Upload{path: "follow_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2]
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports new-style mastodon follow lists", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{
|
||||
"list" => "Account address,Show boosts\n#{user2.ap_id},true"
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response == "job started"
|
||||
end
|
||||
|
||||
test "requires 'follow' or 'write:follows' permissions" do
|
||||
token1 = insert(:oauth_token, scopes: ["read", "write"])
|
||||
token2 = insert(:oauth_token, scopes: ["follow"])
|
||||
token3 = insert(:oauth_token, scopes: ["something"])
|
||||
another_user = insert(:user)
|
||||
|
||||
for token <- [token1, token2, token3] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("authorization", "Bearer #{token.token}")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
|
||||
|
||||
if token == token3 do
|
||||
assert %{"error" => "Insufficient permissions: follow | write:follows."} ==
|
||||
json_response(conn, 403)
|
||||
else
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports follows with different nickname variations", %{conn: conn} do
|
||||
users = [user2, user3, user4, user5, user6] = insert_list(5, :user)
|
||||
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
" ",
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/blocks_import" do
|
||||
# Note: "follow" or "write:blocks" permission is required
|
||||
setup do: oauth_access(["write:blocks"])
|
||||
|
||||
test "it returns HTTP 200", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "it imports blocks users from file", %{conn: conn} do
|
||||
users = [user2, user3] = insert_list(2, :user)
|
||||
|
||||
with_mocks([
|
||||
{File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
|
||||
]) do
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{
|
||||
"list" => %Plug.Upload{path: "blocks_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports blocks with different nickname variations", %{conn: conn} do
|
||||
users = [user2, user3, user4, user5, user6] = insert_list(5, :user)
|
||||
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join(" ")
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/mutes_import" do
|
||||
# Note: "follow" or "write:mutes" permission is required
|
||||
setup do: oauth_access(["write:mutes"])
|
||||
|
||||
test "it returns HTTP 200", %{user: user, conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2]
|
||||
assert Pleroma.User.mutes?(user, user2)
|
||||
end
|
||||
|
||||
test "it imports mutes users from file", %{user: user, conn: conn} do
|
||||
users = [user2, user3] = insert_list(2, :user)
|
||||
|
||||
with_mocks([
|
||||
{File, [], read!: fn "mutes_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
|
||||
]) do
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{
|
||||
"list" => %Plug.Upload{path: "mutes_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
assert Enum.all?(users, &Pleroma.User.mutes?(user, &1))
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports mutes with different nickname variations", %{user: user, conn: conn} do
|
||||
users = [user2, user3, user4, user5, user6] = insert_list(5, :user)
|
||||
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join(" ")
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
assert Enum.all?(users, &Pleroma.User.mutes?(user, &1))
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue