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 "AP ID user relationships" do
30 {:ok, user: insert(:user)}
33 test "outgoing_relations_ap_ids/1", %{user: user} do
34 rel_types = [:block, :mute, :notification_mute, :reblog_mute, :inverse_subscription]
42 insert_list(2, :user_relationship, %{source: user, relationship_type: rel_type})
44 ap_ids = Enum.map(rel_records, fn rr -> Repo.preload(rr, :target).target.ap_id end)
45 {rel_type, Enum.sort(ap_ids)}
49 assert ap_ids_by_rel[:block] == Enum.sort(User.blocked_users_ap_ids(user))
50 assert ap_ids_by_rel[:block] == Enum.sort(Enum.map(User.blocked_users(user), & &1.ap_id))
52 assert ap_ids_by_rel[:mute] == Enum.sort(User.muted_users_ap_ids(user))
53 assert ap_ids_by_rel[:mute] == Enum.sort(Enum.map(User.muted_users(user), & &1.ap_id))
55 assert ap_ids_by_rel[:notification_mute] ==
56 Enum.sort(User.notification_muted_users_ap_ids(user))
58 assert ap_ids_by_rel[:notification_mute] ==
59 Enum.sort(Enum.map(User.notification_muted_users(user), & &1.ap_id))
61 assert ap_ids_by_rel[:reblog_mute] == Enum.sort(User.reblog_muted_users_ap_ids(user))
63 assert ap_ids_by_rel[:reblog_mute] ==
64 Enum.sort(Enum.map(User.reblog_muted_users(user), & &1.ap_id))
66 assert ap_ids_by_rel[:inverse_subscription] == Enum.sort(User.subscriber_users_ap_ids(user))
68 assert ap_ids_by_rel[:inverse_subscription] ==
69 Enum.sort(Enum.map(User.subscriber_users(user), & &1.ap_id))
71 outgoing_relations_ap_ids = User.outgoing_relations_ap_ids(user, rel_types)
73 assert ap_ids_by_rel ==
74 Enum.into(outgoing_relations_ap_ids, %{}, fn {k, v} -> {k, Enum.sort(v)} end)
78 describe "when tags are nil" do
79 test "tagging a user" do
80 user = insert(:user, %{tags: nil})
81 user = User.tag(user, ["cool", "dude"])
83 assert "cool" in user.tags
84 assert "dude" in user.tags
87 test "untagging a user" do
88 user = insert(:user, %{tags: nil})
89 user = User.untag(user, ["cool", "dude"])
91 assert user.tags == []
95 test "ap_id returns the activity pub id for the user" do
96 user = UserBuilder.build()
98 expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
100 assert expected_ap_id == User.ap_id(user)
103 test "ap_followers returns the followers collection for the user" do
104 user = UserBuilder.build()
106 expected_followers_collection = "#{User.ap_id(user)}/followers"
108 assert expected_followers_collection == User.ap_followers(user)
111 test "ap_following returns the following collection for the user" do
112 user = UserBuilder.build()
114 expected_followers_collection = "#{User.ap_id(user)}/following"
116 assert expected_followers_collection == User.ap_following(user)
119 test "returns all pending follow requests" do
120 unlocked = insert(:user)
121 locked = insert(:user, locked: true)
122 follower = insert(:user)
124 CommonAPI.follow(follower, unlocked)
125 CommonAPI.follow(follower, locked)
127 assert [] = User.get_follow_requests(unlocked)
128 assert [activity] = User.get_follow_requests(locked)
133 test "doesn't return already accepted or duplicate follow requests" do
134 locked = insert(:user, locked: true)
135 pending_follower = insert(:user)
136 accepted_follower = insert(:user)
138 CommonAPI.follow(pending_follower, locked)
139 CommonAPI.follow(pending_follower, locked)
140 CommonAPI.follow(accepted_follower, locked)
141 Pleroma.FollowingRelationship.update(accepted_follower, locked, "accept")
143 assert [^pending_follower] = User.get_follow_requests(locked)
146 test "clears follow requests when requester is blocked" do
147 followed = insert(:user, locked: true)
148 follower = insert(:user)
150 CommonAPI.follow(follower, followed)
151 assert [_activity] = User.get_follow_requests(followed)
153 {:ok, _user_relationship} = User.block(followed, follower)
154 assert [] = User.get_follow_requests(followed)
157 test "follow_all follows mutliple users" do
159 followed_zero = insert(:user)
160 followed_one = insert(:user)
161 followed_two = insert(:user)
162 blocked = insert(:user)
163 not_followed = insert(:user)
164 reverse_blocked = insert(:user)
166 {:ok, _user_relationship} = User.block(user, blocked)
167 {:ok, _user_relationship} = User.block(reverse_blocked, user)
169 {:ok, user} = User.follow(user, followed_zero)
171 {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
173 assert User.following?(user, followed_one)
174 assert User.following?(user, followed_two)
175 assert User.following?(user, followed_zero)
176 refute User.following?(user, not_followed)
177 refute User.following?(user, blocked)
178 refute User.following?(user, reverse_blocked)
181 test "follow_all follows mutliple users without duplicating" do
183 followed_zero = insert(:user)
184 followed_one = insert(:user)
185 followed_two = insert(:user)
187 {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
188 assert length(User.following(user)) == 3
190 {:ok, user} = User.follow_all(user, [followed_one, followed_two])
191 assert length(User.following(user)) == 4
194 test "follow takes a user and another user" do
196 followed = insert(:user)
198 {:ok, user} = User.follow(user, followed)
200 user = User.get_cached_by_id(user.id)
202 followed = User.get_cached_by_ap_id(followed.ap_id)
203 assert followed.follower_count == 1
205 assert User.ap_followers(followed) in User.following(user)
208 test "can't follow a deactivated users" do
210 followed = insert(:user, %{deactivated: true})
212 {:error, _} = User.follow(user, followed)
215 test "can't follow a user who blocked us" do
216 blocker = insert(:user)
217 blockee = insert(:user)
219 {:ok, _user_relationship} = User.block(blocker, blockee)
221 {:error, _} = User.follow(blockee, blocker)
224 test "can't subscribe to a user who blocked us" do
225 blocker = insert(:user)
226 blocked = insert(:user)
228 {:ok, _user_relationship} = User.block(blocker, blocked)
230 {:error, _} = User.subscribe(blocked, blocker)
233 test "local users do not automatically follow local locked accounts" do
234 follower = insert(:user, locked: true)
235 followed = insert(:user, locked: true)
237 {:ok, follower} = User.maybe_direct_follow(follower, followed)
239 refute User.following?(follower, followed)
242 describe "unfollow/2" do
244 setting = Pleroma.Config.get([:instance, :external_user_synchronization])
247 Pleroma.Config.put([:instance, :external_user_synchronization], setting)
253 test "unfollow with syncronizes external user" do
254 Pleroma.Config.put([:instance, :external_user_synchronization], true)
259 follower_address: "http://localhost:4001/users/fuser1/followers",
260 following_address: "http://localhost:4001/users/fuser1/following",
261 ap_id: "http://localhost:4001/users/fuser1"
268 ap_id: "http://localhost:4001/users/fuser2",
269 follower_address: "http://localhost:4001/users/fuser2/followers",
270 following_address: "http://localhost:4001/users/fuser2/following"
273 {:ok, user} = User.follow(user, followed, "accept")
275 {:ok, user, _activity} = User.unfollow(user, followed)
277 user = User.get_cached_by_id(user.id)
279 assert User.following(user) == []
282 test "unfollow takes a user and another user" do
283 followed = insert(:user)
286 {:ok, user} = User.follow(user, followed, "accept")
288 assert User.following(user) == [user.follower_address, followed.follower_address]
290 {:ok, user, _activity} = User.unfollow(user, followed)
292 assert User.following(user) == [user.follower_address]
295 test "unfollow doesn't unfollow yourself" do
298 {:error, _} = User.unfollow(user, user)
300 assert User.following(user) == [user.follower_address]
304 test "test if a user is following another user" do
305 followed = insert(:user)
307 User.follow(user, followed, "accept")
309 assert User.following?(user, followed)
310 refute User.following?(followed, user)
313 test "fetches correct profile for nickname beginning with number" do
314 # Use old-style integer ID to try to reproduce the problem
315 user = insert(:user, %{id: 1080})
316 user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
317 assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
320 describe "user registration" do
326 password_confirmation: "test",
327 email: "email@example.com"
329 clear_config([:instance, :autofollowed_nicknames])
330 clear_config([:instance, :welcome_message])
331 clear_config([:instance, :welcome_user_nickname])
333 test "it autofollows accounts that are set for it" do
335 remote_user = insert(:user, %{local: false})
337 Pleroma.Config.put([:instance, :autofollowed_nicknames], [
342 cng = User.register_changeset(%User{}, @full_user_data)
344 {:ok, registered_user} = User.register(cng)
346 assert User.following?(registered_user, user)
347 refute User.following?(registered_user, remote_user)
350 test "it sends a welcome message if it is set" do
351 welcome_user = insert(:user)
353 Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
354 Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
356 cng = User.register_changeset(%User{}, @full_user_data)
357 {:ok, registered_user} = User.register(cng)
359 activity = Repo.one(Pleroma.Activity)
360 assert registered_user.ap_id in activity.recipients
361 assert Object.normalize(activity).data["content"] =~ "cool site"
362 assert activity.actor == welcome_user.ap_id
365 test "it requires an email, name, nickname and password, bio is optional" do
368 |> Enum.each(fn key ->
369 params = Map.delete(@full_user_data, key)
370 changeset = User.register_changeset(%User{}, params)
372 assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
376 test "it restricts certain nicknames" do
377 [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
379 assert is_bitstring(restricted_name)
383 |> Map.put(:nickname, restricted_name)
385 changeset = User.register_changeset(%User{}, params)
387 refute changeset.valid?
390 test "it sets the password_hash and ap_id" do
391 changeset = User.register_changeset(%User{}, @full_user_data)
393 assert changeset.valid?
395 assert is_binary(changeset.changes[:password_hash])
396 assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
398 assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
401 test "it ensures info is not nil" do
402 changeset = User.register_changeset(%User{}, @full_user_data)
404 assert changeset.valid?
410 refute is_nil(user.info)
414 describe "user registration, with :account_activation_required" do
420 password_confirmation: "test",
421 email: "email@example.com"
424 clear_config([:instance, :account_activation_required]) do
425 Pleroma.Config.put([:instance, :account_activation_required], true)
428 test "it creates unconfirmed user" do
429 changeset = User.register_changeset(%User{}, @full_user_data)
430 assert changeset.valid?
432 {:ok, user} = Repo.insert(changeset)
434 assert user.confirmation_pending
435 assert user.confirmation_token
438 test "it creates confirmed user if :confirmed option is given" do
439 changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
440 assert changeset.valid?
442 {:ok, user} = Repo.insert(changeset)
444 refute user.confirmation_pending
445 refute user.confirmation_token
449 describe "get_or_fetch/1" do
450 test "gets an existing user by nickname" do
452 {:ok, fetched_user} = User.get_or_fetch(user.nickname)
454 assert user == fetched_user
457 test "gets an existing user by ap_id" do
458 ap_id = "http://mastodon.example.org/users/admin"
464 nickname: "admin@mastodon.example.org",
469 {:ok, fetched_user} = User.get_or_fetch(ap_id)
470 freshed_user = refresh_record(user)
471 assert freshed_user == fetched_user
475 describe "fetching a user from nickname or trying to build one" do
476 test "gets an existing user" do
478 {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
480 assert user == fetched_user
483 test "gets an existing user, case insensitive" do
484 user = insert(:user, nickname: "nick")
485 {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
487 assert user == fetched_user
490 test "gets an existing user by fully qualified nickname" do
493 {:ok, fetched_user} =
494 User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
496 assert user == fetched_user
499 test "gets an existing user by fully qualified nickname, case insensitive" do
500 user = insert(:user, nickname: "nick")
501 casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
503 {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
505 assert user == fetched_user
508 test "returns nil if no user could be fetched" do
509 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
510 assert fetched_user == "not found nonexistant@social.heldscal.la"
513 test "returns nil for nonexistant local user" do
514 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
515 assert fetched_user == "not found nonexistant"
518 test "updates an existing user, if stale" do
519 a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
525 nickname: "admin@mastodon.example.org",
526 ap_id: "http://mastodon.example.org/users/admin",
527 last_refreshed_at: a_week_ago,
531 assert orig_user.last_refreshed_at == a_week_ago
533 {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
535 assert user.source_data["endpoints"]
537 refute user.last_refreshed_at == orig_user.last_refreshed_at
541 test "returns an ap_id for a user" do
544 assert User.ap_id(user) ==
545 Pleroma.Web.Router.Helpers.feed_url(
546 Pleroma.Web.Endpoint,
552 test "returns an ap_followers link for a user" do
555 assert User.ap_followers(user) ==
556 Pleroma.Web.Router.Helpers.feed_url(
557 Pleroma.Web.Endpoint,
563 describe "remote user creation changeset" do
569 info: %{some: "info"},
570 avatar: %{some: "avatar"}
573 clear_config([:instance, :user_bio_length])
574 clear_config([:instance, :user_name_length])
576 test "it confirms validity" do
577 cs = User.remote_user_creation(@valid_remote)
581 test "it sets the follower_adress" do
582 cs = User.remote_user_creation(@valid_remote)
583 # remote users get a fake local follower address
584 assert cs.changes.follower_address ==
585 User.ap_followers(%User{nickname: @valid_remote[:nickname]})
588 test "it enforces the fqn format for nicknames" do
589 cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
590 assert Ecto.Changeset.get_field(cs, :local) == false
591 assert cs.changes.avatar
595 test "it has required fields" do
597 |> Enum.each(fn field ->
598 cs = User.remote_user_creation(Map.delete(@valid_remote, field))
604 describe "followers and friends" do
605 test "gets all followers for a given user" do
607 follower_one = insert(:user)
608 follower_two = insert(:user)
609 not_follower = insert(:user)
611 {:ok, follower_one} = User.follow(follower_one, user)
612 {:ok, follower_two} = User.follow(follower_two, user)
614 res = User.get_followers(user)
616 assert Enum.member?(res, follower_one)
617 assert Enum.member?(res, follower_two)
618 refute Enum.member?(res, not_follower)
621 test "gets all friends (followed users) for a given user" do
623 followed_one = insert(:user)
624 followed_two = insert(:user)
625 not_followed = insert(:user)
627 {:ok, user} = User.follow(user, followed_one)
628 {:ok, user} = User.follow(user, followed_two)
630 res = User.get_friends(user)
632 followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
633 followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
634 assert Enum.member?(res, followed_one)
635 assert Enum.member?(res, followed_two)
636 refute Enum.member?(res, not_followed)
640 describe "updating note and follower count" do
641 test "it sets the note_count property" do
644 user = User.get_cached_by_ap_id(note.data["actor"])
646 assert user.note_count == 0
648 {:ok, user} = User.update_note_count(user)
650 assert user.note_count == 1
653 test "it increases the note_count property" do
655 user = User.get_cached_by_ap_id(note.data["actor"])
657 assert user.note_count == 0
659 {:ok, user} = User.increase_note_count(user)
661 assert user.note_count == 1
663 {:ok, user} = User.increase_note_count(user)
665 assert user.note_count == 2
668 test "it decreases the note_count property" do
670 user = User.get_cached_by_ap_id(note.data["actor"])
672 assert user.note_count == 0
674 {:ok, user} = User.increase_note_count(user)
676 assert user.note_count == 1
678 {:ok, user} = User.decrease_note_count(user)
680 assert user.note_count == 0
682 {:ok, user} = User.decrease_note_count(user)
684 assert user.note_count == 0
687 test "it sets the follower_count property" do
689 follower = insert(:user)
691 User.follow(follower, user)
693 assert user.follower_count == 0
695 {:ok, user} = User.update_follower_count(user)
697 assert user.follower_count == 1
701 describe "follow_import" do
702 test "it imports user followings from list" do
703 [user1, user2, user3] = insert_list(3, :user)
710 {:ok, job} = User.follow_import(user1, identifiers)
711 result = ObanHelpers.perform(job)
713 assert is_list(result)
714 assert result == [user2, user3]
719 test "it mutes people" do
721 muted_user = insert(:user)
723 refute User.mutes?(user, muted_user)
724 refute User.muted_notifications?(user, muted_user)
726 {:ok, _user_relationships} = User.mute(user, muted_user)
728 assert User.mutes?(user, muted_user)
729 assert User.muted_notifications?(user, muted_user)
732 test "it unmutes users" do
734 muted_user = insert(:user)
736 {:ok, _user_relationships} = User.mute(user, muted_user)
737 {:ok, _user_mute} = User.unmute(user, muted_user)
739 refute User.mutes?(user, muted_user)
740 refute User.muted_notifications?(user, muted_user)
743 test "it mutes user without notifications" do
745 muted_user = insert(:user)
747 refute User.mutes?(user, muted_user)
748 refute User.muted_notifications?(user, muted_user)
750 {:ok, _user_relationships} = User.mute(user, muted_user, false)
752 assert User.mutes?(user, muted_user)
753 refute User.muted_notifications?(user, muted_user)
758 test "it blocks people" do
760 blocked_user = insert(:user)
762 refute User.blocks?(user, blocked_user)
764 {:ok, _user_relationship} = User.block(user, blocked_user)
766 assert User.blocks?(user, blocked_user)
769 test "it unblocks users" do
771 blocked_user = insert(:user)
773 {:ok, _user_relationship} = User.block(user, blocked_user)
774 {:ok, _user_block} = User.unblock(user, blocked_user)
776 refute User.blocks?(user, blocked_user)
779 test "blocks tear down cyclical follow relationships" do
780 blocker = insert(:user)
781 blocked = insert(:user)
783 {:ok, blocker} = User.follow(blocker, blocked)
784 {:ok, blocked} = User.follow(blocked, blocker)
786 assert User.following?(blocker, blocked)
787 assert User.following?(blocked, blocker)
789 {:ok, _user_relationship} = 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 blocker->blocked follow relationships" do
799 blocker = insert(:user)
800 blocked = insert(:user)
802 {:ok, blocker} = User.follow(blocker, blocked)
804 assert User.following?(blocker, blocked)
805 refute User.following?(blocked, blocker)
807 {:ok, _user_relationship} = 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 follow relationships" do
817 blocker = insert(:user)
818 blocked = insert(:user)
820 {:ok, blocked} = User.follow(blocked, blocker)
822 refute User.following?(blocker, blocked)
823 assert User.following?(blocked, blocker)
825 {:ok, _user_relationship} = User.block(blocker, blocked)
826 blocked = User.get_cached_by_id(blocked.id)
828 assert User.blocks?(blocker, blocked)
830 refute User.following?(blocker, blocked)
831 refute User.following?(blocked, blocker)
834 test "blocks tear down blocked->blocker subscription relationships" do
835 blocker = insert(:user)
836 blocked = insert(:user)
838 {:ok, _subscription} = User.subscribe(blocked, blocker)
840 assert User.subscribed_to?(blocked, blocker)
841 refute User.subscribed_to?(blocker, blocked)
843 {:ok, _user_relationship} = User.block(blocker, blocked)
845 assert User.blocks?(blocker, blocked)
846 refute User.subscribed_to?(blocker, blocked)
847 refute User.subscribed_to?(blocked, blocker)
851 describe "domain blocking" do
852 test "blocks domains" do
854 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
856 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
858 assert User.blocks?(user, collateral_user)
861 test "does not block domain with same end" do
865 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
867 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
869 refute User.blocks?(user, collateral_user)
872 test "does not block domain with same end if wildcard added" do
876 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
878 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
880 refute User.blocks?(user, collateral_user)
883 test "blocks domain with wildcard for subdomain" do
886 user_from_subdomain =
887 insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
889 user_with_two_subdomains =
891 ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
894 user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
896 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
898 assert User.blocks?(user, user_from_subdomain)
899 assert User.blocks?(user, user_with_two_subdomains)
900 assert User.blocks?(user, user_domain)
903 test "unblocks domains" do
905 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
907 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
908 {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
910 refute User.blocks?(user, collateral_user)
914 describe "blocks_import" do
915 test "it imports user blocks from list" do
916 [user1, user2, user3] = insert_list(3, :user)
923 {:ok, job} = User.blocks_import(user1, identifiers)
924 result = ObanHelpers.perform(job)
926 assert is_list(result)
927 assert result == [user2, user3]
931 describe "get_recipients_from_activity" do
932 test "get recipients" do
933 actor = insert(:user)
934 user = insert(:user, local: true)
935 user_two = insert(:user, local: false)
936 addressed = insert(:user, local: true)
937 addressed_remote = insert(:user, local: false)
940 CommonAPI.post(actor, %{
941 "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
944 assert Enum.map([actor, addressed], & &1.ap_id) --
945 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
947 {:ok, user} = User.follow(user, actor)
948 {:ok, _user_two} = User.follow(user_two, actor)
949 recipients = User.get_recipients_from_activity(activity)
950 assert length(recipients) == 3
951 assert user in recipients
952 assert addressed in recipients
955 test "has following" do
956 actor = insert(:user)
958 user_two = insert(:user)
959 addressed = insert(:user, local: true)
962 CommonAPI.post(actor, %{
963 "status" => "hey @#{addressed.nickname}"
966 assert Enum.map([actor, addressed], & &1.ap_id) --
967 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
969 {:ok, _actor} = User.follow(actor, user)
970 {:ok, _actor} = User.follow(actor, user_two)
971 recipients = User.get_recipients_from_activity(activity)
972 assert length(recipients) == 2
973 assert addressed in recipients
977 describe ".deactivate" do
978 test "can de-activate then re-activate a user" do
980 assert false == user.deactivated
981 {:ok, user} = User.deactivate(user)
982 assert true == user.deactivated
983 {:ok, user} = User.deactivate(user, false)
984 assert false == user.deactivated
987 test "hide a user from followers" do
989 user2 = insert(:user)
991 {:ok, user} = User.follow(user, user2)
992 {:ok, _user} = User.deactivate(user)
994 info = User.get_cached_user_info(user2)
996 assert info.follower_count == 0
997 assert [] = User.get_followers(user2)
1000 test "hide a user from friends" do
1001 user = insert(:user)
1002 user2 = insert(:user)
1004 {:ok, user2} = User.follow(user2, user)
1005 assert User.following_count(user2) == 1
1007 {:ok, _user} = User.deactivate(user)
1009 info = User.get_cached_user_info(user2)
1011 assert info.following_count == 0
1012 assert User.following_count(user2) == 0
1013 assert [] = User.get_friends(user2)
1016 test "hide a user's statuses from timelines and notifications" do
1017 user = insert(:user)
1018 user2 = insert(:user)
1020 {:ok, user2} = User.follow(user2, user)
1022 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
1024 activity = Repo.preload(activity, :bookmark)
1026 [notification] = Pleroma.Notification.for_user(user2)
1027 assert notification.activity.id == activity.id
1029 assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
1031 assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
1032 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1036 {:ok, _user} = User.deactivate(user)
1038 assert [] == ActivityPub.fetch_public_activities(%{})
1039 assert [] == Pleroma.Notification.for_user(user2)
1042 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1048 describe "delete" do
1050 {:ok, user} = insert(:user) |> User.set_cache()
1055 clear_config([:instance, :federating])
1057 test ".delete_user_activities deletes all create activities", %{user: user} do
1058 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
1060 User.delete_user_activities(user)
1062 # TODO: Remove favorites, repeats, delete activities.
1063 refute Activity.get_by_id(activity.id)
1066 test "it deletes deactivated user" do
1067 {:ok, user} = insert(:user, deactivated: true) |> User.set_cache()
1069 {:ok, job} = User.delete(user)
1070 {:ok, _user} = ObanHelpers.perform(job)
1072 refute User.get_by_id(user.id)
1075 test "it deletes a user, all follow relationships and all activities", %{user: user} do
1076 follower = insert(:user)
1077 {:ok, follower} = User.follow(follower, user)
1079 object = insert(:note, user: user)
1080 activity = insert(:note_activity, user: user, note: object)
1082 object_two = insert(:note, user: follower)
1083 activity_two = insert(:note_activity, user: follower, note: object_two)
1085 {:ok, like, _} = CommonAPI.favorite(activity_two.id, user)
1086 {:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
1087 {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
1089 {:ok, job} = User.delete(user)
1090 {:ok, _user} = ObanHelpers.perform(job)
1092 follower = User.get_cached_by_id(follower.id)
1094 refute User.following?(follower, user)
1095 refute User.get_by_id(user.id)
1096 assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1100 |> Activity.Queries.by_actor()
1102 |> Enum.map(fn act -> act.data["type"] end)
1104 assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
1106 refute Activity.get_by_id(activity.id)
1107 refute Activity.get_by_id(like.id)
1108 refute Activity.get_by_id(like_two.id)
1109 refute Activity.get_by_id(repeat.id)
1112 test_with_mock "it sends out User Delete activity",
1114 Pleroma.Web.ActivityPub.Publisher,
1117 Pleroma.Config.put([:instance, :federating], true)
1119 {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
1120 {:ok, _} = User.follow(follower, user)
1122 {:ok, job} = User.delete(user)
1123 {:ok, _user} = ObanHelpers.perform(job)
1125 assert ObanHelpers.member?(
1127 "op" => "publish_one",
1129 "inbox" => "http://mastodon.example.org/inbox",
1130 "id" => "pleroma:fakeid"
1133 all_enqueued(worker: Pleroma.Workers.PublisherWorker)
1138 test "get_public_key_for_ap_id fetches a user that's not in the db" do
1139 assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
1142 describe "insert or update a user from given data" do
1143 test "with normal data" do
1144 user = insert(:user, %{nickname: "nick@name.de"})
1145 data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
1147 assert {:ok, %User{}} = User.insert_or_update_user(data)
1150 test "with overly long fields" do
1151 current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
1152 user = insert(:user, nickname: "nickname@supergood.domain")
1157 nickname: user.nickname,
1159 %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
1163 assert {:ok, %User{}} = User.insert_or_update_user(data)
1166 test "with an overly long bio" do
1167 current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
1168 user = insert(:user, nickname: "nickname@supergood.domain")
1173 nickname: user.nickname,
1174 bio: String.duplicate("h", current_max_length + 1),
1178 assert {:ok, %User{}} = User.insert_or_update_user(data)
1181 test "with an overly long display name" do
1182 current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
1183 user = insert(:user, nickname: "nickname@supergood.domain")
1187 name: String.duplicate("h", current_max_length + 1),
1188 nickname: user.nickname,
1192 assert {:ok, %User{}} = User.insert_or_update_user(data)
1196 describe "per-user rich-text filtering" do
1197 test "html_filter_policy returns default policies, when rich-text is enabled" do
1198 user = insert(:user)
1200 assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
1203 test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
1204 user = insert(:user, no_rich_text: true)
1206 assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
1210 describe "caching" do
1211 test "invalidate_cache works" do
1212 user = insert(:user)
1213 _user_info = User.get_cached_user_info(user)
1215 User.invalidate_cache(user)
1217 {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1218 {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
1219 {:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}")
1222 test "User.delete() plugs any possible zombie objects" do
1223 user = insert(:user)
1225 {:ok, job} = User.delete(user)
1226 {:ok, _} = ObanHelpers.perform(job)
1228 {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1230 assert cached_user != user
1232 {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
1234 assert cached_user != user
1238 test "auth_active?/1 works correctly" do
1239 Pleroma.Config.put([:instance, :account_activation_required], true)
1241 local_user = insert(:user, local: true, confirmation_pending: true)
1242 confirmed_user = insert(:user, local: true, confirmation_pending: false)
1243 remote_user = insert(:user, local: false)
1245 refute User.auth_active?(local_user)
1246 assert User.auth_active?(confirmed_user)
1247 assert User.auth_active?(remote_user)
1249 # also shows unactive for deactivated users
1251 deactivated_but_confirmed =
1252 insert(:user, local: true, confirmation_pending: false, deactivated: true)
1254 refute User.auth_active?(deactivated_but_confirmed)
1257 describe "superuser?/1" do
1258 test "returns false for unprivileged users" do
1259 user = insert(:user, local: true)
1261 refute User.superuser?(user)
1264 test "returns false for remote users" do
1265 user = insert(:user, local: false)
1266 remote_admin_user = insert(:user, local: false, is_admin: true)
1268 refute User.superuser?(user)
1269 refute User.superuser?(remote_admin_user)
1272 test "returns true for local moderators" do
1273 user = insert(:user, local: true, is_moderator: true)
1275 assert User.superuser?(user)
1278 test "returns true for local admins" do
1279 user = insert(:user, local: true, is_admin: true)
1281 assert User.superuser?(user)
1285 describe "invisible?/1" do
1286 test "returns true for an invisible user" do
1287 user = insert(:user, local: true, invisible: true)
1289 assert User.invisible?(user)
1292 test "returns false for a non-invisible user" do
1293 user = insert(:user, local: true)
1295 refute User.invisible?(user)
1299 describe "visible_for?/2" do
1300 test "returns true when the account is itself" do
1301 user = insert(:user, local: true)
1303 assert User.visible_for?(user, user)
1306 test "returns false when the account is unauthenticated and auth is required" do
1307 Pleroma.Config.put([:instance, :account_activation_required], true)
1309 user = insert(:user, local: true, confirmation_pending: true)
1310 other_user = insert(:user, local: true)
1312 refute User.visible_for?(user, other_user)
1315 test "returns true when the account is unauthenticated and auth is not required" do
1316 user = insert(:user, local: true, confirmation_pending: true)
1317 other_user = insert(:user, local: true)
1319 assert User.visible_for?(user, other_user)
1322 test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
1323 Pleroma.Config.put([:instance, :account_activation_required], true)
1325 user = insert(:user, local: true, confirmation_pending: true)
1326 other_user = insert(:user, local: true, is_admin: true)
1328 assert User.visible_for?(user, other_user)
1332 describe "parse_bio/2" do
1333 test "preserves hosts in user links text" do
1334 remote_user = insert(:user, local: false, nickname: "nick@domain.com")
1335 user = insert(:user)
1336 bio = "A.k.a. @nick@domain.com"
1339 ~s(A.k.a. <span class="h-card"><a data-user="#{remote_user.id}" class="u-url mention" href="#{
1341 }" rel="ugc">@<span>nick@domain.com</span></a></span>)
1343 assert expected_text == User.parse_bio(bio, user)
1346 test "Adds rel=me on linkbacked urls" do
1347 user = insert(:user, ap_id: "https://social.example.org/users/lain")
1349 bio = "http://example.com/rel_me/null"
1350 expected_text = "<a href=\"#{bio}\">#{bio}</a>"
1351 assert expected_text == User.parse_bio(bio, user)
1353 bio = "http://example.com/rel_me/link"
1354 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1355 assert expected_text == User.parse_bio(bio, user)
1357 bio = "http://example.com/rel_me/anchor"
1358 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1359 assert expected_text == User.parse_bio(bio, user)
1363 test "follower count is updated when a follower is blocked" do
1364 user = insert(:user)
1365 follower = insert(:user)
1366 follower2 = insert(:user)
1367 follower3 = insert(:user)
1369 {:ok, follower} = User.follow(follower, user)
1370 {:ok, _follower2} = User.follow(follower2, user)
1371 {:ok, _follower3} = User.follow(follower3, user)
1373 {:ok, _user_relationship} = User.block(user, follower)
1374 user = refresh_record(user)
1376 assert User.user_info(user).follower_count == 2
1379 describe "list_inactive_users_query/1" do
1380 defp days_ago(days) do
1382 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
1383 -days * 60 * 60 * 24,
1388 test "Users are inactive by default" do
1392 Enum.map(1..total, fn _ ->
1393 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1396 inactive_users_ids =
1397 Pleroma.User.list_inactive_users_query()
1398 |> Pleroma.Repo.all()
1399 |> Enum.map(& &1.id)
1401 Enum.each(users, fn user ->
1402 assert user.id in inactive_users_ids
1406 test "Only includes users who has no recent activity" do
1410 Enum.map(1..total, fn _ ->
1411 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1414 {inactive, active} = Enum.split(users, trunc(total / 2))
1416 Enum.map(active, fn user ->
1417 to = Enum.random(users -- [user])
1420 CommonAPI.post(user, %{
1421 "status" => "hey @#{to.nickname}"
1425 inactive_users_ids =
1426 Pleroma.User.list_inactive_users_query()
1427 |> Pleroma.Repo.all()
1428 |> Enum.map(& &1.id)
1430 Enum.each(active, fn user ->
1431 refute user.id in inactive_users_ids
1434 Enum.each(inactive, fn user ->
1435 assert user.id in inactive_users_ids
1439 test "Only includes users with no read notifications" do
1443 Enum.map(1..total, fn _ ->
1444 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1447 [sender | recipients] = users
1448 {inactive, active} = Enum.split(recipients, trunc(total / 2))
1450 Enum.each(recipients, fn to ->
1452 CommonAPI.post(sender, %{
1453 "status" => "hey @#{to.nickname}"
1457 CommonAPI.post(sender, %{
1458 "status" => "hey again @#{to.nickname}"
1462 Enum.each(active, fn user ->
1463 [n1, _n2] = Pleroma.Notification.for_user(user)
1464 {:ok, _} = Pleroma.Notification.read_one(user, n1.id)
1467 inactive_users_ids =
1468 Pleroma.User.list_inactive_users_query()
1469 |> Pleroma.Repo.all()
1470 |> Enum.map(& &1.id)
1472 Enum.each(active, fn user ->
1473 refute user.id in inactive_users_ids
1476 Enum.each(inactive, fn user ->
1477 assert user.id in inactive_users_ids
1482 describe "toggle_confirmation/1" do
1483 test "if user is confirmed" do
1484 user = insert(:user, confirmation_pending: false)
1485 {:ok, user} = User.toggle_confirmation(user)
1487 assert user.confirmation_pending
1488 assert user.confirmation_token
1491 test "if user is unconfirmed" do
1492 user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
1493 {:ok, user} = User.toggle_confirmation(user)
1495 refute user.confirmation_pending
1496 refute user.confirmation_token
1500 describe "ensure_keys_present" do
1501 test "it creates keys for a user and stores them in info" do
1502 user = insert(:user)
1503 refute is_binary(user.keys)
1504 {:ok, user} = User.ensure_keys_present(user)
1505 assert is_binary(user.keys)
1508 test "it doesn't create keys if there already are some" do
1509 user = insert(:user, keys: "xxx")
1510 {:ok, user} = User.ensure_keys_present(user)
1511 assert user.keys == "xxx"
1515 describe "get_ap_ids_by_nicknames" do
1516 test "it returns a list of AP ids for a given set of nicknames" do
1517 user = insert(:user)
1518 user_two = insert(:user)
1520 ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
1521 assert length(ap_ids) == 2
1522 assert user.ap_id in ap_ids
1523 assert user_two.ap_id in ap_ids
1527 describe "sync followers count" do
1529 user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
1530 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
1531 insert(:user, local: true)
1532 insert(:user, local: false, deactivated: true)
1533 {:ok, user1: user1, user2: user2}
1536 test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
1537 [fdb_user1] = User.external_users(limit: 1)
1539 assert fdb_user1.ap_id
1540 assert fdb_user1.ap_id == user1.ap_id
1541 assert fdb_user1.id == user1.id
1543 [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
1545 assert fdb_user2.ap_id
1546 assert fdb_user2.ap_id == user2.ap_id
1547 assert fdb_user2.id == user2.id
1549 assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
1553 describe "set_info_cache/2" do
1555 user = insert(:user)
1559 test "update from args", %{user: user} do
1560 User.set_info_cache(user, %{following_count: 15, follower_count: 18})
1562 %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
1563 assert followers == 18
1564 assert following == 15
1567 test "without args", %{user: user} do
1568 User.set_info_cache(user, %{})
1570 %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
1571 assert followers == 0
1572 assert following == 0
1576 describe "user_info/2" do
1578 user = insert(:user)
1582 test "update from args", %{user: user} do
1583 %{follower_count: followers, following_count: following} =
1584 User.user_info(user, %{following_count: 15, follower_count: 18})
1586 assert followers == 18
1587 assert following == 15
1590 test "without args", %{user: user} do
1591 %{follower_count: followers, following_count: following} = User.user_info(user)
1593 assert followers == 0
1594 assert following == 0
1598 describe "is_internal_user?/1" do
1599 test "non-internal user returns false" do
1600 user = insert(:user)
1601 refute User.is_internal_user?(user)
1604 test "user with no nickname returns true" do
1605 user = insert(:user, %{nickname: nil})
1606 assert User.is_internal_user?(user)
1609 test "user with internal-prefixed nickname returns true" do
1610 user = insert(:user, %{nickname: "internal.test"})
1611 assert User.is_internal_user?(user)
1615 describe "update_and_set_cache/1" do
1616 test "returns error when user is stale instead Ecto.StaleEntryError" do
1617 user = insert(:user)
1619 changeset = Ecto.Changeset.change(user, bio: "test")
1623 assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
1624 User.update_and_set_cache(changeset)
1627 test "performs update cache if user updated" do
1628 user = insert(:user)
1629 assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1631 changeset = Ecto.Changeset.change(user, bio: "test-bio")
1633 assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
1634 assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1635 assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
1639 describe "following/followers synchronization" do
1640 clear_config([:instance, :external_user_synchronization])
1642 test "updates the counters normally on following/getting a follow when disabled" do
1643 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1644 user = insert(:user)
1649 follower_address: "http://localhost:4001/users/masto_closed/followers",
1650 following_address: "http://localhost:4001/users/masto_closed/following",
1654 assert User.user_info(other_user).following_count == 0
1655 assert User.user_info(other_user).follower_count == 0
1657 {:ok, user} = Pleroma.User.follow(user, other_user)
1658 other_user = Pleroma.User.get_by_id(other_user.id)
1660 assert User.user_info(user).following_count == 1
1661 assert User.user_info(other_user).follower_count == 1
1664 test "syncronizes the counters with the remote instance for the followed when enabled" do
1665 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1667 user = insert(:user)
1672 follower_address: "http://localhost:4001/users/masto_closed/followers",
1673 following_address: "http://localhost:4001/users/masto_closed/following",
1677 assert User.user_info(other_user).following_count == 0
1678 assert User.user_info(other_user).follower_count == 0
1680 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1681 {:ok, _user} = User.follow(user, other_user)
1682 other_user = User.get_by_id(other_user.id)
1684 assert User.user_info(other_user).follower_count == 437
1687 test "syncronizes the counters with the remote instance for the follower when enabled" do
1688 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1690 user = insert(:user)
1695 follower_address: "http://localhost:4001/users/masto_closed/followers",
1696 following_address: "http://localhost:4001/users/masto_closed/following",
1700 assert User.user_info(other_user).following_count == 0
1701 assert User.user_info(other_user).follower_count == 0
1703 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1704 {:ok, other_user} = User.follow(other_user, user)
1706 assert User.user_info(other_user).following_count == 152
1710 describe "change_email/2" do
1712 [user: insert(:user)]
1715 test "blank email returns error", %{user: user} do
1716 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
1717 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
1720 test "non unique email returns error", %{user: user} do
1721 %{email: email} = insert(:user)
1723 assert {:error, %{errors: [email: {"has already been taken", _}]}} =
1724 User.change_email(user, email)
1727 test "invalid email returns error", %{user: user} do
1728 assert {:error, %{errors: [email: {"has invalid format", _}]}} =
1729 User.change_email(user, "cofe")
1732 test "changes email", %{user: user} do
1733 assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
1737 describe "get_cached_by_nickname_or_id" do
1739 limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
1740 local_user = insert(:user)
1741 remote_user = insert(:user, nickname: "nickname@example.com", local: false)
1744 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
1747 [local_user: local_user, remote_user: remote_user]
1750 test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
1751 remote_user: remote_user
1753 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1754 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1756 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1757 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1759 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1760 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1763 test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
1764 %{remote_user: remote_user} do
1765 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1766 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1769 test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
1770 %{remote_user: remote_user, local_user: local_user} do
1771 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1772 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
1775 test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
1776 %{remote_user: remote_user} do
1777 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1778 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1781 test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
1782 %{local_user: local_user} do
1783 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1784 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1786 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1787 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1789 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1790 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1794 describe "update_email_notifications/2" do
1796 user = insert(:user, email_notifications: %{"digest" => true})
1801 test "Notifications are updated", %{user: user} do
1802 true = user.email_notifications["digest"]
1803 assert {:ok, result} = User.update_email_notifications(user, %{"digest" => false})
1804 assert result.email_notifications["digest"] == false