summaryrefslogtreecommitdiff
path: root/test/pleroma
diff options
context:
space:
mode:
Diffstat (limited to 'test/pleroma')
-rw-r--r--test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs11
-rw-r--r--test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs59
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs11
-rw-r--r--test/pleroma/web/admin_api/controllers/report_controller_test.exs1
4 files changed, 82 insertions, 0 deletions
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
index 949b1339a..ed8a2412b 100644
--- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -62,4 +62,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
assert cng.valid?
assert cng.changes.quoteUrl == "https://misskey.io/notes/8vs6wxufd0"
end
+
+ test "a Note from Roadhouse validates" do
+ insert(:user, ap_id: "https://macgirvin.com/channel/mike")
+
+ %{"object" => note} =
+ "test/fixtures/roadhouse-create-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
+ end
end
diff --git a/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs
new file mode 100644
index 000000000..c3e6854e4
--- /dev/null
+++ b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs
@@ -0,0 +1,59 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidatorTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.Web.ActivityPub.ObjectValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator
+ alias Pleroma.Web.ActivityPub.Utils
+
+ import Pleroma.Factory
+
+ test "a Create/Note from Roadhouse validates" do
+ insert(:user, ap_id: "https://macgirvin.com/channel/mike")
+
+ note_activity =
+ "test/fixtures/roadhouse-create-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ # Build metadata
+ {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"])
+ meta = [object_data: ObjectValidator.stringify_keys(object_data)]
+
+ %{valid?: true} = CreateGenericValidator.cast_and_validate(note_activity, meta)
+ end
+
+ test "a Create/Note with mismatched context is invalid" do
+ user = insert(:user)
+
+ note = %{
+ "id" => Utils.generate_object_id(),
+ "type" => "Note",
+ "actor" => user.ap_id,
+ "to" => [user.follower_address],
+ "cc" => [],
+ "content" => "Hello world",
+ "context" => Utils.generate_context_id()
+ }
+
+ note_activity = %{
+ "id" => Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => note["actor"],
+ "to" => note["to"],
+ "cc" => note["cc"],
+ "object" => note,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => Utils.generate_context_id()
+ }
+
+ # Build metadata
+ {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"])
+ meta = [object_data: ObjectValidator.stringify_keys(object_data)]
+
+ %{valid?: false} = CreateGenericValidator.cast_and_validate(note_activity, meta)
+ end
+end
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 388d59faf..0d338ec2b 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -129,6 +129,17 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
# It fetched the quoted post
assert Object.normalize("https://misskey.io/notes/8vs6wxufd0")
end
+
+ test "a reply with mismatched context is rejected" do
+ insert(:user, ap_id: "https://macgirvin.com/channel/mike")
+
+ note_activity =
+ "test/fixtures/roadhouse-create-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ assert {:error, _} = Transmogrifier.handle_incoming(note_activity)
+ end
end
describe "prepare outgoing" do
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 99cc7bbd0..802a8c05f 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
@@ -355,6 +355,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
} = note
end
+ @tag :erratic
test "it returns reports with notes", %{conn: conn, admin: admin} do
conn = get(conn, "/api/pleroma/admin/reports")