Merge branch 'develop' into issue/2099
This commit is contained in:
commit
2ec0dcf001
62 changed files with 1421 additions and 159 deletions
1
test/fixtures/custom_instance_panel.html
vendored
Normal file
1
test/fixtures/custom_instance_panel.html
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
<h2>Custom instance panel</h2>
|
||||
|
|
@ -1,20 +1,24 @@
|
|||
{
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", {
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"movedTo": "as:movedTo",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"Emoji": "toot:Emoji",
|
||||
"alsoKnownAs": {
|
||||
"@id": "as:alsoKnownAs",
|
||||
"@type": "@id"
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"movedTo": "as:movedTo",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"Emoji": "toot:Emoji",
|
||||
"alsoKnownAs": {
|
||||
"@id": "as:alsoKnownAs",
|
||||
"@type": "@id"
|
||||
}
|
||||
}
|
||||
}],
|
||||
],
|
||||
"id": "http://mastodon.example.org/users/admin",
|
||||
"type": "Person",
|
||||
"following": "http://mastodon.example.org/users/admin/following",
|
||||
|
|
@ -23,6 +27,7 @@
|
|||
"outbox": "http://mastodon.example.org/users/admin/outbox",
|
||||
"preferredUsername": "admin",
|
||||
"name": null,
|
||||
"discoverable": "true",
|
||||
"summary": "\u003cp\u003e\u003c/p\u003e",
|
||||
"url": "http://mastodon.example.org/@admin",
|
||||
"manuallyApprovesFollowers": false,
|
||||
|
|
@ -34,7 +39,8 @@
|
|||
"owner": "http://mastodon.example.org/users/admin",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"attachment": [{
|
||||
"attachment": [
|
||||
{
|
||||
"type": "PropertyValue",
|
||||
"name": "foo",
|
||||
"value": "bar"
|
||||
|
|
@ -58,5 +64,7 @@
|
|||
"mediaType": "image/png",
|
||||
"url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
},
|
||||
"alsoKnownAs": ["http://example.org/users/foo"]
|
||||
}
|
||||
"alsoKnownAs": [
|
||||
"http://example.org/users/foo"
|
||||
]
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
"preferredUsername": "mike",
|
||||
"name": "Mike Macgirvin (Osada)",
|
||||
"updated": "2018-08-29T03:09:11Z",
|
||||
"discoverable": "true",
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
|
|
@ -51,4 +52,4 @@
|
|||
"created": "2018-10-17T07:16:28Z",
|
||||
"signatureValue": "WbfFVIPImkd3yNu6brz0CvZaeV242rwAbH0vy8DM4vfnXCxLr5Uv/Wj9gwP+tbooTxGaahAKBeqlGkQp8RLEo37LATrKMRLA/0V6DeeV+C5ORWR9B4WxyWiD3s/9Wf+KesFMtktNLAcMZ5PfnOS/xNYerhnpkp/gWPxtkglmLIWJv+w18A5zZ01JCxsO4QljHbhYaEUPHUfQ97abrkLECeam+FThVwdO6BFCtbjoNXHfzjpSZL/oKyBpi5/fpnqMqOLOQPs5WgBBZJvjEYYkQcoPTyxYI5NGpNbzIjGHPQNuACnOelH16A7L+q4swLWDIaEFeXQ2/5bmqVKZDZZ6usNP4QyTVszwd8jqo27qcDTNibXDUTsTdKpNQvM/3UncBuzuzmUV3FczhtGshIU1/pRVZiQycpVqPlGLvXhP/yZCe+1siyqDd+3uMaS2vkHTObSl5r+VYof+c+TcjrZXHSWnQTg8/X3zkoBWosrQ93VZcwjzMxQoARYv6rphbOoTz7RPmGAXYUt3/PDWkqDlmQDwCpLNNkJo1EidyefZBdD9HXQpCBO0ZU0NHb0JmPvg/+zU0krxlv70bm3RHA/maBETVjroIWzt7EwQEg5pL2hVnvSBG+1wF3BtRVe77etkPOHxLnYYIcAMLlVKCcgDd89DPIziQyruvkx1busHI08="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ defmodule Pleroma.Factory do
|
|||
nickname: sequence(:nickname, &"nick#{&1}"),
|
||||
password_hash: Pbkdf2.hash_pwd_salt("test"),
|
||||
bio: sequence(:bio, &"Tester Number #{&1}"),
|
||||
discoverable: true,
|
||||
last_digest_emailed_at: NaiveDateTime.utc_now(),
|
||||
last_refreshed_at: NaiveDateTime.utc_now(),
|
||||
notification_settings: %Pleroma.User.NotificationSetting{},
|
||||
|
|
|
|||
|
|
@ -40,6 +40,19 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "config migration refused when deprecated settings are found" do
|
||||
clear_config([:media_proxy, :whitelist], ["domain_without_scheme.com"])
|
||||
assert Repo.all(ConfigDB) == []
|
||||
|
||||
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||
|
||||
assert_received {:mix_shell, :error, [message]}
|
||||
|
||||
assert message =~
|
||||
"Migration is not allowed until all deprecation warnings have been resolved."
|
||||
end
|
||||
|
||||
test "filtered settings are migrated to db" do
|
||||
assert Repo.all(ConfigDB) == []
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ defmodule Pleroma.UserSearchTest do
|
|||
assert found_user.id == user.id
|
||||
end
|
||||
|
||||
test "excludes users when discoverable is false" do
|
||||
insert(:user, %{nickname: "john 3000", discoverable: false})
|
||||
insert(:user, %{nickname: "john 3001"})
|
||||
|
||||
users = User.search("john")
|
||||
assert Enum.count(users) == 1
|
||||
end
|
||||
|
||||
test "excludes service actors from results" do
|
||||
insert(:user, actor_type: "Application", nickname: "user1")
|
||||
service = insert(:user, actor_type: "Service", nickname: "user2")
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[filter: fn o -> {:ok, o} end]
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
|
|
@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[filter: fn o -> {:ok, o} end]
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
assert_called(Pleroma.Web.Federator.publish(activity))
|
||||
|
|
@ -109,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[filter: fn o -> {:ok, o} end]
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
|
|
@ -131,7 +131,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
|
|
@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[filter: fn o -> {:ok, o} end]
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
|
|
@ -170,7 +170,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1510,6 +1510,56 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/:nickname/chats" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipients = insert_list(3, :user)
|
||||
|
||||
Enum.each(recipients, fn recipient ->
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
end)
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
|
||||
test "renders user's chats", %{conn: conn, user: user} do
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/chats")
|
||||
|
||||
assert json_response(conn, 200) |> length() == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/:nickname/chats unauthorized" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
%{conn: conn} = oauth_access(["read:chats"])
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
||||
test "returns 403", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/chats")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/:nickname/chats unauthenticated" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
%{conn: build_conn(), user: user}
|
||||
end
|
||||
|
||||
test "returns 403", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/chats")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/moderation_log" do
|
||||
setup do
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
|
|
|
|||
219
test/web/admin_api/controllers/chat_controller_test.exs
Normal file
219
test/web/admin_api/controllers/chat_controller_test.exs
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
defp admin_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
|
||||
|
||||
describe "DELETE /api/pleroma/admin/chats/:id/messages/:message_id" do
|
||||
setup do: admin_setup()
|
||||
|
||||
test "it deletes a message from the chat", %{conn: conn, admin: admin} do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
{:ok, message} =
|
||||
CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend")
|
||||
|
||||
object = Object.normalize(message, false)
|
||||
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
recipient_chat = Chat.get(recipient.id, user.ap_id)
|
||||
|
||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||
recipient_cm_ref = MessageReference.for_chat_and_object(recipient_chat, object)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/pleroma/admin/chats/#{chat.id}/messages/#{cm_ref.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted chat message ##{cm_ref.id}"
|
||||
|
||||
assert result["id"] == cm_ref.id
|
||||
refute MessageReference.get_by_id(cm_ref.id)
|
||||
refute MessageReference.get_by_id(recipient_cm_ref.id)
|
||||
assert %{data: %{"type" => "Tombstone"}} = Object.get_by_id(object.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/chats/:id/messages" do
|
||||
setup do: admin_setup()
|
||||
|
||||
test "it paginates", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
Enum.each(1..30, fn _ ->
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, recipient, "hey")
|
||||
end)
|
||||
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 20
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages?max_id=#{List.last(result)["id"]}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 10
|
||||
end
|
||||
|
||||
test "it returns the messages for a given chat", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, other_user, "hey")
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, third_user, "hey")
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, other_user, "how are you?")
|
||||
{:ok, _} = CommonAPI.post_chat_message(other_user, user, "fine, how about you?")
|
||||
|
||||
chat = Chat.get(user.id, other_user.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
result
|
||||
|> Enum.each(fn message ->
|
||||
assert message["chat_id"] == chat.id |> to_string()
|
||||
end)
|
||||
|
||||
assert length(result) == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/chats/:id" do
|
||||
setup do: admin_setup()
|
||||
|
||||
test "it returns a chat", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert result["id"] == to_string(chat.id)
|
||||
assert %{} = result["sender"]
|
||||
assert %{} = result["receiver"]
|
||||
refute result["account"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "unauthorized chat moderation" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
{:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo")
|
||||
object = Object.normalize(message, false)
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||
|
||||
%{conn: conn} = oauth_access(["read:chats", "write:chats"])
|
||||
%{conn: conn, chat: chat, cm_ref: cm_ref}
|
||||
end
|
||||
|
||||
test "DELETE /api/pleroma/admin/chats/:id/messages/:message_id", %{
|
||||
conn: conn,
|
||||
chat: chat,
|
||||
cm_ref: cm_ref
|
||||
} do
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/pleroma/admin/chats/#{chat.id}/messages/#{cm_ref.id}")
|
||||
|> json_response(403)
|
||||
|
||||
assert MessageReference.get_by_id(cm_ref.id) == cm_ref
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/chats/:id/messages", %{conn: conn, chat: chat} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/chats/:id", %{conn: conn, chat: chat} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "unauthenticated chat moderation" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
{:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo")
|
||||
object = Object.normalize(message, false)
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||
|
||||
%{conn: build_conn(), chat: chat, cm_ref: cm_ref}
|
||||
end
|
||||
|
||||
test "DELETE /api/pleroma/admin/chats/:id/messages/:message_id", %{
|
||||
conn: conn,
|
||||
chat: chat,
|
||||
cm_ref: cm_ref
|
||||
} do
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/pleroma/admin/chats/#{chat.id}/messages/#{cm_ref.id}")
|
||||
|> json_response(403)
|
||||
|
||||
assert MessageReference.get_by_id(cm_ref.id) == cm_ref
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/chats/:id/messages", %{conn: conn, chat: chat} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/chats/:id", %{conn: conn, chat: chat} do
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.InstanceDocumentControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Config
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
@default_instance_panel ~s(<p>Welcome to <a href="https://pleroma.social" target="_blank">Pleroma!</a></p>)
|
||||
|
||||
setup do
|
||||
File.mkdir_p!(@dir)
|
||||
on_exit(fn -> File.rm_rf(@dir) end)
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :static_dir], @dir)
|
||||
|
||||
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
|
||||
|
||||
describe "GET /api/pleroma/admin/instance_document/:name" do
|
||||
test "return the instance document url", %{conn: conn} do
|
||||
conn = get(conn, "/api/pleroma/admin/instance_document/instance-panel")
|
||||
|
||||
assert content = html_response(conn, 200)
|
||||
assert String.contains?(content, @default_instance_panel)
|
||||
end
|
||||
|
||||
test "it returns 403 if requested by a non-admin" do
|
||||
non_admin_user = insert(:user)
|
||||
token = insert(:oauth_token, user: non_admin_user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, non_admin_user)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/instance_document/instance-panel")
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
|
||||
test "it returns 404 if the instance document with the given name doesn't exist", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn = get(conn, "/api/pleroma/admin/instance_document/1234")
|
||||
|
||||
assert json_response_and_validate_schema(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/pleroma/admin/instance_document/:name" do
|
||||
test "uploads the instance document", %{conn: conn} do
|
||||
image = %Plug.Upload{
|
||||
content_type: "text/html",
|
||||
path: Path.absname("test/fixtures/custom_instance_panel.html"),
|
||||
filename: "custom_instance_panel.html"
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/pleroma/admin/instance_document/instance-panel", %{
|
||||
"file" => image
|
||||
})
|
||||
|
||||
assert %{"url" => url} = json_response_and_validate_schema(conn, 200)
|
||||
index = get(build_conn(), url)
|
||||
assert html_response(index, 200) == "<h2>Custom instance panel</h2>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /api/pleroma/admin/instance_document/:name" do
|
||||
test "deletes the instance document", %{conn: conn} do
|
||||
File.mkdir!(@dir <> "/instance/")
|
||||
File.write!(@dir <> "/instance/panel.html", "Custom instance panel")
|
||||
|
||||
conn_resp =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/instance_document/instance-panel")
|
||||
|
||||
assert html_response(conn_resp, 200) == "Custom instance panel"
|
||||
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/instance_document/instance-panel")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
conn_resp =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/instance_document/instance-panel")
|
||||
|
||||
assert content = html_response(conn_resp, 200)
|
||||
assert String.contains?(content, @default_instance_panel)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -177,5 +177,14 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
assert total == 3
|
||||
assert count == 1
|
||||
end
|
||||
|
||||
test "it returns non-discoverable users" do
|
||||
insert(:user)
|
||||
insert(:user, discoverable: false)
|
||||
|
||||
{:ok, _results, total} = Search.user()
|
||||
|
||||
assert total == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -217,6 +217,17 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert message == :content_too_long
|
||||
end
|
||||
|
||||
test "it reject messages via MRF" do
|
||||
clear_config([:mrf_keyword, :reject], ["GNO"])
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
|
||||
author = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} ==
|
||||
CommonAPI.post_chat_message(author, recipient, "GNO/Linux")
|
||||
end
|
||||
end
|
||||
|
||||
describe "unblocking" do
|
||||
|
|
@ -1193,4 +1204,24 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert Visibility.get_visibility(activity) == "private"
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_user/1" do
|
||||
test "gets user by ap_id" do
|
||||
user = insert(:user)
|
||||
assert CommonAPI.get_user(user.ap_id) == user
|
||||
end
|
||||
|
||||
test "gets user by guessed nickname" do
|
||||
user = insert(:user, ap_id: "", nickname: "mario@mushroom.kingdom")
|
||||
assert CommonAPI.get_user("https://mushroom.kingdom/users/mario") == user
|
||||
end
|
||||
|
||||
test "fallback" do
|
||||
assert %User{
|
||||
name: "",
|
||||
ap_id: "",
|
||||
nickname: "erroruser@example.com"
|
||||
} = CommonAPI.get_user("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
sensitive: false,
|
||||
pleroma: %{
|
||||
actor_type: "Person",
|
||||
discoverable: false
|
||||
discoverable: true
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
|
|
@ -166,7 +166,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
sensitive: false,
|
||||
pleroma: %{
|
||||
actor_type: "Service",
|
||||
discoverable: false
|
||||
discoverable: true
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,7 +16,14 @@ defmodule Pleroma.Web.MetadataTest do
|
|||
end
|
||||
|
||||
test "for local user" do
|
||||
user = insert(:user)
|
||||
user = insert(:user, discoverable: false)
|
||||
|
||||
assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~
|
||||
"<meta content=\"noindex, noarchive\" name=\"robots\">"
|
||||
end
|
||||
|
||||
test "for local user set to discoverable" do
|
||||
user = insert(:user, discoverable: true)
|
||||
|
||||
refute Pleroma.Web.Metadata.build_tags(%{user: user}) =~
|
||||
"<meta content=\"noindex, noarchive\" name=\"robots\">"
|
||||
|
|
@ -24,11 +31,19 @@ defmodule Pleroma.Web.MetadataTest do
|
|||
end
|
||||
|
||||
describe "no metadata for private instances" do
|
||||
test "for local user" do
|
||||
test "for local user set to discoverable" do
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio")
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", discoverable: true)
|
||||
|
||||
assert "" = Pleroma.Web.Metadata.build_tags(%{user: user})
|
||||
end
|
||||
|
||||
test "search exclusion metadata is included" do
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", discoverable: false)
|
||||
|
||||
assert ~s(<meta content="noindex, noarchive" name="robots">) ==
|
||||
Pleroma.Web.Metadata.build_tags(%{user: user})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,8 +14,14 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do
|
|||
|
||||
test "for local user" do
|
||||
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
|
||||
user: %Pleroma.User{local: true}
|
||||
user: %Pleroma.User{local: true, discoverable: true}
|
||||
}) == []
|
||||
end
|
||||
|
||||
test "for local user when discoverable is false" do
|
||||
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
|
||||
user: %Pleroma.User{local: true, discoverable: false}
|
||||
}) == [{:meta, [name: "robots", content: "noindex, noarchive"], []}]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue