aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-04-28 16:26:19 +0200
committerlain <lain@soykaf.club>2020-04-28 16:26:19 +0200
commit6aa116eca7d6ef6567dcef03b8c776bd2134bf3f (patch)
tree60d1a53c276f03a01db4a8f095b666f5b9485afe /test
parentb5dc59c8fa587b4db844c7fc0ba16e5cb00bfd38 (diff)
downloadpleroma-6aa116eca7d6ef6567dcef03b8c776bd2134bf3f.tar.gz
Create activity handling: Flip it and reverse it
Both objects and create activities will now go through the common pipeline and will be validated. Objects are now created as a side effect of the Create activity, rolling back a transaction if it's not possible to insert the object.
Diffstat (limited to 'test')
-rw-r--r--test/web/activity_pub/object_validators/types/safe_text_test.exs23
-rw-r--r--test/web/activity_pub/side_effects_test.exs21
-rw-r--r--test/web/activity_pub/transmogrifier/chat_message_test.exs3
3 files changed, 37 insertions, 10 deletions
diff --git a/test/web/activity_pub/object_validators/types/safe_text_test.exs b/test/web/activity_pub/object_validators/types/safe_text_test.exs
new file mode 100644
index 000000000..59ed0a1fe
--- /dev/null
+++ b/test/web/activity_pub/object_validators/types/safe_text_test.exs
@@ -0,0 +1,23 @@
+# 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.ObjectValidators.Types.SafeTextTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeText
+
+ test "it lets normal text go through" do
+ text = "hey how are you"
+ assert {:ok, text} == SafeText.cast(text)
+ end
+
+ test "it removes html tags from text" do
+ text = "hey look xss <script>alert('foo')</script>"
+ assert {:ok, "hey look xss alert(&#39;foo&#39;)"} == SafeText.cast(text)
+ end
+
+ test "errors for non-text" do
+ assert :error == SafeText.cast(1)
+ end
+end
diff --git a/test/web/activity_pub/side_effects_test.exs b/test/web/activity_pub/side_effects_test.exs
index 2889a577c..19abac6a6 100644
--- a/test/web/activity_pub/side_effects_test.exs
+++ b/test/web/activity_pub/side_effects_test.exs
@@ -47,14 +47,14 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
recipient = insert(:user, local: true)
{:ok, chat_message_data, _meta} = Builder.chat_message(author, recipient.ap_id, "hey")
- {:ok, chat_message_object} = Object.create(chat_message_data)
{:ok, create_activity_data, _meta} =
- Builder.create(author, chat_message_object.data["id"], [recipient.ap_id])
+ Builder.create(author, chat_message_data["id"], [recipient.ap_id])
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
- {:ok, _create_activity, _meta} = SideEffects.handle(create_activity)
+ {:ok, _create_activity, _meta} =
+ SideEffects.handle(create_activity, local: false, object_data: chat_message_data)
assert Repo.get_by(Notification, user_id: recipient.id, activity_id: create_activity.id)
end
@@ -64,14 +64,17 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
recipient = insert(:user, local: true)
{:ok, chat_message_data, _meta} = Builder.chat_message(author, recipient.ap_id, "hey")
- {:ok, chat_message_object} = Object.create(chat_message_data)
{:ok, create_activity_data, _meta} =
- Builder.create(author, chat_message_object.data["id"], [recipient.ap_id])
+ Builder.create(author, chat_message_data["id"], [recipient.ap_id])
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
- {:ok, _create_activity, _meta} = SideEffects.handle(create_activity)
+ {:ok, _create_activity, _meta} =
+ SideEffects.handle(create_activity, local: false, object_data: chat_message_data)
+
+ # An object is created
+ assert Object.get_by_ap_id(chat_message_data["id"])
# The remote user won't get a chat
chat = Chat.get(author.id, recipient.ap_id)
@@ -85,14 +88,14 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
recipient = insert(:user, local: true)
{:ok, chat_message_data, _meta} = Builder.chat_message(author, recipient.ap_id, "hey")
- {:ok, chat_message_object} = Object.create(chat_message_data)
{:ok, create_activity_data, _meta} =
- Builder.create(author, chat_message_object.data["id"], [recipient.ap_id])
+ Builder.create(author, chat_message_data["id"], [recipient.ap_id])
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
- {:ok, _create_activity, _meta} = SideEffects.handle(create_activity)
+ {:ok, _create_activity, _meta} =
+ SideEffects.handle(create_activity, local: false, object_data: chat_message_data)
# Both users are local and get the chat
chat = Chat.get(author.id, recipient.ap_id)
diff --git a/test/web/activity_pub/transmogrifier/chat_message_test.exs b/test/web/activity_pub/transmogrifier/chat_message_test.exs
index a63a31e6e..ceaee614c 100644
--- a/test/web/activity_pub/transmogrifier/chat_message_test.exs
+++ b/test/web/activity_pub/transmogrifier/chat_message_test.exs
@@ -55,7 +55,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
data
|> Map.put("to", author.ap_id)
- {:error, _} = Transmogrifier.handle_incoming(data)
+ assert match?({:error, _}, Transmogrifier.handle_incoming(data))
+ refute Object.get_by_ap_id(data["object"]["id"])
end
test "it inserts it and creates a chat" do