Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remove/mastofe
This commit is contained in:
commit
1841bd8383
24 changed files with 323 additions and 219 deletions
|
|
@ -1334,9 +1334,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
activity: %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "content" => "AP C2S test"},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "AP C2S test",
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
}
|
||||
]
|
||||
end
|
||||
|
|
@ -1442,19 +1445,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
data = %{
|
||||
type: "Delete",
|
||||
object: %{
|
||||
id: note_object.data["id"]
|
||||
"type" => "Delete",
|
||||
"object" => %{
|
||||
"id" => note_object.data["id"]
|
||||
}
|
||||
}
|
||||
|
||||
conn =
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> json_response(201)
|
||||
|
||||
result = json_response(conn, 201)
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
|
||||
assert object = Object.get_by_ap_id(note_object.data["id"])
|
||||
|
|
@ -1479,7 +1482,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|
||||
assert json_response(conn, 400)
|
||||
assert json_response(conn, 403)
|
||||
end
|
||||
|
||||
test "it increases like count when receiving a like action", %{conn: conn} do
|
||||
|
|
@ -1557,7 +1560,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(400)
|
||||
|
||||
assert result == "Note is over the character limit"
|
||||
assert result == "Character limit (5 characters) exceeded, contains 11 characters"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1934,10 +1937,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "AP C2S test, attachment",
|
||||
"attachment" => [object]
|
||||
},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
"attachment" => [object],
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
}
|
||||
|
||||
activity_response =
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
|
|||
end
|
||||
|
||||
test "a basic note validates", %{note: note} do
|
||||
%{valid?: true} = ArticleNoteValidator.cast_and_validate(note)
|
||||
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.PageHandlingTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Object.Fetcher
|
||||
|
||||
test "Lemmy Page" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "https://enterprise.lemmy.ml/post/3"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/lemmy-page.json")
|
||||
}
|
||||
|
||||
%{url: "https://enterprise.lemmy.ml/u/nutomic"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/lemmy-user.json")
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, object} = Fetcher.fetch_object_from_id("https://enterprise.lemmy.ml/post/3")
|
||||
|
||||
assert object.data["summary"] == "Hello Federation!"
|
||||
assert object.data["published"] == "2020-09-14T15:03:11.909105Z"
|
||||
|
||||
# WAT
|
||||
assert object.data["url"] == "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg"
|
||||
end
|
||||
end
|
||||
|
|
@ -305,7 +305,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|> get("/api/pleroma/admin/reports")
|
||||
|
||||
assert json_response(conn, :forbidden) ==
|
||||
%{"error" => "User is not an admin."}
|
||||
%{"error" => "User is not a staff member."}
|
||||
end
|
||||
|
||||
test "returns 403 when requested by anonymous" do
|
||||
|
|
|
|||
|
|
@ -384,24 +384,22 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(
|
||||
admin,
|
||||
%{"roles" => %{"admin" => true, "moderator" => false}}
|
||||
),
|
||||
user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
|
||||
user_response(
|
||||
user2,
|
||||
%{
|
||||
"local" => true,
|
||||
"is_approved" => false,
|
||||
"registration_reason" => "I'm a chill dude",
|
||||
"actor_type" => "Person"
|
||||
}
|
||||
)
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(
|
||||
user2,
|
||||
%{
|
||||
"local" => true,
|
||||
"is_approved" => false,
|
||||
"registration_reason" => "I'm a chill dude",
|
||||
"actor_type" => "Person"
|
||||
}
|
||||
),
|
||||
user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
|
||||
user_response(
|
||||
admin,
|
||||
%{"roles" => %{"admin" => true, "moderator" => false}}
|
||||
)
|
||||
]
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 3,
|
||||
|
|
@ -525,7 +523,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
assert json_response_and_validate_schema(conn1, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user)]
|
||||
"users" => [user_response(user2)]
|
||||
}
|
||||
|
||||
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
||||
|
|
@ -533,7 +531,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
assert json_response_and_validate_schema(conn2, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user2)]
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -565,18 +563,16 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=local")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(user),
|
||||
user_response(admin, %{
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(old_admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(user),
|
||||
user_response(admin, %{
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(old_admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 3,
|
||||
|
|
@ -604,7 +600,6 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
"is_approved" => true
|
||||
})
|
||||
end)
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert result == %{"count" => 2, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
|
@ -642,18 +637,16 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(second_admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(second_admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(admin, %{
|
||||
"is_active" => true,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 2,
|
||||
|
|
@ -693,13 +686,11 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> get(user_path(conn, :index), %{actor_types: ["Person"]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
||||
user_response(user1),
|
||||
user_response(user2)
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(user2),
|
||||
user_response(user1),
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
|
||||
]
|
||||
|
||||
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
|
@ -716,14 +707,12 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
||||
user_response(user1),
|
||||
user_response(user2),
|
||||
user_response(user_service, %{"actor_type" => "Service"})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(user2),
|
||||
user_response(user1),
|
||||
user_response(user_service, %{"actor_type" => "Service"}),
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
|
||||
]
|
||||
|
||||
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
|
@ -752,12 +741,10 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(user1, %{"tags" => ["first"]}),
|
||||
user_response(user2, %{"tags" => ["second"]})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
users = [
|
||||
user_response(user2, %{"tags" => ["second"]}),
|
||||
user_response(user1, %{"tags" => ["first"]})
|
||||
]
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 2,
|
||||
|
|
@ -781,8 +768,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{"id" => ^admin_id},
|
||||
%{"id" => ^user_id}
|
||||
%{"id" => ^user_id},
|
||||
%{"id" => ^admin_id}
|
||||
]
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
|
@ -921,7 +908,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
"is_approved" => true,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil,
|
||||
"actor_type" => "Person"
|
||||
"actor_type" => "Person",
|
||||
"created_at" => CommonAPI.Utils.to_masto_date(user.inserted_at)
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -151,9 +151,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
|
||||
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
|
||||
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
|
||||
{:ok, [^user1, ^user2], 2} = Search.user(%{actor_types: ["Person"]})
|
||||
{:ok, [^user2, ^user1], 2} = Search.user(%{actor_types: ["Person"]})
|
||||
|
||||
{:ok, [^user_service, ^user1, ^user2], 3} =
|
||||
{:ok, [^user2, ^user1, ^user_service], 3} =
|
||||
Search.user(%{actor_types: ["Person", "Service"]})
|
||||
end
|
||||
|
||||
|
|
|
|||
47
test/pleroma/web/plugs/user_is_staff_plug_test.exs
Normal file
47
test/pleroma/web/plugs/user_is_staff_plug_test.exs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.UserIsStaffPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.Plugs.UserIsStaffPlug
|
||||
import Pleroma.Factory
|
||||
|
||||
test "accepts a user that is an admin" do
|
||||
user = insert(:user, is_admin: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = UserIsStaffPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "accepts a user that is a moderator" do
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = UserIsStaffPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "denies a user that isn't a staff member" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> UserIsStaffPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies when a user isn't set" do
|
||||
conn = UserIsStaffPlug.call(build_conn(), %{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue