1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.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
18 import Pleroma.Factory
19 import ExUnit.CaptureLog
22 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
26 setup do: clear_config([:instance, :account_activation_required])
28 describe "service actors" do
29 test "returns updated invisible actor" do
30 uri = "#{Pleroma.Web.Endpoint.url()}/relay"
31 followers_uri = "#{uri}/followers"
40 follower_address: followers_uri
44 actor = User.get_or_create_service_actor_by_ap_id(uri, "relay")
45 assert actor.invisible
48 test "returns relay user" do
49 uri = "#{Pleroma.Web.Endpoint.url()}/relay"
50 followers_uri = "#{uri}/followers"
57 follower_address: ^followers_uri
58 } = User.get_or_create_service_actor_by_ap_id(uri, "relay")
60 assert capture_log(fn ->
61 refute User.get_or_create_service_actor_by_ap_id("/relay", "relay")
62 end) =~ "Cannot create service actor:"
65 test "returns invisible actor" do
66 uri = "#{Pleroma.Web.Endpoint.url()}/internal/fetch-test"
67 followers_uri = "#{uri}/followers"
68 user = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
71 nickname: "internal.fetch-test",
75 follower_address: ^followers_uri
78 user2 = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
79 assert user.id == user2.id
83 describe "AP ID user relationships" do
85 {:ok, user: insert(:user)}
88 test "outgoing_relationships_ap_ids/1", %{user: user} do
89 rel_types = [:block, :mute, :notification_mute, :reblog_mute, :inverse_subscription]
97 insert_list(2, :user_relationship, %{source: user, relationship_type: rel_type})
99 ap_ids = Enum.map(rel_records, fn rr -> Repo.preload(rr, :target).target.ap_id end)
100 {rel_type, Enum.sort(ap_ids)}
104 assert ap_ids_by_rel[:block] == Enum.sort(User.blocked_users_ap_ids(user))
105 assert ap_ids_by_rel[:block] == Enum.sort(Enum.map(User.blocked_users(user), & &1.ap_id))
107 assert ap_ids_by_rel[:mute] == Enum.sort(User.muted_users_ap_ids(user))
108 assert ap_ids_by_rel[:mute] == Enum.sort(Enum.map(User.muted_users(user), & &1.ap_id))
110 assert ap_ids_by_rel[:notification_mute] ==
111 Enum.sort(User.notification_muted_users_ap_ids(user))
113 assert ap_ids_by_rel[:notification_mute] ==
114 Enum.sort(Enum.map(User.notification_muted_users(user), & &1.ap_id))
116 assert ap_ids_by_rel[:reblog_mute] == Enum.sort(User.reblog_muted_users_ap_ids(user))
118 assert ap_ids_by_rel[:reblog_mute] ==
119 Enum.sort(Enum.map(User.reblog_muted_users(user), & &1.ap_id))
121 assert ap_ids_by_rel[:inverse_subscription] == Enum.sort(User.subscriber_users_ap_ids(user))
123 assert ap_ids_by_rel[:inverse_subscription] ==
124 Enum.sort(Enum.map(User.subscriber_users(user), & &1.ap_id))
126 outgoing_relationships_ap_ids = User.outgoing_relationships_ap_ids(user, rel_types)
128 assert ap_ids_by_rel ==
129 Enum.into(outgoing_relationships_ap_ids, %{}, fn {k, v} -> {k, Enum.sort(v)} end)
133 describe "when tags are nil" do
134 test "tagging a user" do
135 user = insert(:user, %{tags: nil})
136 user = User.tag(user, ["cool", "dude"])
138 assert "cool" in user.tags
139 assert "dude" in user.tags
142 test "untagging a user" do
143 user = insert(:user, %{tags: nil})
144 user = User.untag(user, ["cool", "dude"])
146 assert user.tags == []
150 test "ap_id returns the activity pub id for the user" do
151 user = UserBuilder.build()
153 expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
155 assert expected_ap_id == User.ap_id(user)
158 test "ap_followers returns the followers collection for the user" do
159 user = UserBuilder.build()
161 expected_followers_collection = "#{User.ap_id(user)}/followers"
163 assert expected_followers_collection == User.ap_followers(user)
166 test "ap_following returns the following collection for the user" do
167 user = UserBuilder.build()
169 expected_followers_collection = "#{User.ap_id(user)}/following"
171 assert expected_followers_collection == User.ap_following(user)
174 test "returns all pending follow requests" do
175 unlocked = insert(:user)
176 locked = insert(:user, locked: true)
177 follower = insert(:user)
179 CommonAPI.follow(follower, unlocked)
180 CommonAPI.follow(follower, locked)
182 assert [] = User.get_follow_requests(unlocked)
183 assert [activity] = User.get_follow_requests(locked)
188 test "doesn't return already accepted or duplicate follow requests" do
189 locked = insert(:user, locked: true)
190 pending_follower = insert(:user)
191 accepted_follower = insert(:user)
193 CommonAPI.follow(pending_follower, locked)
194 CommonAPI.follow(pending_follower, locked)
195 CommonAPI.follow(accepted_follower, locked)
197 Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept)
199 assert [^pending_follower] = User.get_follow_requests(locked)
202 test "clears follow requests when requester is blocked" do
203 followed = insert(:user, locked: true)
204 follower = insert(:user)
206 CommonAPI.follow(follower, followed)
207 assert [_activity] = User.get_follow_requests(followed)
209 {:ok, _user_relationship} = User.block(followed, follower)
210 assert [] = User.get_follow_requests(followed)
213 test "follow_all follows mutliple users" do
215 followed_zero = insert(:user)
216 followed_one = insert(:user)
217 followed_two = insert(:user)
218 blocked = insert(:user)
219 not_followed = insert(:user)
220 reverse_blocked = insert(:user)
222 {:ok, _user_relationship} = User.block(user, blocked)
223 {:ok, _user_relationship} = User.block(reverse_blocked, user)
225 {:ok, user} = User.follow(user, followed_zero)
227 {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
229 assert User.following?(user, followed_one)
230 assert User.following?(user, followed_two)
231 assert User.following?(user, followed_zero)
232 refute User.following?(user, not_followed)
233 refute User.following?(user, blocked)
234 refute User.following?(user, reverse_blocked)
237 test "follow_all follows mutliple users without duplicating" do
239 followed_zero = insert(:user)
240 followed_one = insert(:user)
241 followed_two = insert(:user)
243 {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
244 assert length(User.following(user)) == 3
246 {:ok, user} = User.follow_all(user, [followed_one, followed_two])
247 assert length(User.following(user)) == 4
250 test "follow takes a user and another user" do
252 followed = insert(:user)
254 {:ok, user} = User.follow(user, followed)
256 user = User.get_cached_by_id(user.id)
257 followed = User.get_cached_by_ap_id(followed.ap_id)
259 assert followed.follower_count == 1
260 assert user.following_count == 1
262 assert User.ap_followers(followed) in User.following(user)
265 test "can't follow a deactivated users" do
267 followed = insert(:user, %{deactivated: true})
269 {:error, _} = User.follow(user, followed)
272 test "can't follow a user who blocked us" do
273 blocker = insert(:user)
274 blockee = insert(:user)
276 {:ok, _user_relationship} = User.block(blocker, blockee)
278 {:error, _} = User.follow(blockee, blocker)
281 test "can't subscribe to a user who blocked us" do
282 blocker = insert(:user)
283 blocked = insert(:user)
285 {:ok, _user_relationship} = User.block(blocker, blocked)
287 {:error, _} = User.subscribe(blocked, blocker)
290 test "local users do not automatically follow local locked accounts" do
291 follower = insert(:user, locked: true)
292 followed = insert(:user, locked: true)
294 {:ok, follower} = User.maybe_direct_follow(follower, followed)
296 refute User.following?(follower, followed)
299 describe "unfollow/2" do
300 setup do: clear_config([:instance, :external_user_synchronization])
302 test "unfollow with syncronizes external user" do
303 Pleroma.Config.put([:instance, :external_user_synchronization], true)
308 follower_address: "http://localhost:4001/users/fuser1/followers",
309 following_address: "http://localhost:4001/users/fuser1/following",
310 ap_id: "http://localhost:4001/users/fuser1"
317 ap_id: "http://localhost:4001/users/fuser2",
318 follower_address: "http://localhost:4001/users/fuser2/followers",
319 following_address: "http://localhost:4001/users/fuser2/following"
322 {:ok, user} = User.follow(user, followed, :follow_accept)
324 {:ok, user, _activity} = User.unfollow(user, followed)
326 user = User.get_cached_by_id(user.id)
328 assert User.following(user) == []
331 test "unfollow takes a user and another user" do
332 followed = insert(:user)
335 {:ok, user} = User.follow(user, followed, :follow_accept)
337 assert User.following(user) == [user.follower_address, followed.follower_address]
339 {:ok, user, _activity} = User.unfollow(user, followed)
341 assert User.following(user) == [user.follower_address]
344 test "unfollow doesn't unfollow yourself" do
347 {:error, _} = User.unfollow(user, user)
349 assert User.following(user) == [user.follower_address]
353 test "test if a user is following another user" do
354 followed = insert(:user)
356 User.follow(user, followed, :follow_accept)
358 assert User.following?(user, followed)
359 refute User.following?(followed, user)
362 test "fetches correct profile for nickname beginning with number" do
363 # Use old-style integer ID to try to reproduce the problem
364 user = insert(:user, %{id: 1080})
365 user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
366 assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
369 describe "user registration" do
375 password_confirmation: "test",
376 email: "email@example.com"
378 setup do: clear_config([:instance, :autofollowed_nicknames])
379 setup do: clear_config([:instance, :welcome_message])
380 setup do: clear_config([:instance, :welcome_user_nickname])
382 test "it autofollows accounts that are set for it" do
384 remote_user = insert(:user, %{local: false})
386 Pleroma.Config.put([:instance, :autofollowed_nicknames], [
391 cng = User.register_changeset(%User{}, @full_user_data)
393 {:ok, registered_user} = User.register(cng)
395 assert User.following?(registered_user, user)
396 refute User.following?(registered_user, remote_user)
399 test "it sends a welcome message if it is set" do
400 welcome_user = insert(:user)
402 Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
403 Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
405 cng = User.register_changeset(%User{}, @full_user_data)
406 {:ok, registered_user} = User.register(cng)
408 activity = Repo.one(Pleroma.Activity)
409 assert registered_user.ap_id in activity.recipients
410 assert Object.normalize(activity).data["content"] =~ "cool site"
411 assert activity.actor == welcome_user.ap_id
414 setup do: clear_config([:instance, :account_activation_required])
416 test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
417 Pleroma.Config.put([:instance, :account_activation_required], true)
421 |> Enum.each(fn key ->
422 params = Map.delete(@full_user_data, key)
423 changeset = User.register_changeset(%User{}, params)
425 assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
429 test "it requires an name, nickname and password, bio and email are optional when account_activation_required is disabled" do
430 Pleroma.Config.put([:instance, :account_activation_required], false)
434 |> Enum.each(fn key ->
435 params = Map.delete(@full_user_data, key)
436 changeset = User.register_changeset(%User{}, params)
438 assert if key in [:bio, :email], do: changeset.valid?, else: not changeset.valid?
442 test "it restricts certain nicknames" do
443 [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
445 assert is_bitstring(restricted_name)
449 |> Map.put(:nickname, restricted_name)
451 changeset = User.register_changeset(%User{}, params)
453 refute changeset.valid?
456 test "it sets the password_hash and ap_id" do
457 changeset = User.register_changeset(%User{}, @full_user_data)
459 assert changeset.valid?
461 assert is_binary(changeset.changes[:password_hash])
462 assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
464 assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
468 describe "user registration, with :account_activation_required" do
474 password_confirmation: "test",
475 email: "email@example.com"
477 setup do: clear_config([:instance, :account_activation_required], true)
479 test "it creates unconfirmed user" do
480 changeset = User.register_changeset(%User{}, @full_user_data)
481 assert changeset.valid?
483 {:ok, user} = Repo.insert(changeset)
485 assert user.confirmation_pending
486 assert user.confirmation_token
489 test "it creates confirmed user if :confirmed option is given" do
490 changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
491 assert changeset.valid?
493 {:ok, user} = Repo.insert(changeset)
495 refute user.confirmation_pending
496 refute user.confirmation_token
500 describe "get_or_fetch/1" do
501 test "gets an existing user by nickname" do
503 {:ok, fetched_user} = User.get_or_fetch(user.nickname)
505 assert user == fetched_user
508 test "gets an existing user by ap_id" do
509 ap_id = "http://mastodon.example.org/users/admin"
515 nickname: "admin@mastodon.example.org",
519 {:ok, fetched_user} = User.get_or_fetch(ap_id)
520 freshed_user = refresh_record(user)
521 assert freshed_user == fetched_user
525 describe "fetching a user from nickname or trying to build one" do
526 test "gets an existing user" do
528 {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
530 assert user == fetched_user
533 test "gets an existing user, case insensitive" do
534 user = insert(:user, nickname: "nick")
535 {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
537 assert user == fetched_user
540 test "gets an existing user by fully qualified nickname" do
543 {:ok, fetched_user} =
544 User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
546 assert user == fetched_user
549 test "gets an existing user by fully qualified nickname, case insensitive" do
550 user = insert(:user, nickname: "nick")
551 casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
553 {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
555 assert user == fetched_user
558 test "returns nil if no user could be fetched" do
559 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
560 assert fetched_user == "not found nonexistant@social.heldscal.la"
563 test "returns nil for nonexistant local user" do
564 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
565 assert fetched_user == "not found nonexistant"
568 test "updates an existing user, if stale" do
569 a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
575 nickname: "admin@mastodon.example.org",
576 ap_id: "http://mastodon.example.org/users/admin",
577 last_refreshed_at: a_week_ago
580 assert orig_user.last_refreshed_at == a_week_ago
582 {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
586 refute user.last_refreshed_at == orig_user.last_refreshed_at
590 test "returns an ap_id for a user" do
593 assert User.ap_id(user) ==
594 Pleroma.Web.Router.Helpers.user_feed_url(
595 Pleroma.Web.Endpoint,
601 test "returns an ap_followers link for a user" do
604 assert User.ap_followers(user) ==
605 Pleroma.Web.Router.Helpers.user_feed_url(
606 Pleroma.Web.Endpoint,
612 describe "remote user changeset" do
618 avatar: %{some: "avatar"}
620 setup do: clear_config([:instance, :user_bio_length])
621 setup do: clear_config([:instance, :user_name_length])
623 test "it confirms validity" do
624 cs = User.remote_user_changeset(@valid_remote)
628 test "it sets the follower_adress" do
629 cs = User.remote_user_changeset(@valid_remote)
630 # remote users get a fake local follower address
631 assert cs.changes.follower_address ==
632 User.ap_followers(%User{nickname: @valid_remote[:nickname]})
635 test "it enforces the fqn format for nicknames" do
636 cs = User.remote_user_changeset(%{@valid_remote | nickname: "bla"})
637 assert Ecto.Changeset.get_field(cs, :local) == false
638 assert cs.changes.avatar
642 test "it has required fields" do
644 |> Enum.each(fn field ->
645 cs = User.remote_user_changeset(Map.delete(@valid_remote, field))
651 describe "followers and friends" do
652 test "gets all followers for a given user" do
654 follower_one = insert(:user)
655 follower_two = insert(:user)
656 not_follower = insert(:user)
658 {:ok, follower_one} = User.follow(follower_one, user)
659 {:ok, follower_two} = User.follow(follower_two, user)
661 res = User.get_followers(user)
663 assert Enum.member?(res, follower_one)
664 assert Enum.member?(res, follower_two)
665 refute Enum.member?(res, not_follower)
668 test "gets all friends (followed users) for a given user" do
670 followed_one = insert(:user)
671 followed_two = insert(:user)
672 not_followed = insert(:user)
674 {:ok, user} = User.follow(user, followed_one)
675 {:ok, user} = User.follow(user, followed_two)
677 res = User.get_friends(user)
679 followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
680 followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
681 assert Enum.member?(res, followed_one)
682 assert Enum.member?(res, followed_two)
683 refute Enum.member?(res, not_followed)
687 describe "updating note and follower count" do
688 test "it sets the note_count property" do
691 user = User.get_cached_by_ap_id(note.data["actor"])
693 assert user.note_count == 0
695 {:ok, user} = User.update_note_count(user)
697 assert user.note_count == 1
700 test "it increases the note_count property" do
702 user = User.get_cached_by_ap_id(note.data["actor"])
704 assert user.note_count == 0
706 {:ok, user} = User.increase_note_count(user)
708 assert user.note_count == 1
710 {:ok, user} = User.increase_note_count(user)
712 assert user.note_count == 2
715 test "it decreases the note_count property" do
717 user = User.get_cached_by_ap_id(note.data["actor"])
719 assert user.note_count == 0
721 {:ok, user} = User.increase_note_count(user)
723 assert user.note_count == 1
725 {:ok, user} = User.decrease_note_count(user)
727 assert user.note_count == 0
729 {:ok, user} = User.decrease_note_count(user)
731 assert user.note_count == 0
734 test "it sets the follower_count property" do
736 follower = insert(:user)
738 User.follow(follower, user)
740 assert user.follower_count == 0
742 {:ok, user} = User.update_follower_count(user)
744 assert user.follower_count == 1
748 describe "follow_import" do
749 test "it imports user followings from list" do
750 [user1, user2, user3] = insert_list(3, :user)
757 {:ok, job} = User.follow_import(user1, identifiers)
759 assert {:ok, result} = ObanHelpers.perform(job)
760 assert is_list(result)
761 assert result == [user2, user3]
766 test "it mutes people" do
768 muted_user = insert(:user)
770 refute User.mutes?(user, muted_user)
771 refute User.muted_notifications?(user, muted_user)
773 {:ok, _user_relationships} = User.mute(user, muted_user)
775 assert User.mutes?(user, muted_user)
776 assert User.muted_notifications?(user, muted_user)
779 test "it unmutes users" do
781 muted_user = insert(:user)
783 {:ok, _user_relationships} = User.mute(user, muted_user)
784 {:ok, _user_mute} = User.unmute(user, muted_user)
786 refute User.mutes?(user, muted_user)
787 refute User.muted_notifications?(user, muted_user)
790 test "it mutes user without notifications" do
792 muted_user = insert(:user)
794 refute User.mutes?(user, muted_user)
795 refute User.muted_notifications?(user, muted_user)
797 {:ok, _user_relationships} = User.mute(user, muted_user, false)
799 assert User.mutes?(user, muted_user)
800 refute User.muted_notifications?(user, muted_user)
805 test "it blocks people" do
807 blocked_user = insert(:user)
809 refute User.blocks?(user, blocked_user)
811 {:ok, _user_relationship} = User.block(user, blocked_user)
813 assert User.blocks?(user, blocked_user)
816 test "it unblocks users" do
818 blocked_user = insert(:user)
820 {:ok, _user_relationship} = User.block(user, blocked_user)
821 {:ok, _user_block} = User.unblock(user, blocked_user)
823 refute User.blocks?(user, blocked_user)
826 test "blocks tear down cyclical follow relationships" do
827 blocker = insert(:user)
828 blocked = insert(:user)
830 {:ok, blocker} = User.follow(blocker, blocked)
831 {:ok, blocked} = User.follow(blocked, blocker)
833 assert User.following?(blocker, blocked)
834 assert User.following?(blocked, blocker)
836 {:ok, _user_relationship} = User.block(blocker, blocked)
837 blocked = User.get_cached_by_id(blocked.id)
839 assert User.blocks?(blocker, blocked)
841 refute User.following?(blocker, blocked)
842 refute User.following?(blocked, blocker)
845 test "blocks tear down blocker->blocked follow relationships" do
846 blocker = insert(:user)
847 blocked = insert(:user)
849 {:ok, blocker} = User.follow(blocker, blocked)
851 assert User.following?(blocker, blocked)
852 refute User.following?(blocked, blocker)
854 {:ok, _user_relationship} = User.block(blocker, blocked)
855 blocked = User.get_cached_by_id(blocked.id)
857 assert User.blocks?(blocker, blocked)
859 refute User.following?(blocker, blocked)
860 refute User.following?(blocked, blocker)
863 test "blocks tear down blocked->blocker follow relationships" do
864 blocker = insert(:user)
865 blocked = insert(:user)
867 {:ok, blocked} = User.follow(blocked, blocker)
869 refute User.following?(blocker, blocked)
870 assert User.following?(blocked, blocker)
872 {:ok, _user_relationship} = User.block(blocker, blocked)
873 blocked = User.get_cached_by_id(blocked.id)
875 assert User.blocks?(blocker, blocked)
877 refute User.following?(blocker, blocked)
878 refute User.following?(blocked, blocker)
881 test "blocks tear down blocked->blocker subscription relationships" do
882 blocker = insert(:user)
883 blocked = insert(:user)
885 {:ok, _subscription} = User.subscribe(blocked, blocker)
887 assert User.subscribed_to?(blocked, blocker)
888 refute User.subscribed_to?(blocker, blocked)
890 {:ok, _user_relationship} = User.block(blocker, blocked)
892 assert User.blocks?(blocker, blocked)
893 refute User.subscribed_to?(blocker, blocked)
894 refute User.subscribed_to?(blocked, blocker)
898 describe "domain blocking" do
899 test "blocks domains" do
901 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
903 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
905 assert User.blocks?(user, collateral_user)
908 test "does not block domain with same end" do
912 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
914 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
916 refute User.blocks?(user, collateral_user)
919 test "does not block domain with same end if wildcard added" do
923 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
925 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
927 refute User.blocks?(user, collateral_user)
930 test "blocks domain with wildcard for subdomain" do
933 user_from_subdomain =
934 insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
936 user_with_two_subdomains =
938 ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
941 user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
943 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
945 assert User.blocks?(user, user_from_subdomain)
946 assert User.blocks?(user, user_with_two_subdomains)
947 assert User.blocks?(user, user_domain)
950 test "unblocks domains" do
952 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
954 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
955 {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
957 refute User.blocks?(user, collateral_user)
960 test "follows take precedence over domain blocks" do
962 good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
964 {:ok, user} = User.block_domain(user, "meanies.social")
965 {:ok, user} = User.follow(user, good_eggo)
967 refute User.blocks?(user, good_eggo)
971 describe "blocks_import" do
972 test "it imports user blocks from list" do
973 [user1, user2, user3] = insert_list(3, :user)
980 {:ok, job} = User.blocks_import(user1, identifiers)
982 assert {:ok, result} = ObanHelpers.perform(job)
983 assert is_list(result)
984 assert result == [user2, user3]
988 describe "get_recipients_from_activity" do
989 test "works for announces" do
990 actor = insert(:user)
991 user = insert(:user, local: true)
993 {:ok, activity} = CommonAPI.post(actor, %{"status" => "hello"})
994 {:ok, announce, _} = CommonAPI.repeat(activity.id, user)
996 recipients = User.get_recipients_from_activity(announce)
998 assert user in recipients
1001 test "get recipients" do
1002 actor = insert(:user)
1003 user = insert(:user, local: true)
1004 user_two = insert(:user, local: false)
1005 addressed = insert(:user, local: true)
1006 addressed_remote = insert(:user, local: false)
1009 CommonAPI.post(actor, %{
1010 "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
1013 assert Enum.map([actor, addressed], & &1.ap_id) --
1014 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
1016 {:ok, user} = User.follow(user, actor)
1017 {:ok, _user_two} = User.follow(user_two, actor)
1018 recipients = User.get_recipients_from_activity(activity)
1019 assert length(recipients) == 3
1020 assert user in recipients
1021 assert addressed in recipients
1024 test "has following" do
1025 actor = insert(:user)
1026 user = insert(:user)
1027 user_two = insert(:user)
1028 addressed = insert(:user, local: true)
1031 CommonAPI.post(actor, %{
1032 "status" => "hey @#{addressed.nickname}"
1035 assert Enum.map([actor, addressed], & &1.ap_id) --
1036 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
1038 {:ok, _actor} = User.follow(actor, user)
1039 {:ok, _actor} = User.follow(actor, user_two)
1040 recipients = User.get_recipients_from_activity(activity)
1041 assert length(recipients) == 2
1042 assert addressed in recipients
1046 describe ".deactivate" do
1047 test "can de-activate then re-activate a user" do
1048 user = insert(:user)
1049 assert false == user.deactivated
1050 {:ok, user} = User.deactivate(user)
1051 assert true == user.deactivated
1052 {:ok, user} = User.deactivate(user, false)
1053 assert false == user.deactivated
1056 test "hide a user from followers" do
1057 user = insert(:user)
1058 user2 = insert(:user)
1060 {:ok, user} = User.follow(user, user2)
1061 {:ok, _user} = User.deactivate(user)
1063 user2 = User.get_cached_by_id(user2.id)
1065 assert user2.follower_count == 0
1066 assert [] = User.get_followers(user2)
1069 test "hide a user from friends" do
1070 user = insert(:user)
1071 user2 = insert(:user)
1073 {:ok, user2} = User.follow(user2, user)
1074 assert user2.following_count == 1
1075 assert User.following_count(user2) == 1
1077 {:ok, _user} = User.deactivate(user)
1079 user2 = User.get_cached_by_id(user2.id)
1081 assert refresh_record(user2).following_count == 0
1082 assert user2.following_count == 0
1083 assert User.following_count(user2) == 0
1084 assert [] = User.get_friends(user2)
1087 test "hide a user's statuses from timelines and notifications" do
1088 user = insert(:user)
1089 user2 = insert(:user)
1091 {:ok, user2} = User.follow(user2, user)
1093 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
1095 activity = Repo.preload(activity, :bookmark)
1097 [notification] = Pleroma.Notification.for_user(user2)
1098 assert notification.activity.id == activity.id
1100 assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
1102 assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
1103 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1107 {:ok, _user} = User.deactivate(user)
1109 assert [] == ActivityPub.fetch_public_activities(%{})
1110 assert [] == Pleroma.Notification.for_user(user2)
1113 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1119 describe "delete" do
1121 {:ok, user} = insert(:user) |> User.set_cache()
1126 setup do: clear_config([:instance, :federating])
1128 test ".delete_user_activities deletes all create activities", %{user: user} do
1129 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
1131 User.delete_user_activities(user)
1133 # TODO: Test removal favorites, repeats, delete activities.
1134 refute Activity.get_by_id(activity.id)
1137 test "it deletes deactivated user" do
1138 {:ok, user} = insert(:user, deactivated: true) |> User.set_cache()
1140 {:ok, job} = User.delete(user)
1141 {:ok, _user} = ObanHelpers.perform(job)
1143 refute User.get_by_id(user.id)
1146 test "it deletes a user, all follow relationships and all activities", %{user: user} do
1147 follower = insert(:user)
1148 {:ok, follower} = User.follow(follower, user)
1150 object = insert(:note, user: user)
1151 activity = insert(:note_activity, user: user, note: object)
1153 object_two = insert(:note, user: follower)
1154 activity_two = insert(:note_activity, user: follower, note: object_two)
1156 {:ok, like} = CommonAPI.favorite(user, activity_two.id)
1157 {:ok, like_two} = CommonAPI.favorite(follower, activity.id)
1158 {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
1160 {:ok, job} = User.delete(user)
1161 {:ok, _user} = ObanHelpers.perform(job)
1163 follower = User.get_cached_by_id(follower.id)
1165 refute User.following?(follower, user)
1166 refute User.get_by_id(user.id)
1167 assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1171 |> Activity.Queries.by_actor()
1173 |> Enum.map(fn act -> act.data["type"] end)
1175 assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
1177 refute Activity.get_by_id(activity.id)
1178 refute Activity.get_by_id(like.id)
1179 refute Activity.get_by_id(like_two.id)
1180 refute Activity.get_by_id(repeat.id)
1184 test "get_public_key_for_ap_id fetches a user that's not in the db" do
1185 assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
1188 describe "per-user rich-text filtering" do
1189 test "html_filter_policy returns default policies, when rich-text is enabled" do
1190 user = insert(:user)
1192 assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
1195 test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
1196 user = insert(:user, no_rich_text: true)
1198 assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
1202 describe "caching" do
1203 test "invalidate_cache works" do
1204 user = insert(:user)
1206 User.set_cache(user)
1207 User.invalidate_cache(user)
1209 {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1210 {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
1213 test "User.delete() plugs any possible zombie objects" do
1214 user = insert(:user)
1216 {:ok, job} = User.delete(user)
1217 {:ok, _} = ObanHelpers.perform(job)
1219 {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1221 assert cached_user != user
1223 {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
1225 assert cached_user != user
1229 describe "account_status/1" do
1230 setup do: clear_config([:instance, :account_activation_required])
1232 test "return confirmation_pending for unconfirm user" do
1233 Pleroma.Config.put([:instance, :account_activation_required], true)
1234 user = insert(:user, confirmation_pending: true)
1235 assert User.account_status(user) == :confirmation_pending
1238 test "return active for confirmed user" do
1239 Pleroma.Config.put([:instance, :account_activation_required], true)
1240 user = insert(:user, confirmation_pending: false)
1241 assert User.account_status(user) == :active
1244 test "return active for remote user" do
1245 user = insert(:user, local: false)
1246 assert User.account_status(user) == :active
1249 test "returns :password_reset_pending for user with reset password" do
1250 user = insert(:user, password_reset_pending: true)
1251 assert User.account_status(user) == :password_reset_pending
1254 test "returns :deactivated for deactivated user" do
1255 user = insert(:user, local: true, confirmation_pending: false, deactivated: true)
1256 assert User.account_status(user) == :deactivated
1260 describe "superuser?/1" do
1261 test "returns false for unprivileged users" do
1262 user = insert(:user, local: true)
1264 refute User.superuser?(user)
1267 test "returns false for remote users" do
1268 user = insert(:user, local: false)
1269 remote_admin_user = insert(:user, local: false, is_admin: true)
1271 refute User.superuser?(user)
1272 refute User.superuser?(remote_admin_user)
1275 test "returns true for local moderators" do
1276 user = insert(:user, local: true, is_moderator: true)
1278 assert User.superuser?(user)
1281 test "returns true for local admins" do
1282 user = insert(:user, local: true, is_admin: true)
1284 assert User.superuser?(user)
1288 describe "invisible?/1" do
1289 test "returns true for an invisible user" do
1290 user = insert(:user, local: true, invisible: true)
1292 assert User.invisible?(user)
1295 test "returns false for a non-invisible user" do
1296 user = insert(:user, local: true)
1298 refute User.invisible?(user)
1302 describe "visible_for?/2" do
1303 test "returns true when the account is itself" do
1304 user = insert(:user, local: true)
1306 assert User.visible_for?(user, user)
1309 test "returns false when the account is unauthenticated and auth is required" do
1310 Pleroma.Config.put([:instance, :account_activation_required], true)
1312 user = insert(:user, local: true, confirmation_pending: true)
1313 other_user = insert(:user, local: true)
1315 refute User.visible_for?(user, other_user)
1318 test "returns true when the account is unauthenticated and auth is not required" do
1319 user = insert(:user, local: true, confirmation_pending: true)
1320 other_user = insert(:user, local: true)
1322 assert User.visible_for?(user, other_user)
1325 test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
1326 Pleroma.Config.put([:instance, :account_activation_required], true)
1328 user = insert(:user, local: true, confirmation_pending: true)
1329 other_user = insert(:user, local: true, is_admin: true)
1331 assert User.visible_for?(user, other_user)
1335 describe "parse_bio/2" do
1336 test "preserves hosts in user links text" do
1337 remote_user = insert(:user, local: false, nickname: "nick@domain.com")
1338 user = insert(:user)
1339 bio = "A.k.a. @nick@domain.com"
1342 ~s(A.k.a. <span class="h-card"><a class="u-url mention" data-user="#{remote_user.id}" href="#{
1344 }" rel="ugc">@<span>nick@domain.com</span></a></span>)
1346 assert expected_text == User.parse_bio(bio, user)
1349 test "Adds rel=me on linkbacked urls" do
1350 user = insert(:user, ap_id: "https://social.example.org/users/lain")
1352 bio = "http://example.com/rel_me/null"
1353 expected_text = "<a href=\"#{bio}\">#{bio}</a>"
1354 assert expected_text == User.parse_bio(bio, user)
1356 bio = "http://example.com/rel_me/link"
1357 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1358 assert expected_text == User.parse_bio(bio, user)
1360 bio = "http://example.com/rel_me/anchor"
1361 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1362 assert expected_text == User.parse_bio(bio, user)
1366 test "follower count is updated when a follower is blocked" do
1367 user = insert(:user)
1368 follower = insert(:user)
1369 follower2 = insert(:user)
1370 follower3 = insert(:user)
1372 {:ok, follower} = User.follow(follower, user)
1373 {:ok, _follower2} = User.follow(follower2, user)
1374 {:ok, _follower3} = User.follow(follower3, user)
1376 {:ok, _user_relationship} = User.block(user, follower)
1377 user = refresh_record(user)
1379 assert user.follower_count == 2
1382 describe "list_inactive_users_query/1" do
1383 defp days_ago(days) do
1385 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
1386 -days * 60 * 60 * 24,
1391 test "Users are inactive by default" do
1395 Enum.map(1..total, fn _ ->
1396 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1399 inactive_users_ids =
1400 Pleroma.User.list_inactive_users_query()
1401 |> Pleroma.Repo.all()
1402 |> Enum.map(& &1.id)
1404 Enum.each(users, fn user ->
1405 assert user.id in inactive_users_ids
1409 test "Only includes users who has no recent activity" do
1413 Enum.map(1..total, fn _ ->
1414 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1417 {inactive, active} = Enum.split(users, trunc(total / 2))
1419 Enum.map(active, fn user ->
1420 to = Enum.random(users -- [user])
1423 CommonAPI.post(user, %{
1424 "status" => "hey @#{to.nickname}"
1428 inactive_users_ids =
1429 Pleroma.User.list_inactive_users_query()
1430 |> Pleroma.Repo.all()
1431 |> Enum.map(& &1.id)
1433 Enum.each(active, fn user ->
1434 refute user.id in inactive_users_ids
1437 Enum.each(inactive, fn user ->
1438 assert user.id in inactive_users_ids
1442 test "Only includes users with no read notifications" do
1446 Enum.map(1..total, fn _ ->
1447 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1450 [sender | recipients] = users
1451 {inactive, active} = Enum.split(recipients, trunc(total / 2))
1453 Enum.each(recipients, fn to ->
1455 CommonAPI.post(sender, %{
1456 "status" => "hey @#{to.nickname}"
1460 CommonAPI.post(sender, %{
1461 "status" => "hey again @#{to.nickname}"
1465 Enum.each(active, fn user ->
1466 [n1, _n2] = Pleroma.Notification.for_user(user)
1467 {:ok, _} = Pleroma.Notification.read_one(user, n1.id)
1470 inactive_users_ids =
1471 Pleroma.User.list_inactive_users_query()
1472 |> Pleroma.Repo.all()
1473 |> Enum.map(& &1.id)
1475 Enum.each(active, fn user ->
1476 refute user.id in inactive_users_ids
1479 Enum.each(inactive, fn user ->
1480 assert user.id in inactive_users_ids
1485 describe "toggle_confirmation/1" do
1486 test "if user is confirmed" do
1487 user = insert(:user, confirmation_pending: false)
1488 {:ok, user} = User.toggle_confirmation(user)
1490 assert user.confirmation_pending
1491 assert user.confirmation_token
1494 test "if user is unconfirmed" do
1495 user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
1496 {:ok, user} = User.toggle_confirmation(user)
1498 refute user.confirmation_pending
1499 refute user.confirmation_token
1503 describe "ensure_keys_present" do
1504 test "it creates keys for a user and stores them in info" do
1505 user = insert(:user)
1506 refute is_binary(user.keys)
1507 {:ok, user} = User.ensure_keys_present(user)
1508 assert is_binary(user.keys)
1511 test "it doesn't create keys if there already are some" do
1512 user = insert(:user, keys: "xxx")
1513 {:ok, user} = User.ensure_keys_present(user)
1514 assert user.keys == "xxx"
1518 describe "get_ap_ids_by_nicknames" do
1519 test "it returns a list of AP ids for a given set of nicknames" do
1520 user = insert(:user)
1521 user_two = insert(:user)
1523 ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
1524 assert length(ap_ids) == 2
1525 assert user.ap_id in ap_ids
1526 assert user_two.ap_id in ap_ids
1530 describe "sync followers count" do
1532 user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
1533 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
1534 insert(:user, local: true)
1535 insert(:user, local: false, deactivated: true)
1536 {:ok, user1: user1, user2: user2}
1539 test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
1540 [fdb_user1] = User.external_users(limit: 1)
1542 assert fdb_user1.ap_id
1543 assert fdb_user1.ap_id == user1.ap_id
1544 assert fdb_user1.id == user1.id
1546 [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
1548 assert fdb_user2.ap_id
1549 assert fdb_user2.ap_id == user2.ap_id
1550 assert fdb_user2.id == user2.id
1552 assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
1556 describe "is_internal_user?/1" do
1557 test "non-internal user returns false" do
1558 user = insert(:user)
1559 refute User.is_internal_user?(user)
1562 test "user with no nickname returns true" do
1563 user = insert(:user, %{nickname: nil})
1564 assert User.is_internal_user?(user)
1567 test "user with internal-prefixed nickname returns true" do
1568 user = insert(:user, %{nickname: "internal.test"})
1569 assert User.is_internal_user?(user)
1573 describe "update_and_set_cache/1" do
1574 test "returns error when user is stale instead Ecto.StaleEntryError" do
1575 user = insert(:user)
1577 changeset = Ecto.Changeset.change(user, bio: "test")
1581 assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
1582 User.update_and_set_cache(changeset)
1585 test "performs update cache if user updated" do
1586 user = insert(:user)
1587 assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1589 changeset = Ecto.Changeset.change(user, bio: "test-bio")
1591 assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
1592 assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1593 assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
1597 describe "following/followers synchronization" do
1598 setup do: clear_config([:instance, :external_user_synchronization])
1600 test "updates the counters normally on following/getting a follow when disabled" do
1601 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1602 user = insert(:user)
1607 follower_address: "http://localhost:4001/users/masto_closed/followers",
1608 following_address: "http://localhost:4001/users/masto_closed/following",
1612 assert other_user.following_count == 0
1613 assert other_user.follower_count == 0
1615 {:ok, user} = Pleroma.User.follow(user, other_user)
1616 other_user = Pleroma.User.get_by_id(other_user.id)
1618 assert user.following_count == 1
1619 assert other_user.follower_count == 1
1622 test "syncronizes the counters with the remote instance for the followed when enabled" do
1623 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1625 user = insert(:user)
1630 follower_address: "http://localhost:4001/users/masto_closed/followers",
1631 following_address: "http://localhost:4001/users/masto_closed/following",
1635 assert other_user.following_count == 0
1636 assert other_user.follower_count == 0
1638 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1639 {:ok, _user} = User.follow(user, other_user)
1640 other_user = User.get_by_id(other_user.id)
1642 assert other_user.follower_count == 437
1645 test "syncronizes the counters with the remote instance for the follower when enabled" do
1646 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1648 user = insert(:user)
1653 follower_address: "http://localhost:4001/users/masto_closed/followers",
1654 following_address: "http://localhost:4001/users/masto_closed/following",
1658 assert other_user.following_count == 0
1659 assert other_user.follower_count == 0
1661 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1662 {:ok, other_user} = User.follow(other_user, user)
1664 assert other_user.following_count == 152
1668 describe "change_email/2" do
1670 [user: insert(:user)]
1673 test "blank email returns error", %{user: user} do
1674 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
1675 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
1678 test "non unique email returns error", %{user: user} do
1679 %{email: email} = insert(:user)
1681 assert {:error, %{errors: [email: {"has already been taken", _}]}} =
1682 User.change_email(user, email)
1685 test "invalid email returns error", %{user: user} do
1686 assert {:error, %{errors: [email: {"has invalid format", _}]}} =
1687 User.change_email(user, "cofe")
1690 test "changes email", %{user: user} do
1691 assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
1695 describe "get_cached_by_nickname_or_id" do
1697 local_user = insert(:user)
1698 remote_user = insert(:user, nickname: "nickname@example.com", local: false)
1700 [local_user: local_user, remote_user: remote_user]
1703 setup do: clear_config([:instance, :limit_to_local_content])
1705 test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
1706 remote_user: remote_user
1708 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1709 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1711 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1712 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1714 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1715 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1718 test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
1719 %{remote_user: remote_user} do
1720 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1721 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1724 test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
1725 %{remote_user: remote_user, local_user: local_user} do
1726 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1727 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
1730 test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
1731 %{remote_user: remote_user} do
1732 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1733 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1736 test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
1737 %{local_user: local_user} do
1738 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1739 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1741 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1742 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1744 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1745 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1749 describe "update_email_notifications/2" do
1751 user = insert(:user, email_notifications: %{"digest" => true})
1756 test "Notifications are updated", %{user: user} do
1757 true = user.email_notifications["digest"]
1758 assert {:ok, result} = User.update_email_notifications(user, %{"digest" => false})
1759 assert result.email_notifications["digest"] == false