aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/tesla_mock/lemmy-page.json17
-rw-r--r--test/fixtures/tesla_mock/lemmy-user.json27
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs31
-rw-r--r--test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs (renamed from test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs)6
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs36
-rw-r--r--test/pleroma/web/admin_api/controllers/report_controller_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/user_controller_test.exs126
-rw-r--r--test/pleroma/web/admin_api/search_test.exs4
-rw-r--r--test/pleroma/web/plugs/user_is_staff_plug_test.exs47
9 files changed, 207 insertions, 89 deletions
diff --git a/test/fixtures/tesla_mock/lemmy-page.json b/test/fixtures/tesla_mock/lemmy-page.json
new file mode 100644
index 000000000..f07097a0e
--- /dev/null
+++ b/test/fixtures/tesla_mock/lemmy-page.json
@@ -0,0 +1,17 @@
+{
+ "commentsEnabled": true,
+ "sensitive": false,
+ "stickied": false,
+ "attributedTo": "https://enterprise.lemmy.ml/u/nutomic",
+ "summary": "Hello Federation!",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg",
+ "image": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/lwFAcXHUjS.jpg"
+ },
+ "published": "2020-09-14T15:03:11.909105+00:00",
+ "to": "https://enterprise.lemmy.ml/c/main",
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "https://enterprise.lemmy.ml/post/3",
+ "type": "Page"
+}
diff --git a/test/fixtures/tesla_mock/lemmy-user.json b/test/fixtures/tesla_mock/lemmy-user.json
new file mode 100644
index 000000000..d0e9066ac
--- /dev/null
+++ b/test/fixtures/tesla_mock/lemmy-user.json
@@ -0,0 +1,27 @@
+{
+ "publicKey": {
+ "id": "https://enterprise.lemmy.ml/u/nutomic#main-key",
+ "owner": "https://enterprise.lemmy.ml/u/nutomic",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvfwAYPxp1gOk2HcCRoUd\nupoecvmnpzRc5Gu6/N3YQyOyRsrYuiYLNQq2cgM3kcU80ZeEetkwkYgXkRJOKu/b\nBWb7i1zt2tdr5k6lUdW8dfCyjht8ooFPQdov8J3QYHfgBHyUYxuCNfSujryxx2wu\nLQcdjRQa5NIWcomSO8OXmCF5/Yhg2XWCbtnlxEq6Y+AFddr1mAlTOy5pBr5d+xZz\njLw/U3CioNJ79yGi/sJhgp6IyJqtUSoN3b4BgRIEts2QVvn44W1rQy9wCbRYQrO1\nBcB9Wel4k3rJJK8uHg+LpHVMaZppkNaWGkMBhMbzr8qmIlcNWNi7cbMK/p5vyviy\nSwIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "inbox": "https://enterprise.lemmy.ml/u/nutomic/inbox",
+ "preferredUsername": "Nutomic",
+ "endpoints": {
+ "sharedInbox": "https://enterprise.lemmy.ml/inbox"
+ },
+ "summary": "some bio",
+ "icon": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/F6Z7QcWZRJ.jpg"
+ },
+ "image": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml:/pictrs/image/Q79N9oCDEG.png"
+ },
+ "published": "2020-09-14T14:54:53.080949+00:00",
+ "updated": "2020-10-14T10:58:28.139178+00:00",
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "https://enterprise.lemmy.ml/u/nutomic",
+ "type": "Person",
+ "name": "nutomic"
+}
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
index c7039d1f8..50315e21f 100644
--- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
@@ -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 =
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
index e408c85c3..720c17d8d 100644
--- a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -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
diff --git a/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
new file mode 100644
index 000000000..4ac71e066
--- /dev/null
+++ b/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
@@ -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
diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
index 6a2986b5f..8102845d5 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/admin_api/controllers/user_controller_test.exs b/test/pleroma/web/admin_api/controllers/user_controller_test.exs
index 1a3aa439b..d9da34f6e 100644
--- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/admin_api/search_test.exs b/test/pleroma/web/admin_api/search_test.exs
index b8eeec65b..2335c5228 100644
--- a/test/pleroma/web/admin_api/search_test.exs
+++ b/test/pleroma/web/admin_api/search_test.exs
@@ -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
diff --git a/test/pleroma/web/plugs/user_is_staff_plug_test.exs b/test/pleroma/web/plugs/user_is_staff_plug_test.exs
new file mode 100644
index 000000000..a0c4061db
--- /dev/null
+++ b/test/pleroma/web/plugs/user_is_staff_plug_test.exs
@@ -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