1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserTest do
7 alias Pleroma.Builders.UserBuilder
10 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.CommonAPI
16 use Oban.Testing, repo: Pleroma.Repo
19 import Pleroma.Factory
22 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
26 clear_config([:instance, :account_activation_required])
28 describe "when tags are nil" do
29 test "tagging a user" do
30 user = insert(:user, %{tags: nil})
31 user = User.tag(user, ["cool", "dude"])
33 assert "cool" in user.tags
34 assert "dude" in user.tags
37 test "untagging a user" do
38 user = insert(:user, %{tags: nil})
39 user = User.untag(user, ["cool", "dude"])
41 assert user.tags == []
45 test "ap_id returns the activity pub id for the user" do
46 user = UserBuilder.build()
48 expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
50 assert expected_ap_id == User.ap_id(user)
53 test "ap_followers returns the followers collection for the user" do
54 user = UserBuilder.build()
56 expected_followers_collection = "#{User.ap_id(user)}/followers"
58 assert expected_followers_collection == User.ap_followers(user)
61 test "ap_following returns the following collection for the user" do
62 user = UserBuilder.build()
64 expected_followers_collection = "#{User.ap_id(user)}/following"
66 assert expected_followers_collection == User.ap_following(user)
69 test "returns all pending follow requests" do
70 unlocked = insert(:user)
71 locked = insert(:user, %{info: %{locked: true}})
72 follower = insert(:user)
74 CommonAPI.follow(follower, unlocked)
75 CommonAPI.follow(follower, locked)
77 assert [] = User.get_follow_requests(unlocked)
78 assert [activity] = User.get_follow_requests(locked)
83 test "doesn't return already accepted or duplicate follow requests" do
84 locked = insert(:user, %{info: %{locked: true}})
85 pending_follower = insert(:user)
86 accepted_follower = insert(:user)
88 CommonAPI.follow(pending_follower, locked)
89 CommonAPI.follow(pending_follower, locked)
90 CommonAPI.follow(accepted_follower, locked)
91 User.follow(accepted_follower, locked)
93 assert [activity] = User.get_follow_requests(locked)
97 test "clears follow requests when requester is blocked" do
98 followed = insert(:user, %{info: %{locked: true}})
99 follower = insert(:user)
101 CommonAPI.follow(follower, followed)
102 assert [_activity] = User.get_follow_requests(followed)
104 {:ok, _follower} = User.block(followed, follower)
105 assert [] = User.get_follow_requests(followed)
108 test "follow_all follows mutliple users" do
110 followed_zero = insert(:user)
111 followed_one = insert(:user)
112 followed_two = insert(:user)
113 blocked = insert(:user)
114 not_followed = insert(:user)
115 reverse_blocked = insert(:user)
117 {:ok, user} = User.block(user, blocked)
118 {:ok, reverse_blocked} = User.block(reverse_blocked, user)
120 {:ok, user} = User.follow(user, followed_zero)
122 {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
124 assert User.following?(user, followed_one)
125 assert User.following?(user, followed_two)
126 assert User.following?(user, followed_zero)
127 refute User.following?(user, not_followed)
128 refute User.following?(user, blocked)
129 refute User.following?(user, reverse_blocked)
132 test "follow_all follows mutliple users without duplicating" do
134 followed_zero = insert(:user)
135 followed_one = insert(:user)
136 followed_two = insert(:user)
138 {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
139 assert length(user.following) == 3
141 {:ok, user} = User.follow_all(user, [followed_one, followed_two])
142 assert length(user.following) == 4
145 test "follow takes a user and another user" do
147 followed = insert(:user)
149 {:ok, user} = User.follow(user, followed)
151 user = User.get_cached_by_id(user.id)
153 followed = User.get_cached_by_ap_id(followed.ap_id)
154 assert followed.info.follower_count == 1
156 assert User.ap_followers(followed) in user.following
159 test "can't follow a deactivated users" do
161 followed = insert(:user, info: %{deactivated: true})
163 {:error, _} = User.follow(user, followed)
166 test "can't follow a user who blocked us" do
167 blocker = insert(:user)
168 blockee = insert(:user)
170 {:ok, blocker} = User.block(blocker, blockee)
172 {:error, _} = User.follow(blockee, blocker)
175 test "can't subscribe to a user who blocked us" do
176 blocker = insert(:user)
177 blocked = insert(:user)
179 {:ok, blocker} = User.block(blocker, blocked)
181 {:error, _} = User.subscribe(blocked, blocker)
184 test "local users do not automatically follow local locked accounts" do
185 follower = insert(:user, info: %{locked: true})
186 followed = insert(:user, info: %{locked: true})
188 {:ok, follower} = User.maybe_direct_follow(follower, followed)
190 refute User.following?(follower, followed)
193 describe "unfollow/2" do
195 setting = Pleroma.Config.get([:instance, :external_user_synchronization])
198 Pleroma.Config.put([:instance, :external_user_synchronization], setting)
204 test "unfollow with syncronizes external user" do
205 Pleroma.Config.put([:instance, :external_user_synchronization], true)
210 follower_address: "http://localhost:4001/users/fuser1/followers",
211 following_address: "http://localhost:4001/users/fuser1/following",
212 ap_id: "http://localhost:4001/users/fuser1"
219 ap_id: "http://localhost:4001/users/fuser2",
220 follower_address: "http://localhost:4001/users/fuser2/followers",
221 following_address: "http://localhost:4001/users/fuser2/following",
222 following: [User.ap_followers(followed)]
225 {:ok, user, _activity} = User.unfollow(user, followed)
227 user = User.get_cached_by_id(user.id)
229 assert user.following == []
232 test "unfollow takes a user and another user" do
233 followed = insert(:user)
234 user = insert(:user, %{following: [User.ap_followers(followed)]})
236 {:ok, user, _activity} = User.unfollow(user, followed)
238 user = User.get_cached_by_id(user.id)
240 assert user.following == []
243 test "unfollow doesn't unfollow yourself" do
246 {:error, _} = User.unfollow(user, user)
248 user = User.get_cached_by_id(user.id)
249 assert user.following == [user.ap_id]
253 test "test if a user is following another user" do
254 followed = insert(:user)
255 user = insert(:user, %{following: [User.ap_followers(followed)]})
257 assert User.following?(user, followed)
258 refute User.following?(followed, user)
261 test "fetches correct profile for nickname beginning with number" do
262 # Use old-style integer ID to try to reproduce the problem
263 user = insert(:user, %{id: 1080})
264 user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
265 assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
268 describe "user registration" do
274 password_confirmation: "test",
275 email: "email@example.com"
277 clear_config([:instance, :autofollowed_nicknames])
278 clear_config([:instance, :welcome_message])
279 clear_config([:instance, :welcome_user_nickname])
281 test "it autofollows accounts that are set for it" do
283 remote_user = insert(:user, %{local: false})
285 Pleroma.Config.put([:instance, :autofollowed_nicknames], [
290 cng = User.register_changeset(%User{}, @full_user_data)
292 {:ok, registered_user} = User.register(cng)
294 assert User.following?(registered_user, user)
295 refute User.following?(registered_user, remote_user)
298 test "it sends a welcome message if it is set" do
299 welcome_user = insert(:user)
301 Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
302 Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
304 cng = User.register_changeset(%User{}, @full_user_data)
305 {:ok, registered_user} = User.register(cng)
307 activity = Repo.one(Pleroma.Activity)
308 assert registered_user.ap_id in activity.recipients
309 assert Object.normalize(activity).data["content"] =~ "cool site"
310 assert activity.actor == welcome_user.ap_id
313 test "it requires an email, name, nickname and password, bio is optional" do
316 |> Enum.each(fn key ->
317 params = Map.delete(@full_user_data, key)
318 changeset = User.register_changeset(%User{}, params)
320 assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
324 test "it restricts certain nicknames" do
325 [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
327 assert is_bitstring(restricted_name)
331 |> Map.put(:nickname, restricted_name)
333 changeset = User.register_changeset(%User{}, params)
335 refute changeset.valid?
338 test "it sets the password_hash, ap_id and following fields" do
339 changeset = User.register_changeset(%User{}, @full_user_data)
341 assert changeset.valid?
343 assert is_binary(changeset.changes[:password_hash])
344 assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
346 assert changeset.changes[:following] == [
347 User.ap_followers(%User{nickname: @full_user_data.nickname})
350 assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
353 test "it ensures info is not nil" do
354 changeset = User.register_changeset(%User{}, @full_user_data)
356 assert changeset.valid?
362 refute is_nil(user.info)
366 describe "user registration, with :account_activation_required" do
372 password_confirmation: "test",
373 email: "email@example.com"
376 clear_config([:instance, :account_activation_required]) do
377 Pleroma.Config.put([:instance, :account_activation_required], true)
380 test "it creates unconfirmed user" do
381 changeset = User.register_changeset(%User{}, @full_user_data)
382 assert changeset.valid?
384 {:ok, user} = Repo.insert(changeset)
386 assert user.info.confirmation_pending
387 assert user.info.confirmation_token
390 test "it creates confirmed user if :confirmed option is given" do
391 changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
392 assert changeset.valid?
394 {:ok, user} = Repo.insert(changeset)
396 refute user.info.confirmation_pending
397 refute user.info.confirmation_token
401 describe "get_or_fetch/1" do
402 test "gets an existing user by nickname" do
404 {:ok, fetched_user} = User.get_or_fetch(user.nickname)
406 assert user == fetched_user
409 test "gets an existing user by ap_id" do
410 ap_id = "http://mastodon.example.org/users/admin"
416 nickname: "admin@mastodon.example.org",
421 {:ok, fetched_user} = User.get_or_fetch(ap_id)
422 freshed_user = refresh_record(user)
423 assert freshed_user == fetched_user
427 describe "fetching a user from nickname or trying to build one" do
428 test "gets an existing user" do
430 {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
432 assert user == fetched_user
435 test "gets an existing user, case insensitive" do
436 user = insert(:user, nickname: "nick")
437 {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
439 assert user == fetched_user
442 test "gets an existing user by fully qualified nickname" do
445 {:ok, fetched_user} =
446 User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
448 assert user == fetched_user
451 test "gets an existing user by fully qualified nickname, case insensitive" do
452 user = insert(:user, nickname: "nick")
453 casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
455 {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
457 assert user == fetched_user
460 test "returns nil if no user could be fetched" do
461 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
462 assert fetched_user == "not found nonexistant@social.heldscal.la"
465 test "returns nil for nonexistant local user" do
466 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
467 assert fetched_user == "not found nonexistant"
470 test "updates an existing user, if stale" do
471 a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
477 nickname: "admin@mastodon.example.org",
478 ap_id: "http://mastodon.example.org/users/admin",
479 last_refreshed_at: a_week_ago,
483 assert orig_user.last_refreshed_at == a_week_ago
485 {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
486 assert user.info.source_data["endpoints"]
488 refute user.last_refreshed_at == orig_user.last_refreshed_at
492 test "returns an ap_id for a user" do
495 assert User.ap_id(user) ==
496 Pleroma.Web.Router.Helpers.feed_url(
497 Pleroma.Web.Endpoint,
503 test "returns an ap_followers link for a user" do
506 assert User.ap_followers(user) ==
507 Pleroma.Web.Router.Helpers.feed_url(
508 Pleroma.Web.Endpoint,
514 describe "remote user creation changeset" do
520 info: %{some: "info"},
521 avatar: %{some: "avatar"}
524 clear_config([:instance, :user_bio_length])
525 clear_config([:instance, :user_name_length])
527 test "it confirms validity" do
528 cs = User.remote_user_creation(@valid_remote)
532 test "it sets the follower_adress" do
533 cs = User.remote_user_creation(@valid_remote)
534 # remote users get a fake local follower address
535 assert cs.changes.follower_address ==
536 User.ap_followers(%User{nickname: @valid_remote[:nickname]})
539 test "it enforces the fqn format for nicknames" do
540 cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
541 assert Ecto.Changeset.get_field(cs, :local) == false
542 assert cs.changes.avatar
546 test "it has required fields" do
548 |> Enum.each(fn field ->
549 cs = User.remote_user_creation(Map.delete(@valid_remote, field))
555 describe "followers and friends" do
556 test "gets all followers for a given user" do
558 follower_one = insert(:user)
559 follower_two = insert(:user)
560 not_follower = insert(:user)
562 {:ok, follower_one} = User.follow(follower_one, user)
563 {:ok, follower_two} = User.follow(follower_two, user)
565 res = User.get_followers(user)
567 assert Enum.member?(res, follower_one)
568 assert Enum.member?(res, follower_two)
569 refute Enum.member?(res, not_follower)
572 test "gets all friends (followed users) for a given user" do
574 followed_one = insert(:user)
575 followed_two = insert(:user)
576 not_followed = insert(:user)
578 {:ok, user} = User.follow(user, followed_one)
579 {:ok, user} = User.follow(user, followed_two)
581 res = User.get_friends(user)
583 followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
584 followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
585 assert Enum.member?(res, followed_one)
586 assert Enum.member?(res, followed_two)
587 refute Enum.member?(res, not_followed)
591 describe "updating note and follower count" do
592 test "it sets the info->note_count property" do
595 user = User.get_cached_by_ap_id(note.data["actor"])
597 assert user.info.note_count == 0
599 {:ok, user} = User.update_note_count(user)
601 assert user.info.note_count == 1
604 test "it increases the info->note_count property" do
606 user = User.get_cached_by_ap_id(note.data["actor"])
608 assert user.info.note_count == 0
610 {:ok, user} = User.increase_note_count(user)
612 assert user.info.note_count == 1
614 {:ok, user} = User.increase_note_count(user)
616 assert user.info.note_count == 2
619 test "it decreases the info->note_count property" do
621 user = User.get_cached_by_ap_id(note.data["actor"])
623 assert user.info.note_count == 0
625 {:ok, user} = User.increase_note_count(user)
627 assert user.info.note_count == 1
629 {:ok, user} = User.decrease_note_count(user)
631 assert user.info.note_count == 0
633 {:ok, user} = User.decrease_note_count(user)
635 assert user.info.note_count == 0
638 test "it sets the info->follower_count property" do
640 follower = insert(:user)
642 User.follow(follower, user)
644 assert user.info.follower_count == 0
646 {:ok, user} = User.update_follower_count(user)
648 assert user.info.follower_count == 1
652 describe "remove duplicates from following list" do
653 test "it removes duplicates" do
655 follower = insert(:user)
657 {:ok, %User{following: following} = follower} = User.follow(follower, user)
658 assert length(following) == 2
662 |> User.update_changeset(%{following: following ++ following})
665 assert length(follower.following) == 4
667 {:ok, follower} = User.remove_duplicated_following(follower)
668 assert length(follower.following) == 2
671 test "it does nothing when following is uniq" do
673 follower = insert(:user)
675 {:ok, follower} = User.follow(follower, user)
676 assert length(follower.following) == 2
678 {:ok, follower} = User.remove_duplicated_following(follower)
679 assert length(follower.following) == 2
683 describe "follow_import" do
684 test "it imports user followings from list" do
685 [user1, user2, user3] = insert_list(3, :user)
692 {:ok, job} = User.follow_import(user1, identifiers)
693 result = ObanHelpers.perform(job)
695 assert is_list(result)
696 assert result == [user2, user3]
701 test "it mutes people" do
703 muted_user = insert(:user)
705 refute User.mutes?(user, muted_user)
706 refute User.muted_notifications?(user, muted_user)
708 {:ok, user} = User.mute(user, muted_user)
710 assert User.mutes?(user, muted_user)
711 assert User.muted_notifications?(user, muted_user)
714 test "it unmutes users" do
716 muted_user = insert(:user)
718 {:ok, user} = User.mute(user, muted_user)
719 {:ok, user} = User.unmute(user, muted_user)
721 refute User.mutes?(user, muted_user)
722 refute User.muted_notifications?(user, muted_user)
725 test "it mutes user without notifications" do
727 muted_user = insert(:user)
729 refute User.mutes?(user, muted_user)
730 refute User.muted_notifications?(user, muted_user)
732 {:ok, user} = User.mute(user, muted_user, false)
734 assert User.mutes?(user, muted_user)
735 refute User.muted_notifications?(user, muted_user)
740 test "it blocks people" do
742 blocked_user = insert(:user)
744 refute User.blocks?(user, blocked_user)
746 {:ok, user} = User.block(user, blocked_user)
748 assert User.blocks?(user, blocked_user)
751 test "it unblocks users" do
753 blocked_user = insert(:user)
755 {:ok, user} = User.block(user, blocked_user)
756 {:ok, user} = User.unblock(user, blocked_user)
758 refute User.blocks?(user, blocked_user)
761 test "blocks tear down cyclical follow relationships" do
762 blocker = insert(:user)
763 blocked = insert(:user)
765 {:ok, blocker} = User.follow(blocker, blocked)
766 {:ok, blocked} = User.follow(blocked, blocker)
768 assert User.following?(blocker, blocked)
769 assert User.following?(blocked, blocker)
771 {:ok, blocker} = User.block(blocker, blocked)
772 blocked = User.get_cached_by_id(blocked.id)
774 assert User.blocks?(blocker, blocked)
776 refute User.following?(blocker, blocked)
777 refute User.following?(blocked, blocker)
780 test "blocks tear down blocker->blocked follow relationships" do
781 blocker = insert(:user)
782 blocked = insert(:user)
784 {:ok, blocker} = User.follow(blocker, blocked)
786 assert User.following?(blocker, blocked)
787 refute User.following?(blocked, blocker)
789 {:ok, blocker} = User.block(blocker, blocked)
790 blocked = User.get_cached_by_id(blocked.id)
792 assert User.blocks?(blocker, blocked)
794 refute User.following?(blocker, blocked)
795 refute User.following?(blocked, blocker)
798 test "blocks tear down blocked->blocker follow relationships" do
799 blocker = insert(:user)
800 blocked = insert(:user)
802 {:ok, blocked} = User.follow(blocked, blocker)
804 refute User.following?(blocker, blocked)
805 assert User.following?(blocked, blocker)
807 {:ok, blocker} = User.block(blocker, blocked)
808 blocked = User.get_cached_by_id(blocked.id)
810 assert User.blocks?(blocker, blocked)
812 refute User.following?(blocker, blocked)
813 refute User.following?(blocked, blocker)
816 test "blocks tear down blocked->blocker subscription relationships" do
817 blocker = insert(:user)
818 blocked = insert(:user)
820 {:ok, blocker} = User.subscribe(blocked, blocker)
822 assert User.subscribed_to?(blocked, blocker)
823 refute User.subscribed_to?(blocker, blocked)
825 {:ok, blocker} = User.block(blocker, blocked)
827 assert User.blocks?(blocker, blocked)
828 refute User.subscribed_to?(blocker, blocked)
829 refute User.subscribed_to?(blocked, blocker)
833 describe "domain blocking" do
834 test "blocks domains" do
836 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
838 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
840 assert User.blocks?(user, collateral_user)
843 test "does not block domain with same end" do
847 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
849 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
851 refute User.blocks?(user, collateral_user)
854 test "does not block domain with same end if wildcard added" do
858 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
860 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
862 refute User.blocks?(user, collateral_user)
865 test "blocks domain with wildcard for subdomain" do
868 user_from_subdomain =
869 insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
871 user_with_two_subdomains =
873 ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
876 user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
878 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
880 assert User.blocks?(user, user_from_subdomain)
881 assert User.blocks?(user, user_with_two_subdomains)
882 assert User.blocks?(user, user_domain)
885 test "unblocks domains" do
887 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
889 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
890 {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
892 refute User.blocks?(user, collateral_user)
896 describe "blocks_import" do
897 test "it imports user blocks from list" do
898 [user1, user2, user3] = insert_list(3, :user)
905 {:ok, job} = User.blocks_import(user1, identifiers)
906 result = ObanHelpers.perform(job)
908 assert is_list(result)
909 assert result == [user2, user3]
913 test "get recipients from activity" do
914 actor = insert(:user)
915 user = insert(:user, local: true)
916 user_two = insert(:user, local: false)
917 addressed = insert(:user, local: true)
918 addressed_remote = insert(:user, local: false)
921 CommonAPI.post(actor, %{
922 "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
925 assert Enum.map([actor, addressed], & &1.ap_id) --
926 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
928 {:ok, user} = User.follow(user, actor)
929 {:ok, _user_two} = User.follow(user_two, actor)
930 recipients = User.get_recipients_from_activity(activity)
931 assert length(recipients) == 3
932 assert user in recipients
933 assert addressed in recipients
936 describe ".deactivate" do
937 test "can de-activate then re-activate a user" do
939 assert false == user.info.deactivated
940 {:ok, user} = User.deactivate(user)
941 assert true == user.info.deactivated
942 {:ok, user} = User.deactivate(user, false)
943 assert false == user.info.deactivated
946 test "hide a user from followers " do
948 user2 = insert(:user)
950 {:ok, user} = User.follow(user, user2)
951 {:ok, _user} = User.deactivate(user)
953 info = User.get_cached_user_info(user2)
955 assert info.follower_count == 0
956 assert [] = User.get_followers(user2)
959 test "hide a user from friends" do
961 user2 = insert(:user)
963 {:ok, user2} = User.follow(user2, user)
964 assert User.following_count(user2) == 1
966 {:ok, _user} = User.deactivate(user)
968 info = User.get_cached_user_info(user2)
970 assert info.following_count == 0
971 assert User.following_count(user2) == 0
972 assert [] = User.get_friends(user2)
975 test "hide a user's statuses from timelines and notifications" do
977 user2 = insert(:user)
979 {:ok, user2} = User.follow(user2, user)
981 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
983 activity = Repo.preload(activity, :bookmark)
985 [notification] = Pleroma.Notification.for_user(user2)
986 assert notification.activity.id == activity.id
988 assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
990 assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
991 ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
993 {:ok, _user} = User.deactivate(user)
995 assert [] == ActivityPub.fetch_public_activities(%{})
996 assert [] == Pleroma.Notification.for_user(user2)
999 ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
1003 describe "delete" do
1005 {:ok, user} = insert(:user) |> User.set_cache()
1010 clear_config([:instance, :federating])
1012 test ".delete_user_activities deletes all create activities", %{user: user} do
1013 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
1015 User.delete_user_activities(user)
1017 # TODO: Remove favorites, repeats, delete activities.
1018 refute Activity.get_by_id(activity.id)
1021 test "it deletes deactivated user" do
1022 {:ok, user} = insert(:user, info: %{deactivated: true}) |> User.set_cache()
1024 {:ok, job} = User.delete(user)
1025 {:ok, _user} = ObanHelpers.perform(job)
1027 refute User.get_by_id(user.id)
1030 test "it deletes a user, all follow relationships and all activities", %{user: user} do
1031 follower = insert(:user)
1032 {:ok, follower} = User.follow(follower, user)
1034 object = insert(:note, user: user)
1035 activity = insert(:note_activity, user: user, note: object)
1037 object_two = insert(:note, user: follower)
1038 activity_two = insert(:note_activity, user: follower, note: object_two)
1040 {:ok, like, _} = CommonAPI.favorite(activity_two.id, user)
1041 {:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
1042 {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
1044 {:ok, job} = User.delete(user)
1045 {:ok, _user} = ObanHelpers.perform(job)
1047 follower = User.get_cached_by_id(follower.id)
1049 refute User.following?(follower, user)
1050 refute User.get_by_id(user.id)
1051 assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1055 |> Activity.Queries.by_actor()
1057 |> Enum.map(fn act -> act.data["type"] end)
1059 assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
1061 refute Activity.get_by_id(activity.id)
1062 refute Activity.get_by_id(like.id)
1063 refute Activity.get_by_id(like_two.id)
1064 refute Activity.get_by_id(repeat.id)
1067 test_with_mock "it sends out User Delete activity",
1069 Pleroma.Web.ActivityPub.Publisher,
1072 Pleroma.Config.put([:instance, :federating], true)
1074 {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
1075 {:ok, _} = User.follow(follower, user)
1077 {:ok, job} = User.delete(user)
1078 {:ok, _user} = ObanHelpers.perform(job)
1080 assert ObanHelpers.member?(
1082 "op" => "publish_one",
1084 "inbox" => "http://mastodon.example.org/inbox",
1085 "id" => "pleroma:fakeid"
1088 all_enqueued(worker: Pleroma.Workers.PublisherWorker)
1093 test "get_public_key_for_ap_id fetches a user that's not in the db" do
1094 assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
1097 describe "insert or update a user from given data" do
1098 test "with normal data" do
1099 user = insert(:user, %{nickname: "nick@name.de"})
1100 data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
1102 assert {:ok, %User{}} = User.insert_or_update_user(data)
1105 test "with overly long fields" do
1106 current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
1107 user = insert(:user, nickname: "nickname@supergood.domain")
1112 nickname: user.nickname,
1115 %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
1120 assert {:ok, %User{}} = User.insert_or_update_user(data)
1123 test "with an overly long bio" do
1124 current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
1125 user = insert(:user, nickname: "nickname@supergood.domain")
1130 nickname: user.nickname,
1131 bio: String.duplicate("h", current_max_length + 1),
1135 assert {:ok, %User{}} = User.insert_or_update_user(data)
1138 test "with an overly long display name" do
1139 current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
1140 user = insert(:user, nickname: "nickname@supergood.domain")
1144 name: String.duplicate("h", current_max_length + 1),
1145 nickname: user.nickname,
1149 assert {:ok, %User{}} = User.insert_or_update_user(data)
1153 describe "per-user rich-text filtering" do
1154 test "html_filter_policy returns default policies, when rich-text is enabled" do
1155 user = insert(:user)
1157 assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
1160 test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
1161 user = insert(:user, %{info: %{no_rich_text: true}})
1163 assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
1167 describe "caching" do
1168 test "invalidate_cache works" do
1169 user = insert(:user)
1170 _user_info = User.get_cached_user_info(user)
1172 User.invalidate_cache(user)
1174 {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1175 {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
1176 {:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}")
1179 test "User.delete() plugs any possible zombie objects" do
1180 user = insert(:user)
1182 {:ok, job} = User.delete(user)
1183 {:ok, _} = ObanHelpers.perform(job)
1185 {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1187 assert cached_user != user
1189 {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
1191 assert cached_user != user
1195 test "auth_active?/1 works correctly" do
1196 Pleroma.Config.put([:instance, :account_activation_required], true)
1198 local_user = insert(:user, local: true, info: %{confirmation_pending: true})
1199 confirmed_user = insert(:user, local: true, info: %{confirmation_pending: false})
1200 remote_user = insert(:user, local: false)
1202 refute User.auth_active?(local_user)
1203 assert User.auth_active?(confirmed_user)
1204 assert User.auth_active?(remote_user)
1207 describe "superuser?/1" do
1208 test "returns false for unprivileged users" do
1209 user = insert(:user, local: true)
1211 refute User.superuser?(user)
1214 test "returns false for remote users" do
1215 user = insert(:user, local: false)
1216 remote_admin_user = insert(:user, local: false, info: %{is_admin: true})
1218 refute User.superuser?(user)
1219 refute User.superuser?(remote_admin_user)
1222 test "returns true for local moderators" do
1223 user = insert(:user, local: true, info: %{is_moderator: true})
1225 assert User.superuser?(user)
1228 test "returns true for local admins" do
1229 user = insert(:user, local: true, info: %{is_admin: true})
1231 assert User.superuser?(user)
1235 describe "visible_for?/2" do
1236 test "returns true when the account is itself" do
1237 user = insert(:user, local: true)
1239 assert User.visible_for?(user, user)
1242 test "returns false when the account is unauthenticated and auth is required" do
1243 Pleroma.Config.put([:instance, :account_activation_required], true)
1245 user = insert(:user, local: true, info: %{confirmation_pending: true})
1246 other_user = insert(:user, local: true)
1248 refute User.visible_for?(user, other_user)
1251 test "returns true when the account is unauthenticated and auth is not required" do
1252 user = insert(:user, local: true, info: %{confirmation_pending: true})
1253 other_user = insert(:user, local: true)
1255 assert User.visible_for?(user, other_user)
1258 test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
1259 Pleroma.Config.put([:instance, :account_activation_required], true)
1261 user = insert(:user, local: true, info: %{confirmation_pending: true})
1262 other_user = insert(:user, local: true, info: %{is_admin: true})
1264 assert User.visible_for?(user, other_user)
1268 describe "parse_bio/2" do
1269 test "preserves hosts in user links text" do
1270 remote_user = insert(:user, local: false, nickname: "nick@domain.com")
1271 user = insert(:user)
1272 bio = "A.k.a. @nick@domain.com"
1275 ~s(A.k.a. <span class="h-card"><a data-user="#{remote_user.id}" class="u-url mention" href="#{
1277 }" rel="ugc">@<span>nick@domain.com</span></a></span>)
1279 assert expected_text == User.parse_bio(bio, user)
1282 test "Adds rel=me on linkbacked urls" do
1283 user = insert(:user, ap_id: "https://social.example.org/users/lain")
1285 bio = "http://example.com/rel_me/null"
1286 expected_text = "<a href=\"#{bio}\">#{bio}</a>"
1287 assert expected_text == User.parse_bio(bio, user)
1289 bio = "http://example.com/rel_me/link"
1290 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1291 assert expected_text == User.parse_bio(bio, user)
1293 bio = "http://example.com/rel_me/anchor"
1294 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1295 assert expected_text == User.parse_bio(bio, user)
1299 test "follower count is updated when a follower is blocked" do
1300 user = insert(:user)
1301 follower = insert(:user)
1302 follower2 = insert(:user)
1303 follower3 = insert(:user)
1305 {:ok, follower} = User.follow(follower, user)
1306 {:ok, _follower2} = User.follow(follower2, user)
1307 {:ok, _follower3} = User.follow(follower3, user)
1309 {:ok, user} = User.block(user, follower)
1311 assert User.user_info(user).follower_count == 2
1314 describe "list_inactive_users_query/1" do
1315 defp days_ago(days) do
1317 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
1318 -days * 60 * 60 * 24,
1323 test "Users are inactive by default" do
1327 Enum.map(1..total, fn _ ->
1328 insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
1331 inactive_users_ids =
1332 Pleroma.User.list_inactive_users_query()
1333 |> Pleroma.Repo.all()
1334 |> Enum.map(& &1.id)
1336 Enum.each(users, fn user ->
1337 assert user.id in inactive_users_ids
1341 test "Only includes users who has no recent activity" do
1345 Enum.map(1..total, fn _ ->
1346 insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
1349 {inactive, active} = Enum.split(users, trunc(total / 2))
1351 Enum.map(active, fn user ->
1352 to = Enum.random(users -- [user])
1355 CommonAPI.post(user, %{
1356 "status" => "hey @#{to.nickname}"
1360 inactive_users_ids =
1361 Pleroma.User.list_inactive_users_query()
1362 |> Pleroma.Repo.all()
1363 |> Enum.map(& &1.id)
1365 Enum.each(active, fn user ->
1366 refute user.id in inactive_users_ids
1369 Enum.each(inactive, fn user ->
1370 assert user.id in inactive_users_ids
1374 test "Only includes users with no read notifications" do
1378 Enum.map(1..total, fn _ ->
1379 insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
1382 [sender | recipients] = users
1383 {inactive, active} = Enum.split(recipients, trunc(total / 2))
1385 Enum.each(recipients, fn to ->
1387 CommonAPI.post(sender, %{
1388 "status" => "hey @#{to.nickname}"
1392 CommonAPI.post(sender, %{
1393 "status" => "hey again @#{to.nickname}"
1397 Enum.each(active, fn user ->
1398 [n1, _n2] = Pleroma.Notification.for_user(user)
1399 {:ok, _} = Pleroma.Notification.read_one(user, n1.id)
1402 inactive_users_ids =
1403 Pleroma.User.list_inactive_users_query()
1404 |> Pleroma.Repo.all()
1405 |> Enum.map(& &1.id)
1407 Enum.each(active, fn user ->
1408 refute user.id in inactive_users_ids
1411 Enum.each(inactive, fn user ->
1412 assert user.id in inactive_users_ids
1417 describe "toggle_confirmation/1" do
1418 test "if user is confirmed" do
1419 user = insert(:user, info: %{confirmation_pending: false})
1420 {:ok, user} = User.toggle_confirmation(user)
1422 assert user.info.confirmation_pending
1423 assert user.info.confirmation_token
1426 test "if user is unconfirmed" do
1427 user = insert(:user, info: %{confirmation_pending: true, confirmation_token: "some token"})
1428 {:ok, user} = User.toggle_confirmation(user)
1430 refute user.info.confirmation_pending
1431 refute user.info.confirmation_token
1435 describe "ensure_keys_present" do
1436 test "it creates keys for a user and stores them in info" do
1437 user = insert(:user)
1438 refute is_binary(user.keys)
1439 {:ok, user} = User.ensure_keys_present(user)
1440 assert is_binary(user.keys)
1443 test "it doesn't create keys if there already are some" do
1444 user = insert(:user, keys: "xxx")
1445 {:ok, user} = User.ensure_keys_present(user)
1446 assert user.keys == "xxx"
1450 describe "get_ap_ids_by_nicknames" do
1451 test "it returns a list of AP ids for a given set of nicknames" do
1452 user = insert(:user)
1453 user_two = insert(:user)
1455 ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
1456 assert length(ap_ids) == 2
1457 assert user.ap_id in ap_ids
1458 assert user_two.ap_id in ap_ids
1462 describe "sync followers count" do
1464 user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
1465 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
1466 insert(:user, local: true)
1467 insert(:user, local: false, info: %{deactivated: true})
1468 {:ok, user1: user1, user2: user2}
1471 test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
1472 [fdb_user1] = User.external_users(limit: 1)
1474 assert fdb_user1.ap_id
1475 assert fdb_user1.ap_id == user1.ap_id
1476 assert fdb_user1.id == user1.id
1478 [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
1480 assert fdb_user2.ap_id
1481 assert fdb_user2.ap_id == user2.ap_id
1482 assert fdb_user2.id == user2.id
1484 assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
1488 describe "set_info_cache/2" do
1490 user = insert(:user)
1494 test "update from args", %{user: user} do
1495 User.set_info_cache(user, %{following_count: 15, follower_count: 18})
1497 %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
1498 assert followers == 18
1499 assert following == 15
1502 test "without args", %{user: user} do
1503 User.set_info_cache(user, %{})
1505 %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
1506 assert followers == 0
1507 assert following == 0
1511 describe "user_info/2" do
1513 user = insert(:user)
1517 test "update from args", %{user: user} do
1518 %{follower_count: followers, following_count: following} =
1519 User.user_info(user, %{following_count: 15, follower_count: 18})
1521 assert followers == 18
1522 assert following == 15
1525 test "without args", %{user: user} do
1526 %{follower_count: followers, following_count: following} = User.user_info(user)
1528 assert followers == 0
1529 assert following == 0
1533 describe "is_internal_user?/1" do
1534 test "non-internal user returns false" do
1535 user = insert(:user)
1536 refute User.is_internal_user?(user)
1539 test "user with no nickname returns true" do
1540 user = insert(:user, %{nickname: nil})
1541 assert User.is_internal_user?(user)
1544 test "user with internal-prefixed nickname returns true" do
1545 user = insert(:user, %{nickname: "internal.test"})
1546 assert User.is_internal_user?(user)
1550 describe "update_and_set_cache/1" do
1551 test "returns error when user is stale instead Ecto.StaleEntryError" do
1552 user = insert(:user)
1554 changeset = Ecto.Changeset.change(user, bio: "test")
1558 assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
1559 User.update_and_set_cache(changeset)
1562 test "performs update cache if user updated" do
1563 user = insert(:user)
1564 assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1566 changeset = Ecto.Changeset.change(user, bio: "test-bio")
1568 assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
1569 assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1570 assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
1574 describe "following/followers synchronization" do
1575 clear_config([:instance, :external_user_synchronization])
1577 test "updates the counters normally on following/getting a follow when disabled" do
1578 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1579 user = insert(:user)
1584 follower_address: "http://localhost:4001/users/masto_closed/followers",
1585 following_address: "http://localhost:4001/users/masto_closed/following",
1586 info: %{ap_enabled: true}
1589 assert User.user_info(other_user).following_count == 0
1590 assert User.user_info(other_user).follower_count == 0
1592 {:ok, user} = Pleroma.User.follow(user, other_user)
1593 other_user = Pleroma.User.get_by_id(other_user.id)
1595 assert User.user_info(user).following_count == 1
1596 assert User.user_info(other_user).follower_count == 1
1599 test "syncronizes the counters with the remote instance for the followed when enabled" do
1600 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1602 user = insert(:user)
1607 follower_address: "http://localhost:4001/users/masto_closed/followers",
1608 following_address: "http://localhost:4001/users/masto_closed/following",
1609 info: %{ap_enabled: true}
1612 assert User.user_info(other_user).following_count == 0
1613 assert User.user_info(other_user).follower_count == 0
1615 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1616 {:ok, _user} = User.follow(user, other_user)
1617 other_user = User.get_by_id(other_user.id)
1619 assert User.user_info(other_user).follower_count == 437
1622 test "syncronizes the counters with the remote instance for the follower when enabled" do
1623 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1625 user = insert(:user)
1630 follower_address: "http://localhost:4001/users/masto_closed/followers",
1631 following_address: "http://localhost:4001/users/masto_closed/following",
1632 info: %{ap_enabled: true}
1635 assert User.user_info(other_user).following_count == 0
1636 assert User.user_info(other_user).follower_count == 0
1638 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1639 {:ok, other_user} = User.follow(other_user, user)
1641 assert User.user_info(other_user).following_count == 152
1645 describe "change_email/2" do
1647 [user: insert(:user)]
1650 test "blank email returns error", %{user: user} do
1651 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
1652 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
1655 test "non unique email returns error", %{user: user} do
1656 %{email: email} = insert(:user)
1658 assert {:error, %{errors: [email: {"has already been taken", _}]}} =
1659 User.change_email(user, email)
1662 test "invalid email returns error", %{user: user} do
1663 assert {:error, %{errors: [email: {"has invalid format", _}]}} =
1664 User.change_email(user, "cofe")
1667 test "changes email", %{user: user} do
1668 assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
1672 describe "set_password_reset_pending/2" do
1674 [user: insert(:user)]
1677 test "sets password_reset_pending to true", %{user: user} do
1678 %{password_reset_pending: password_reset_pending} = user.info
1680 refute password_reset_pending
1682 {:ok, %{info: %{password_reset_pending: password_reset_pending}}} =
1683 User.force_password_reset(user)
1685 assert password_reset_pending
1689 test "change_info/2" do
1690 user = insert(:user)
1691 assert user.info.hide_follows == false
1693 changeset = User.change_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
1694 assert changeset.changes.info.changes.hide_follows == true
1697 test "update_info/2" do
1698 user = insert(:user)
1699 assert user.info.hide_follows == false
1701 assert {:ok, _} = User.update_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
1703 assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
1704 assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1707 describe "get_cached_by_nickname_or_id" do
1709 limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
1710 local_user = insert(:user)
1711 remote_user = insert(:user, nickname: "nickname@example.com", local: false)
1714 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
1717 [local_user: local_user, remote_user: remote_user]
1720 test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
1721 remote_user: remote_user
1723 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1724 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1726 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1727 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1729 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1730 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1733 test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
1734 %{remote_user: remote_user} do
1735 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1736 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1739 test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
1740 %{remote_user: remote_user, local_user: local_user} do
1741 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1742 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
1745 test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
1746 %{remote_user: remote_user} do
1747 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1748 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1751 test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
1752 %{local_user: local_user} do
1753 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1754 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1756 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1757 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1759 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1760 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)