1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
10 alias Pleroma.Activity
13 alias Pleroma.Web.ActivityPub.Transmogrifier
15 describe "handle_incoming" do
16 test "it rejects messages that don't contain content" do
18 File.read!("test/fixtures/create-chat-message.json")
23 |> Map.delete("content")
27 |> Map.put("object", object)
29 _author = insert(:user, ap_id: data["actor"], local: false)
30 _recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
32 {:error, _} = Transmogrifier.handle_incoming(data)
35 test "it rejects messages that don't concern local users" do
37 File.read!("test/fixtures/create-chat-message.json")
40 _author = insert(:user, ap_id: data["actor"], local: false)
41 _recipient = insert(:user, ap_id: List.first(data["to"]), local: false)
43 {:error, _} = Transmogrifier.handle_incoming(data)
46 test "it rejects messages where the `to` field of activity and object don't match" do
48 File.read!("test/fixtures/create-chat-message.json")
51 author = insert(:user, ap_id: data["actor"])
52 _recipient = insert(:user, ap_id: List.first(data["to"]))
56 |> Map.put("to", author.ap_id)
58 {:error, _} = Transmogrifier.handle_incoming(data)
61 test "it inserts it and creates a chat" do
63 File.read!("test/fixtures/create-chat-message.json")
66 author = insert(:user, ap_id: data["actor"], local: false)
67 recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
69 {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(data)
71 assert activity.actor == author.ap_id
72 assert activity.recipients == [recipient.ap_id, author.ap_id]
74 %Object{} = object = Object.get_by_ap_id(activity.data["object"])
77 assert object.data["content"] == "You expected a cute girl? Too bad. alert('XSS')"
79 refute Chat.get(author.id, recipient.ap_id)
80 assert Chat.get(recipient.id, author.ap_id)