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 "service actors" do
29 test "returns invisible actor" do
30 uri = "#{Pleroma.Web.Endpoint.url()}/internal/fetch-test"
31 followers_uri = "#{uri}/followers"
32 user = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
35 nickname: "internal.fetch-test",
39 follower_address: ^followers_uri
42 user2 = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
43 assert user.id == user2.id
47 describe "AP ID user relationships" do
49 {:ok, user: insert(:user)}
52 test "outgoing_relations_ap_ids/1", %{user: user} do
53 rel_types = [:block, :mute, :notification_mute, :reblog_mute, :inverse_subscription]
61 insert_list(2, :user_relationship, %{source: user, relationship_type: rel_type})
63 ap_ids = Enum.map(rel_records, fn rr -> Repo.preload(rr, :target).target.ap_id end)
64 {rel_type, Enum.sort(ap_ids)}
68 assert ap_ids_by_rel[:block] == Enum.sort(User.blocked_users_ap_ids(user))
69 assert ap_ids_by_rel[:block] == Enum.sort(Enum.map(User.blocked_users(user), & &1.ap_id))
71 assert ap_ids_by_rel[:mute] == Enum.sort(User.muted_users_ap_ids(user))
72 assert ap_ids_by_rel[:mute] == Enum.sort(Enum.map(User.muted_users(user), & &1.ap_id))
74 assert ap_ids_by_rel[:notification_mute] ==
75 Enum.sort(User.notification_muted_users_ap_ids(user))
77 assert ap_ids_by_rel[:notification_mute] ==
78 Enum.sort(Enum.map(User.notification_muted_users(user), & &1.ap_id))
80 assert ap_ids_by_rel[:reblog_mute] == Enum.sort(User.reblog_muted_users_ap_ids(user))
82 assert ap_ids_by_rel[:reblog_mute] ==
83 Enum.sort(Enum.map(User.reblog_muted_users(user), & &1.ap_id))
85 assert ap_ids_by_rel[:inverse_subscription] == Enum.sort(User.subscriber_users_ap_ids(user))
87 assert ap_ids_by_rel[:inverse_subscription] ==
88 Enum.sort(Enum.map(User.subscriber_users(user), & &1.ap_id))
90 outgoing_relations_ap_ids = User.outgoing_relations_ap_ids(user, rel_types)
92 assert ap_ids_by_rel ==
93 Enum.into(outgoing_relations_ap_ids, %{}, fn {k, v} -> {k, Enum.sort(v)} end)
97 describe "when tags are nil" do
98 test "tagging a user" do
99 user = insert(:user, %{tags: nil})
100 user = User.tag(user, ["cool", "dude"])
102 assert "cool" in user.tags
103 assert "dude" in user.tags
106 test "untagging a user" do
107 user = insert(:user, %{tags: nil})
108 user = User.untag(user, ["cool", "dude"])
110 assert user.tags == []
114 test "ap_id returns the activity pub id for the user" do
115 user = UserBuilder.build()
117 expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
119 assert expected_ap_id == User.ap_id(user)
122 test "ap_followers returns the followers collection for the user" do
123 user = UserBuilder.build()
125 expected_followers_collection = "#{User.ap_id(user)}/followers"
127 assert expected_followers_collection == User.ap_followers(user)
130 test "ap_following returns the following collection for the user" do
131 user = UserBuilder.build()
133 expected_followers_collection = "#{User.ap_id(user)}/following"
135 assert expected_followers_collection == User.ap_following(user)
138 test "returns all pending follow requests" do
139 unlocked = insert(:user)
140 locked = insert(:user, locked: true)
141 follower = insert(:user)
143 CommonAPI.follow(follower, unlocked)
144 CommonAPI.follow(follower, locked)
146 assert [] = User.get_follow_requests(unlocked)
147 assert [activity] = User.get_follow_requests(locked)
152 test "doesn't return already accepted or duplicate follow requests" do
153 locked = insert(:user, locked: true)
154 pending_follower = insert(:user)
155 accepted_follower = insert(:user)
157 CommonAPI.follow(pending_follower, locked)
158 CommonAPI.follow(pending_follower, locked)
159 CommonAPI.follow(accepted_follower, locked)
160 Pleroma.FollowingRelationship.update(accepted_follower, locked, "accept")
162 assert [^pending_follower] = User.get_follow_requests(locked)
165 test "clears follow requests when requester is blocked" do
166 followed = insert(:user, locked: true)
167 follower = insert(:user)
169 CommonAPI.follow(follower, followed)
170 assert [_activity] = User.get_follow_requests(followed)
172 {:ok, _user_relationship} = User.block(followed, follower)
173 assert [] = User.get_follow_requests(followed)
176 test "follow_all follows mutliple users" do
178 followed_zero = insert(:user)
179 followed_one = insert(:user)
180 followed_two = insert(:user)
181 blocked = insert(:user)
182 not_followed = insert(:user)
183 reverse_blocked = insert(:user)
185 {:ok, _user_relationship} = User.block(user, blocked)
186 {:ok, _user_relationship} = User.block(reverse_blocked, user)
188 {:ok, user} = User.follow(user, followed_zero)
190 {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
192 assert User.following?(user, followed_one)
193 assert User.following?(user, followed_two)
194 assert User.following?(user, followed_zero)
195 refute User.following?(user, not_followed)
196 refute User.following?(user, blocked)
197 refute User.following?(user, reverse_blocked)
200 test "follow_all follows mutliple users without duplicating" do
202 followed_zero = insert(:user)
203 followed_one = insert(:user)
204 followed_two = insert(:user)
206 {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
207 assert length(User.following(user)) == 3
209 {:ok, user} = User.follow_all(user, [followed_one, followed_two])
210 assert length(User.following(user)) == 4
213 test "follow takes a user and another user" do
215 followed = insert(:user)
217 {:ok, user} = User.follow(user, followed)
219 user = User.get_cached_by_id(user.id)
220 followed = User.get_cached_by_ap_id(followed.ap_id)
222 assert followed.follower_count == 1
223 assert user.following_count == 1
225 assert User.ap_followers(followed) in User.following(user)
228 test "can't follow a deactivated users" do
230 followed = insert(:user, %{deactivated: true})
232 {:error, _} = User.follow(user, followed)
235 test "can't follow a user who blocked us" do
236 blocker = insert(:user)
237 blockee = insert(:user)
239 {:ok, _user_relationship} = User.block(blocker, blockee)
241 {:error, _} = User.follow(blockee, blocker)
244 test "can't subscribe to a user who blocked us" do
245 blocker = insert(:user)
246 blocked = insert(:user)
248 {:ok, _user_relationship} = User.block(blocker, blocked)
250 {:error, _} = User.subscribe(blocked, blocker)
253 test "local users do not automatically follow local locked accounts" do
254 follower = insert(:user, locked: true)
255 followed = insert(:user, locked: true)
257 {:ok, follower} = User.maybe_direct_follow(follower, followed)
259 refute User.following?(follower, followed)
262 describe "unfollow/2" do
264 setting = Pleroma.Config.get([:instance, :external_user_synchronization])
267 Pleroma.Config.put([:instance, :external_user_synchronization], setting)
273 test "unfollow with syncronizes external user" do
274 Pleroma.Config.put([:instance, :external_user_synchronization], true)
279 follower_address: "http://localhost:4001/users/fuser1/followers",
280 following_address: "http://localhost:4001/users/fuser1/following",
281 ap_id: "http://localhost:4001/users/fuser1"
288 ap_id: "http://localhost:4001/users/fuser2",
289 follower_address: "http://localhost:4001/users/fuser2/followers",
290 following_address: "http://localhost:4001/users/fuser2/following"
293 {:ok, user} = User.follow(user, followed, "accept")
295 {:ok, user, _activity} = User.unfollow(user, followed)
297 user = User.get_cached_by_id(user.id)
299 assert User.following(user) == []
302 test "unfollow takes a user and another user" do
303 followed = insert(:user)
306 {:ok, user} = User.follow(user, followed, "accept")
308 assert User.following(user) == [user.follower_address, followed.follower_address]
310 {:ok, user, _activity} = User.unfollow(user, followed)
312 assert User.following(user) == [user.follower_address]
315 test "unfollow doesn't unfollow yourself" do
318 {:error, _} = User.unfollow(user, user)
320 assert User.following(user) == [user.follower_address]
324 test "test if a user is following another user" do
325 followed = insert(:user)
327 User.follow(user, followed, "accept")
329 assert User.following?(user, followed)
330 refute User.following?(followed, user)
333 test "fetches correct profile for nickname beginning with number" do
334 # Use old-style integer ID to try to reproduce the problem
335 user = insert(:user, %{id: 1080})
336 user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
337 assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
340 describe "user registration" do
346 password_confirmation: "test",
347 email: "email@example.com"
349 clear_config([:instance, :autofollowed_nicknames])
350 clear_config([:instance, :welcome_message])
351 clear_config([:instance, :welcome_user_nickname])
353 test "it autofollows accounts that are set for it" do
355 remote_user = insert(:user, %{local: false})
357 Pleroma.Config.put([:instance, :autofollowed_nicknames], [
362 cng = User.register_changeset(%User{}, @full_user_data)
364 {:ok, registered_user} = User.register(cng)
366 assert User.following?(registered_user, user)
367 refute User.following?(registered_user, remote_user)
370 test "it sends a welcome message if it is set" do
371 welcome_user = insert(:user)
373 Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
374 Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
376 cng = User.register_changeset(%User{}, @full_user_data)
377 {:ok, registered_user} = User.register(cng)
379 activity = Repo.one(Pleroma.Activity)
380 assert registered_user.ap_id in activity.recipients
381 assert Object.normalize(activity).data["content"] =~ "cool site"
382 assert activity.actor == welcome_user.ap_id
385 test "it requires an email, name, nickname and password, bio is optional" do
388 |> Enum.each(fn key ->
389 params = Map.delete(@full_user_data, key)
390 changeset = User.register_changeset(%User{}, params)
392 assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
396 test "it restricts certain nicknames" do
397 [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
399 assert is_bitstring(restricted_name)
403 |> Map.put(:nickname, restricted_name)
405 changeset = User.register_changeset(%User{}, params)
407 refute changeset.valid?
410 test "it sets the password_hash and ap_id" do
411 changeset = User.register_changeset(%User{}, @full_user_data)
413 assert changeset.valid?
415 assert is_binary(changeset.changes[:password_hash])
416 assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
418 assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
422 describe "user registration, with :account_activation_required" do
428 password_confirmation: "test",
429 email: "email@example.com"
432 clear_config([:instance, :account_activation_required]) do
433 Pleroma.Config.put([:instance, :account_activation_required], true)
436 test "it creates unconfirmed user" do
437 changeset = User.register_changeset(%User{}, @full_user_data)
438 assert changeset.valid?
440 {:ok, user} = Repo.insert(changeset)
442 assert user.confirmation_pending
443 assert user.confirmation_token
446 test "it creates confirmed user if :confirmed option is given" do
447 changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
448 assert changeset.valid?
450 {:ok, user} = Repo.insert(changeset)
452 refute user.confirmation_pending
453 refute user.confirmation_token
457 describe "get_or_fetch/1" do
458 test "gets an existing user by nickname" do
460 {:ok, fetched_user} = User.get_or_fetch(user.nickname)
462 assert user == fetched_user
465 test "gets an existing user by ap_id" do
466 ap_id = "http://mastodon.example.org/users/admin"
472 nickname: "admin@mastodon.example.org",
476 {:ok, fetched_user} = User.get_or_fetch(ap_id)
477 freshed_user = refresh_record(user)
478 assert freshed_user == fetched_user
482 describe "fetching a user from nickname or trying to build one" do
483 test "gets an existing user" do
485 {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
487 assert user == fetched_user
490 test "gets an existing user, case insensitive" do
491 user = insert(:user, nickname: "nick")
492 {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
494 assert user == fetched_user
497 test "gets an existing user by fully qualified nickname" do
500 {:ok, fetched_user} =
501 User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
503 assert user == fetched_user
506 test "gets an existing user by fully qualified nickname, case insensitive" do
507 user = insert(:user, nickname: "nick")
508 casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
510 {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
512 assert user == fetched_user
515 test "returns nil if no user could be fetched" do
516 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
517 assert fetched_user == "not found nonexistant@social.heldscal.la"
520 test "returns nil for nonexistant local user" do
521 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
522 assert fetched_user == "not found nonexistant"
525 test "updates an existing user, if stale" do
526 a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
532 nickname: "admin@mastodon.example.org",
533 ap_id: "http://mastodon.example.org/users/admin",
534 last_refreshed_at: a_week_ago
537 assert orig_user.last_refreshed_at == a_week_ago
539 {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
541 assert user.source_data["endpoints"]
543 refute user.last_refreshed_at == orig_user.last_refreshed_at
547 test "returns an ap_id for a user" do
550 assert User.ap_id(user) ==
551 Pleroma.Web.Router.Helpers.feed_url(
552 Pleroma.Web.Endpoint,
558 test "returns an ap_followers link for a user" do
561 assert User.ap_followers(user) ==
562 Pleroma.Web.Router.Helpers.feed_url(
563 Pleroma.Web.Endpoint,
569 describe "remote user creation changeset" do
575 avatar: %{some: "avatar"}
578 clear_config([:instance, :user_bio_length])
579 clear_config([:instance, :user_name_length])
581 test "it confirms validity" do
582 cs = User.remote_user_creation(@valid_remote)
586 test "it sets the follower_adress" do
587 cs = User.remote_user_creation(@valid_remote)
588 # remote users get a fake local follower address
589 assert cs.changes.follower_address ==
590 User.ap_followers(%User{nickname: @valid_remote[:nickname]})
593 test "it enforces the fqn format for nicknames" do
594 cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
595 assert Ecto.Changeset.get_field(cs, :local) == false
596 assert cs.changes.avatar
600 test "it has required fields" do
602 |> Enum.each(fn field ->
603 cs = User.remote_user_creation(Map.delete(@valid_remote, field))
609 describe "followers and friends" do
610 test "gets all followers for a given user" do
612 follower_one = insert(:user)
613 follower_two = insert(:user)
614 not_follower = insert(:user)
616 {:ok, follower_one} = User.follow(follower_one, user)
617 {:ok, follower_two} = User.follow(follower_two, user)
619 res = User.get_followers(user)
621 assert Enum.member?(res, follower_one)
622 assert Enum.member?(res, follower_two)
623 refute Enum.member?(res, not_follower)
626 test "gets all friends (followed users) for a given user" do
628 followed_one = insert(:user)
629 followed_two = insert(:user)
630 not_followed = insert(:user)
632 {:ok, user} = User.follow(user, followed_one)
633 {:ok, user} = User.follow(user, followed_two)
635 res = User.get_friends(user)
637 followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
638 followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
639 assert Enum.member?(res, followed_one)
640 assert Enum.member?(res, followed_two)
641 refute Enum.member?(res, not_followed)
645 describe "updating note and follower count" do
646 test "it sets the note_count property" do
649 user = User.get_cached_by_ap_id(note.data["actor"])
651 assert user.note_count == 0
653 {:ok, user} = User.update_note_count(user)
655 assert user.note_count == 1
658 test "it increases the note_count property" do
660 user = User.get_cached_by_ap_id(note.data["actor"])
662 assert user.note_count == 0
664 {:ok, user} = User.increase_note_count(user)
666 assert user.note_count == 1
668 {:ok, user} = User.increase_note_count(user)
670 assert user.note_count == 2
673 test "it decreases the note_count property" do
675 user = User.get_cached_by_ap_id(note.data["actor"])
677 assert user.note_count == 0
679 {:ok, user} = User.increase_note_count(user)
681 assert user.note_count == 1
683 {:ok, user} = User.decrease_note_count(user)
685 assert user.note_count == 0
687 {:ok, user} = User.decrease_note_count(user)
689 assert user.note_count == 0
692 test "it sets the follower_count property" do
694 follower = insert(:user)
696 User.follow(follower, user)
698 assert user.follower_count == 0
700 {:ok, user} = User.update_follower_count(user)
702 assert user.follower_count == 1
706 describe "follow_import" do
707 test "it imports user followings from list" do
708 [user1, user2, user3] = insert_list(3, :user)
715 {:ok, job} = User.follow_import(user1, identifiers)
716 result = ObanHelpers.perform(job)
718 assert is_list(result)
719 assert result == [user2, user3]
724 test "it mutes people" do
726 muted_user = insert(:user)
728 refute User.mutes?(user, muted_user)
729 refute User.muted_notifications?(user, muted_user)
731 {:ok, _user_relationships} = User.mute(user, muted_user)
733 assert User.mutes?(user, muted_user)
734 assert User.muted_notifications?(user, muted_user)
737 test "it unmutes users" do
739 muted_user = insert(:user)
741 {:ok, _user_relationships} = User.mute(user, muted_user)
742 {:ok, _user_mute} = User.unmute(user, muted_user)
744 refute User.mutes?(user, muted_user)
745 refute User.muted_notifications?(user, muted_user)
748 test "it mutes user without notifications" do
750 muted_user = insert(:user)
752 refute User.mutes?(user, muted_user)
753 refute User.muted_notifications?(user, muted_user)
755 {:ok, _user_relationships} = User.mute(user, muted_user, false)
757 assert User.mutes?(user, muted_user)
758 refute User.muted_notifications?(user, muted_user)
763 test "it blocks people" do
765 blocked_user = insert(:user)
767 refute User.blocks?(user, blocked_user)
769 {:ok, _user_relationship} = User.block(user, blocked_user)
771 assert User.blocks?(user, blocked_user)
774 test "it unblocks users" do
776 blocked_user = insert(:user)
778 {:ok, _user_relationship} = User.block(user, blocked_user)
779 {:ok, _user_block} = User.unblock(user, blocked_user)
781 refute User.blocks?(user, blocked_user)
784 test "blocks tear down cyclical follow relationships" do
785 blocker = insert(:user)
786 blocked = insert(:user)
788 {:ok, blocker} = User.follow(blocker, blocked)
789 {:ok, blocked} = User.follow(blocked, blocker)
791 assert User.following?(blocker, blocked)
792 assert User.following?(blocked, blocker)
794 {:ok, _user_relationship} = User.block(blocker, blocked)
795 blocked = User.get_cached_by_id(blocked.id)
797 assert User.blocks?(blocker, blocked)
799 refute User.following?(blocker, blocked)
800 refute User.following?(blocked, blocker)
803 test "blocks tear down blocker->blocked follow relationships" do
804 blocker = insert(:user)
805 blocked = insert(:user)
807 {:ok, blocker} = User.follow(blocker, blocked)
809 assert User.following?(blocker, blocked)
810 refute User.following?(blocked, blocker)
812 {:ok, _user_relationship} = User.block(blocker, blocked)
813 blocked = User.get_cached_by_id(blocked.id)
815 assert User.blocks?(blocker, blocked)
817 refute User.following?(blocker, blocked)
818 refute User.following?(blocked, blocker)
821 test "blocks tear down blocked->blocker follow relationships" do
822 blocker = insert(:user)
823 blocked = insert(:user)
825 {:ok, blocked} = User.follow(blocked, blocker)
827 refute User.following?(blocker, blocked)
828 assert User.following?(blocked, blocker)
830 {:ok, _user_relationship} = User.block(blocker, blocked)
831 blocked = User.get_cached_by_id(blocked.id)
833 assert User.blocks?(blocker, blocked)
835 refute User.following?(blocker, blocked)
836 refute User.following?(blocked, blocker)
839 test "blocks tear down blocked->blocker subscription relationships" do
840 blocker = insert(:user)
841 blocked = insert(:user)
843 {:ok, _subscription} = User.subscribe(blocked, blocker)
845 assert User.subscribed_to?(blocked, blocker)
846 refute User.subscribed_to?(blocker, blocked)
848 {:ok, _user_relationship} = User.block(blocker, blocked)
850 assert User.blocks?(blocker, blocked)
851 refute User.subscribed_to?(blocker, blocked)
852 refute User.subscribed_to?(blocked, blocker)
856 describe "domain blocking" do
857 test "blocks domains" do
859 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
861 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
863 assert User.blocks?(user, collateral_user)
866 test "does not block domain with same end" do
870 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
872 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
874 refute User.blocks?(user, collateral_user)
877 test "does not block domain with same end if wildcard added" do
881 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
883 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
885 refute User.blocks?(user, collateral_user)
888 test "blocks domain with wildcard for subdomain" do
891 user_from_subdomain =
892 insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
894 user_with_two_subdomains =
896 ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
899 user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
901 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
903 assert User.blocks?(user, user_from_subdomain)
904 assert User.blocks?(user, user_with_two_subdomains)
905 assert User.blocks?(user, user_domain)
908 test "unblocks domains" do
910 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
912 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
913 {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
915 refute User.blocks?(user, collateral_user)
918 test "follows take precedence over domain blocks" do
920 good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
922 {:ok, user} = User.block_domain(user, "meanies.social")
923 {:ok, user} = User.follow(user, good_eggo)
925 refute User.blocks?(user, good_eggo)
929 describe "blocks_import" do
930 test "it imports user blocks from list" do
931 [user1, user2, user3] = insert_list(3, :user)
938 {:ok, job} = User.blocks_import(user1, identifiers)
939 result = ObanHelpers.perform(job)
941 assert is_list(result)
942 assert result == [user2, user3]
946 describe "get_recipients_from_activity" do
947 test "get recipients" do
948 actor = insert(:user)
949 user = insert(:user, local: true)
950 user_two = insert(:user, local: false)
951 addressed = insert(:user, local: true)
952 addressed_remote = insert(:user, local: false)
955 CommonAPI.post(actor, %{
956 "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
959 assert Enum.map([actor, addressed], & &1.ap_id) --
960 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
962 {:ok, user} = User.follow(user, actor)
963 {:ok, _user_two} = User.follow(user_two, actor)
964 recipients = User.get_recipients_from_activity(activity)
965 assert length(recipients) == 3
966 assert user in recipients
967 assert addressed in recipients
970 test "has following" do
971 actor = insert(:user)
973 user_two = insert(:user)
974 addressed = insert(:user, local: true)
977 CommonAPI.post(actor, %{
978 "status" => "hey @#{addressed.nickname}"
981 assert Enum.map([actor, addressed], & &1.ap_id) --
982 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
984 {:ok, _actor} = User.follow(actor, user)
985 {:ok, _actor} = User.follow(actor, user_two)
986 recipients = User.get_recipients_from_activity(activity)
987 assert length(recipients) == 2
988 assert addressed in recipients
992 describe ".deactivate" do
993 test "can de-activate then re-activate a user" do
995 assert false == user.deactivated
996 {:ok, user} = User.deactivate(user)
997 assert true == user.deactivated
998 {:ok, user} = User.deactivate(user, false)
999 assert false == user.deactivated
1002 test "hide a user from followers" do
1003 user = insert(:user)
1004 user2 = insert(:user)
1006 {:ok, user} = User.follow(user, user2)
1007 {:ok, _user} = User.deactivate(user)
1009 user2 = User.get_cached_by_id(user2.id)
1011 assert user2.follower_count == 0
1012 assert [] = User.get_followers(user2)
1015 test "hide a user from friends" do
1016 user = insert(:user)
1017 user2 = insert(:user)
1019 {:ok, user2} = User.follow(user2, user)
1020 assert user2.following_count == 1
1021 assert User.following_count(user2) == 1
1023 {:ok, _user} = User.deactivate(user)
1025 user2 = User.get_cached_by_id(user2.id)
1027 assert refresh_record(user2).following_count == 0
1028 assert user2.following_count == 0
1029 assert User.following_count(user2) == 0
1030 assert [] = User.get_friends(user2)
1033 test "hide a user's statuses from timelines and notifications" do
1034 user = insert(:user)
1035 user2 = insert(:user)
1037 {:ok, user2} = User.follow(user2, user)
1039 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
1041 activity = Repo.preload(activity, :bookmark)
1043 [notification] = Pleroma.Notification.for_user(user2)
1044 assert notification.activity.id == activity.id
1046 assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
1048 assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
1049 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1053 {:ok, _user} = User.deactivate(user)
1055 assert [] == ActivityPub.fetch_public_activities(%{})
1056 assert [] == Pleroma.Notification.for_user(user2)
1059 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1065 describe "delete" do
1067 {:ok, user} = insert(:user) |> User.set_cache()
1072 clear_config([:instance, :federating])
1074 test ".delete_user_activities deletes all create activities", %{user: user} do
1075 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
1077 User.delete_user_activities(user)
1079 # TODO: Remove favorites, repeats, delete activities.
1080 refute Activity.get_by_id(activity.id)
1083 test "it deletes deactivated user" do
1084 {:ok, user} = insert(:user, deactivated: true) |> User.set_cache()
1086 {:ok, job} = User.delete(user)
1087 {:ok, _user} = ObanHelpers.perform(job)
1089 refute User.get_by_id(user.id)
1092 test "it deletes a user, all follow relationships and all activities", %{user: user} do
1093 follower = insert(:user)
1094 {:ok, follower} = User.follow(follower, user)
1096 object = insert(:note, user: user)
1097 activity = insert(:note_activity, user: user, note: object)
1099 object_two = insert(:note, user: follower)
1100 activity_two = insert(:note_activity, user: follower, note: object_two)
1102 {:ok, like, _} = CommonAPI.favorite(activity_two.id, user)
1103 {:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
1104 {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
1106 {:ok, job} = User.delete(user)
1107 {:ok, _user} = ObanHelpers.perform(job)
1109 follower = User.get_cached_by_id(follower.id)
1111 refute User.following?(follower, user)
1112 refute User.get_by_id(user.id)
1113 assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1117 |> Activity.Queries.by_actor()
1119 |> Enum.map(fn act -> act.data["type"] end)
1121 assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
1123 refute Activity.get_by_id(activity.id)
1124 refute Activity.get_by_id(like.id)
1125 refute Activity.get_by_id(like_two.id)
1126 refute Activity.get_by_id(repeat.id)
1129 test_with_mock "it sends out User Delete activity",
1131 Pleroma.Web.ActivityPub.Publisher,
1134 Pleroma.Config.put([:instance, :federating], true)
1136 {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
1137 {:ok, _} = User.follow(follower, user)
1139 {:ok, job} = User.delete(user)
1140 {:ok, _user} = ObanHelpers.perform(job)
1142 assert ObanHelpers.member?(
1144 "op" => "publish_one",
1146 "inbox" => "http://mastodon.example.org/inbox",
1147 "id" => "pleroma:fakeid"
1150 all_enqueued(worker: Pleroma.Workers.PublisherWorker)
1155 test "get_public_key_for_ap_id fetches a user that's not in the db" do
1156 assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
1159 describe "insert or update a user from given data" do
1160 test "with normal data" do
1161 user = insert(:user, %{nickname: "nick@name.de"})
1162 data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
1164 assert {:ok, %User{}} = User.insert_or_update_user(data)
1167 test "with overly long fields" do
1168 current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
1169 user = insert(:user, nickname: "nickname@supergood.domain")
1174 nickname: user.nickname,
1176 %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
1180 assert {:ok, %User{}} = User.insert_or_update_user(data)
1183 test "with an overly long bio" do
1184 current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
1185 user = insert(:user, nickname: "nickname@supergood.domain")
1190 nickname: user.nickname,
1191 bio: String.duplicate("h", current_max_length + 1)
1194 assert {:ok, %User{}} = User.insert_or_update_user(data)
1197 test "with an overly long display name" do
1198 current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
1199 user = insert(:user, nickname: "nickname@supergood.domain")
1203 name: String.duplicate("h", current_max_length + 1),
1204 nickname: user.nickname
1207 assert {:ok, %User{}} = User.insert_or_update_user(data)
1211 describe "per-user rich-text filtering" do
1212 test "html_filter_policy returns default policies, when rich-text is enabled" do
1213 user = insert(:user)
1215 assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
1218 test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
1219 user = insert(:user, no_rich_text: true)
1221 assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
1225 describe "caching" do
1226 test "invalidate_cache works" do
1227 user = insert(:user)
1229 User.set_cache(user)
1230 User.invalidate_cache(user)
1232 {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1233 {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
1236 test "User.delete() plugs any possible zombie objects" do
1237 user = insert(:user)
1239 {:ok, job} = User.delete(user)
1240 {:ok, _} = ObanHelpers.perform(job)
1242 {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1244 assert cached_user != user
1246 {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
1248 assert cached_user != user
1252 test "auth_active?/1 works correctly" do
1253 Pleroma.Config.put([:instance, :account_activation_required], true)
1255 local_user = insert(:user, local: true, confirmation_pending: true)
1256 confirmed_user = insert(:user, local: true, confirmation_pending: false)
1257 remote_user = insert(:user, local: false)
1259 refute User.auth_active?(local_user)
1260 assert User.auth_active?(confirmed_user)
1261 assert User.auth_active?(remote_user)
1263 # also shows unactive for deactivated users
1265 deactivated_but_confirmed =
1266 insert(:user, local: true, confirmation_pending: false, deactivated: true)
1268 refute User.auth_active?(deactivated_but_confirmed)
1271 describe "superuser?/1" do
1272 test "returns false for unprivileged users" do
1273 user = insert(:user, local: true)
1275 refute User.superuser?(user)
1278 test "returns false for remote users" do
1279 user = insert(:user, local: false)
1280 remote_admin_user = insert(:user, local: false, is_admin: true)
1282 refute User.superuser?(user)
1283 refute User.superuser?(remote_admin_user)
1286 test "returns true for local moderators" do
1287 user = insert(:user, local: true, is_moderator: true)
1289 assert User.superuser?(user)
1292 test "returns true for local admins" do
1293 user = insert(:user, local: true, is_admin: true)
1295 assert User.superuser?(user)
1299 describe "invisible?/1" do
1300 test "returns true for an invisible user" do
1301 user = insert(:user, local: true, invisible: true)
1303 assert User.invisible?(user)
1306 test "returns false for a non-invisible user" do
1307 user = insert(:user, local: true)
1309 refute User.invisible?(user)
1313 describe "visible_for?/2" do
1314 test "returns true when the account is itself" do
1315 user = insert(:user, local: true)
1317 assert User.visible_for?(user, user)
1320 test "returns false when the account is unauthenticated and auth is required" do
1321 Pleroma.Config.put([:instance, :account_activation_required], true)
1323 user = insert(:user, local: true, confirmation_pending: true)
1324 other_user = insert(:user, local: true)
1326 refute User.visible_for?(user, other_user)
1329 test "returns true when the account is unauthenticated and auth is not required" do
1330 user = insert(:user, local: true, confirmation_pending: true)
1331 other_user = insert(:user, local: true)
1333 assert User.visible_for?(user, other_user)
1336 test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
1337 Pleroma.Config.put([:instance, :account_activation_required], true)
1339 user = insert(:user, local: true, confirmation_pending: true)
1340 other_user = insert(:user, local: true, is_admin: true)
1342 assert User.visible_for?(user, other_user)
1346 describe "parse_bio/2" do
1347 test "preserves hosts in user links text" do
1348 remote_user = insert(:user, local: false, nickname: "nick@domain.com")
1349 user = insert(:user)
1350 bio = "A.k.a. @nick@domain.com"
1353 ~s(A.k.a. <span class="h-card"><a data-user="#{remote_user.id}" class="u-url mention" href="#{
1355 }" rel="ugc">@<span>nick@domain.com</span></a></span>)
1357 assert expected_text == User.parse_bio(bio, user)
1360 test "Adds rel=me on linkbacked urls" do
1361 user = insert(:user, ap_id: "https://social.example.org/users/lain")
1363 bio = "http://example.com/rel_me/null"
1364 expected_text = "<a href=\"#{bio}\">#{bio}</a>"
1365 assert expected_text == User.parse_bio(bio, user)
1367 bio = "http://example.com/rel_me/link"
1368 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1369 assert expected_text == User.parse_bio(bio, user)
1371 bio = "http://example.com/rel_me/anchor"
1372 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1373 assert expected_text == User.parse_bio(bio, user)
1377 test "follower count is updated when a follower is blocked" do
1378 user = insert(:user)
1379 follower = insert(:user)
1380 follower2 = insert(:user)
1381 follower3 = insert(:user)
1383 {:ok, follower} = User.follow(follower, user)
1384 {:ok, _follower2} = User.follow(follower2, user)
1385 {:ok, _follower3} = User.follow(follower3, user)
1387 {:ok, _user_relationship} = User.block(user, follower)
1388 user = refresh_record(user)
1390 assert user.follower_count == 2
1393 describe "list_inactive_users_query/1" do
1394 defp days_ago(days) do
1396 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
1397 -days * 60 * 60 * 24,
1402 test "Users are inactive by default" do
1406 Enum.map(1..total, fn _ ->
1407 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1410 inactive_users_ids =
1411 Pleroma.User.list_inactive_users_query()
1412 |> Pleroma.Repo.all()
1413 |> Enum.map(& &1.id)
1415 Enum.each(users, fn user ->
1416 assert user.id in inactive_users_ids
1420 test "Only includes users who has no recent activity" do
1424 Enum.map(1..total, fn _ ->
1425 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1428 {inactive, active} = Enum.split(users, trunc(total / 2))
1430 Enum.map(active, fn user ->
1431 to = Enum.random(users -- [user])
1434 CommonAPI.post(user, %{
1435 "status" => "hey @#{to.nickname}"
1439 inactive_users_ids =
1440 Pleroma.User.list_inactive_users_query()
1441 |> Pleroma.Repo.all()
1442 |> Enum.map(& &1.id)
1444 Enum.each(active, fn user ->
1445 refute user.id in inactive_users_ids
1448 Enum.each(inactive, fn user ->
1449 assert user.id in inactive_users_ids
1453 test "Only includes users with no read notifications" do
1457 Enum.map(1..total, fn _ ->
1458 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1461 [sender | recipients] = users
1462 {inactive, active} = Enum.split(recipients, trunc(total / 2))
1464 Enum.each(recipients, fn to ->
1466 CommonAPI.post(sender, %{
1467 "status" => "hey @#{to.nickname}"
1471 CommonAPI.post(sender, %{
1472 "status" => "hey again @#{to.nickname}"
1476 Enum.each(active, fn user ->
1477 [n1, _n2] = Pleroma.Notification.for_user(user)
1478 {:ok, _} = Pleroma.Notification.read_one(user, n1.id)
1481 inactive_users_ids =
1482 Pleroma.User.list_inactive_users_query()
1483 |> Pleroma.Repo.all()
1484 |> Enum.map(& &1.id)
1486 Enum.each(active, fn user ->
1487 refute user.id in inactive_users_ids
1490 Enum.each(inactive, fn user ->
1491 assert user.id in inactive_users_ids
1496 describe "toggle_confirmation/1" do
1497 test "if user is confirmed" do
1498 user = insert(:user, confirmation_pending: false)
1499 {:ok, user} = User.toggle_confirmation(user)
1501 assert user.confirmation_pending
1502 assert user.confirmation_token
1505 test "if user is unconfirmed" do
1506 user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
1507 {:ok, user} = User.toggle_confirmation(user)
1509 refute user.confirmation_pending
1510 refute user.confirmation_token
1514 describe "ensure_keys_present" do
1515 test "it creates keys for a user and stores them in info" do
1516 user = insert(:user)
1517 refute is_binary(user.keys)
1518 {:ok, user} = User.ensure_keys_present(user)
1519 assert is_binary(user.keys)
1522 test "it doesn't create keys if there already are some" do
1523 user = insert(:user, keys: "xxx")
1524 {:ok, user} = User.ensure_keys_present(user)
1525 assert user.keys == "xxx"
1529 describe "get_ap_ids_by_nicknames" do
1530 test "it returns a list of AP ids for a given set of nicknames" do
1531 user = insert(:user)
1532 user_two = insert(:user)
1534 ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
1535 assert length(ap_ids) == 2
1536 assert user.ap_id in ap_ids
1537 assert user_two.ap_id in ap_ids
1541 describe "sync followers count" do
1543 user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
1544 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
1545 insert(:user, local: true)
1546 insert(:user, local: false, deactivated: true)
1547 {:ok, user1: user1, user2: user2}
1550 test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
1551 [fdb_user1] = User.external_users(limit: 1)
1553 assert fdb_user1.ap_id
1554 assert fdb_user1.ap_id == user1.ap_id
1555 assert fdb_user1.id == user1.id
1557 [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
1559 assert fdb_user2.ap_id
1560 assert fdb_user2.ap_id == user2.ap_id
1561 assert fdb_user2.id == user2.id
1563 assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
1567 describe "is_internal_user?/1" do
1568 test "non-internal user returns false" do
1569 user = insert(:user)
1570 refute User.is_internal_user?(user)
1573 test "user with no nickname returns true" do
1574 user = insert(:user, %{nickname: nil})
1575 assert User.is_internal_user?(user)
1578 test "user with internal-prefixed nickname returns true" do
1579 user = insert(:user, %{nickname: "internal.test"})
1580 assert User.is_internal_user?(user)
1584 describe "update_and_set_cache/1" do
1585 test "returns error when user is stale instead Ecto.StaleEntryError" do
1586 user = insert(:user)
1588 changeset = Ecto.Changeset.change(user, bio: "test")
1592 assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
1593 User.update_and_set_cache(changeset)
1596 test "performs update cache if user updated" do
1597 user = insert(:user)
1598 assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1600 changeset = Ecto.Changeset.change(user, bio: "test-bio")
1602 assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
1603 assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1604 assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
1608 describe "following/followers synchronization" do
1609 clear_config([:instance, :external_user_synchronization])
1611 test "updates the counters normally on following/getting a follow when disabled" do
1612 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1613 user = insert(:user)
1618 follower_address: "http://localhost:4001/users/masto_closed/followers",
1619 following_address: "http://localhost:4001/users/masto_closed/following",
1623 assert other_user.following_count == 0
1624 assert other_user.follower_count == 0
1626 {:ok, user} = Pleroma.User.follow(user, other_user)
1627 other_user = Pleroma.User.get_by_id(other_user.id)
1629 assert user.following_count == 1
1630 assert other_user.follower_count == 1
1633 test "syncronizes the counters with the remote instance for the followed when enabled" do
1634 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1636 user = insert(:user)
1641 follower_address: "http://localhost:4001/users/masto_closed/followers",
1642 following_address: "http://localhost:4001/users/masto_closed/following",
1646 assert other_user.following_count == 0
1647 assert other_user.follower_count == 0
1649 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1650 {:ok, _user} = User.follow(user, other_user)
1651 other_user = User.get_by_id(other_user.id)
1653 assert other_user.follower_count == 437
1656 test "syncronizes the counters with the remote instance for the follower when enabled" do
1657 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1659 user = insert(:user)
1664 follower_address: "http://localhost:4001/users/masto_closed/followers",
1665 following_address: "http://localhost:4001/users/masto_closed/following",
1669 assert other_user.following_count == 0
1670 assert other_user.follower_count == 0
1672 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1673 {:ok, other_user} = User.follow(other_user, user)
1675 assert other_user.following_count == 152
1679 describe "change_email/2" do
1681 [user: insert(:user)]
1684 test "blank email returns error", %{user: user} do
1685 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
1686 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
1689 test "non unique email returns error", %{user: user} do
1690 %{email: email} = insert(:user)
1692 assert {:error, %{errors: [email: {"has already been taken", _}]}} =
1693 User.change_email(user, email)
1696 test "invalid email returns error", %{user: user} do
1697 assert {:error, %{errors: [email: {"has invalid format", _}]}} =
1698 User.change_email(user, "cofe")
1701 test "changes email", %{user: user} do
1702 assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
1706 describe "get_cached_by_nickname_or_id" do
1708 limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
1709 local_user = insert(:user)
1710 remote_user = insert(:user, nickname: "nickname@example.com", local: false)
1713 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
1716 [local_user: local_user, remote_user: remote_user]
1719 test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
1720 remote_user: remote_user
1722 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1723 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1725 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1726 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1728 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1729 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1732 test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
1733 %{remote_user: remote_user} do
1734 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1735 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1738 test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
1739 %{remote_user: remote_user, local_user: local_user} do
1740 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1741 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
1744 test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
1745 %{remote_user: remote_user} do
1746 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1747 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1750 test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
1751 %{local_user: local_user} do
1752 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1753 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1755 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1756 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1758 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1759 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1763 describe "update_email_notifications/2" do
1765 user = insert(:user, email_notifications: %{"digest" => true})
1770 test "Notifications are updated", %{user: user} do
1771 true = user.email_notifications["digest"]
1772 assert {:ok, result} = User.update_email_notifications(user, %{"digest" => false})
1773 assert result.email_notifications["digest"] == false