1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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") |> Jason.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") |> Jason.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 clear_config([:instance, :max_remote_account_fields], 2)
110 |> put_in(["object", "attachment"], [
111 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
112 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
113 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
115 |> Map.put("id", update_data["id"] <> ".")
117 {:ok, _} = Transmogrifier.handle_incoming(update_data)
119 user = User.get_cached_by_ap_id(user.ap_id)
121 assert user.fields == [
122 %{"name" => "foo", "value" => "updated"},
123 %{"name" => "foo1", "value" => "updated"}
128 |> put_in(["object", "attachment"], [])
129 |> Map.put("id", update_data["id"] <> ".")
131 {:ok, _} = Transmogrifier.handle_incoming(update_data)
133 user = User.get_cached_by_ap_id(user.ap_id)
135 assert user.fields == []
138 test "it works for incoming update activities which lock the account" do
139 user = insert(:user, local: false)
141 update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
144 update_data["object"]
145 |> Map.put("actor", user.ap_id)
146 |> Map.put("id", user.ap_id)
147 |> Map.put("manuallyApprovesFollowers", true)
151 |> Map.put("actor", user.ap_id)
152 |> Map.put("object", object)
154 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
156 user = User.get_cached_by_ap_id(user.ap_id)
157 assert user.is_locked == true