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.UserUpdateHandlingTest do
10 alias Pleroma.Web.ActivityPub.Transmogrifier
12 import Pleroma.Factory
14 test "it works for incoming update activities" do
15 user = insert(:user, local: false)
17 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
21 |> Map.put("actor", user.ap_id)
22 |> Map.put("id", user.ap_id)
26 |> Map.put("actor", user.ap_id)
27 |> Map.put("object", object)
29 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
31 assert data["id"] == update_data["id"]
33 user = User.get_cached_by_ap_id(data["actor"])
34 assert user.name == "gargle"
36 assert user.avatar["url"] == [
39 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
43 assert user.banner["url"] == [
46 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
50 assert user.bio == "<p>Some bio</p>"
53 test "it works with alsoKnownAs" do
54 %{ap_id: actor} = insert(:user, local: false)
56 assert User.get_cached_by_ap_id(actor).also_known_as == []
59 "test/fixtures/mastodon-update.json"
62 |> Map.put("actor", actor)
63 |> Map.update!("object", fn object ->
65 |> Map.put("actor", actor)
66 |> Map.put("id", actor)
67 |> Map.put("alsoKnownAs", [
68 "http://mastodon.example.org/users/foo",
69 "http://example.org/users/bar"
72 |> Transmogrifier.handle_incoming()
74 assert User.get_cached_by_ap_id(actor).also_known_as == [
75 "http://mastodon.example.org/users/foo",
76 "http://example.org/users/bar"
80 test "it works with custom profile fields" do
81 user = insert(:user, local: false)
83 assert user.fields == []
85 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
89 |> Map.put("actor", user.ap_id)
90 |> Map.put("id", user.ap_id)
94 |> Map.put("actor", user.ap_id)
95 |> Map.put("object", object)
97 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
99 user = User.get_cached_by_ap_id(user.ap_id)
101 assert user.fields == [
102 %{"name" => "foo", "value" => "updated"},
103 %{"name" => "foo1", "value" => "updated"}
106 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
109 put_in(update_data, ["object", "attachment"], [
110 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
111 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
112 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
115 {:ok, _} = Transmogrifier.handle_incoming(update_data)
117 user = User.get_cached_by_ap_id(user.ap_id)
119 assert user.fields == [
120 %{"name" => "foo", "value" => "updated"},
121 %{"name" => "foo1", "value" => "updated"}
124 update_data = put_in(update_data, ["object", "attachment"], [])
126 {:ok, _} = Transmogrifier.handle_incoming(update_data)
128 user = User.get_cached_by_ap_id(user.ap_id)
130 assert user.fields == []
133 test "it works for incoming update activities which lock the account" do
134 user = insert(:user, local: false)
136 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
139 update_data["object"]
140 |> Map.put("actor", user.ap_id)
141 |> Map.put("id", user.ap_id)
142 |> Map.put("manuallyApprovesFollowers", true)
146 |> Map.put("actor", user.ap_id)
147 |> Map.put("object", object)
149 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
151 user = User.get_cached_by_ap_id(user.ap_id)
152 assert user.locked == true