2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:11:29 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-15 17:14:23 -07:00
|
|
|
defmodule Mix.Tasks.Pleroma.UserTest do
|
2020-05-11 07:06:23 -06:00
|
|
|
alias Pleroma.Activity
|
2020-06-11 14:54:39 -06:00
|
|
|
alias Pleroma.MFA
|
2020-05-11 07:06:23 -06:00
|
|
|
alias Pleroma.Object
|
2019-05-16 14:04:08 -06:00
|
|
|
alias Pleroma.Repo
|
2020-05-01 06:05:25 -06:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2018-12-15 17:14:23 -07:00
|
|
|
alias Pleroma.User
|
2020-05-11 07:06:23 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-07-21 20:43:15 -06:00
|
|
|
alias Pleroma.Web.OAuth.Authorization
|
|
|
|
alias Pleroma.Web.OAuth.Token
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.DataCase, async: false
|
2020-05-01 06:05:25 -06:00
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
2023-08-04 05:50:50 -06:00
|
|
|
@moduletag :mocked
|
2018-12-15 17:14:23 -07:00
|
|
|
|
|
|
|
import ExUnit.CaptureIO
|
2020-05-01 06:05:25 -06:00
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
2018-12-15 17:14:23 -07:00
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Mix.shell(Mix.Shell.Process)
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Mix.shell(Mix.Shell.IO)
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "running new" do
|
|
|
|
test "user is created" do
|
|
|
|
# just get random data
|
|
|
|
unsaved = build(:user)
|
|
|
|
|
|
|
|
# prepare to answer yes
|
2020-12-04 11:07:23 -07:00
|
|
|
send(self(), {:mix_shell_input, :prompt, "Y"})
|
2018-12-15 17:14:23 -07:00
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"new",
|
|
|
|
unsaved.nickname,
|
|
|
|
unsaved.email,
|
|
|
|
"--name",
|
|
|
|
unsaved.name,
|
|
|
|
"--bio",
|
|
|
|
unsaved.bio,
|
|
|
|
"--password",
|
|
|
|
"test",
|
|
|
|
"--moderator",
|
|
|
|
"--admin"
|
|
|
|
])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "user will be created"
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :prompt, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "Continue"
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "created"
|
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
user = User.get_cached_by_nickname(unsaved.nickname)
|
2018-12-15 17:14:23 -07:00
|
|
|
assert user.name == unsaved.name
|
|
|
|
assert user.email == unsaved.email
|
|
|
|
assert user.bio == unsaved.bio
|
2019-10-16 12:59:21 -06:00
|
|
|
assert user.is_moderator
|
|
|
|
assert user.is_admin
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "user is not created" do
|
|
|
|
unsaved = build(:user)
|
|
|
|
|
|
|
|
# prepare to answer no
|
2020-12-04 11:07:23 -07:00
|
|
|
send(self(), {:mix_shell_input, :prompt, "N"})
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2018-12-15 17:14:23 -07:00
|
|
|
Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "user will be created"
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :prompt, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "Continue"
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "will not be created"
|
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
refute User.get_cached_by_nickname(unsaved.nickname)
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "running rm" do
|
|
|
|
test "user is deleted" do
|
2020-05-21 05:16:21 -06:00
|
|
|
clear_config([:instance, :federating], true)
|
2018-12-15 17:14:23 -07:00
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-01 06:05:25 -06:00
|
|
|
with_mock Pleroma.Web.Federator,
|
|
|
|
publish: fn _ -> nil end do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
|
|
|
|
ObanHelpers.perform_all()
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-05-01 06:05:25 -06:00
|
|
|
assert message =~ " deleted"
|
2020-10-12 16:42:27 -06:00
|
|
|
assert %{is_active: false} = User.get_by_nickname(user.nickname)
|
2018-12-15 17:14:23 -07:00
|
|
|
|
2020-05-01 06:05:25 -06:00
|
|
|
assert called(Pleroma.Web.Federator.publish(:_))
|
|
|
|
end
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
|
2020-05-11 07:06:23 -06:00
|
|
|
test "a remote user's create activity is deleted when the object has been pruned" do
|
|
|
|
user = insert(:user)
|
2020-07-07 00:10:02 -06:00
|
|
|
user2 = insert(:user)
|
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
|
2020-07-07 00:10:02 -06:00
|
|
|
{:ok, post2} = CommonAPI.post(user2, %{status: "test"})
|
2021-01-04 05:38:31 -07:00
|
|
|
obj = Object.normalize(post2, fetch: false)
|
2020-07-07 00:10:02 -06:00
|
|
|
|
|
|
|
{:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
|
|
|
|
|
|
|
|
{:ok, like_activity, _meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
|
|
|
like_object,
|
|
|
|
Keyword.put(meta, :local, true)
|
|
|
|
)
|
|
|
|
|
2020-07-08 22:16:52 -06:00
|
|
|
like_activity.data["object"]
|
|
|
|
|> Pleroma.Object.get_by_ap_id()
|
|
|
|
|> Repo.delete()
|
2020-05-21 05:16:21 -06:00
|
|
|
|
|
|
|
clear_config([:instance, :federating], true)
|
|
|
|
|
2021-01-04 05:38:31 -07:00
|
|
|
object = Object.normalize(post, fetch: false)
|
2020-05-11 07:06:23 -06:00
|
|
|
Object.prune(object)
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.Federator,
|
|
|
|
publish: fn _ -> nil end do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-05-11 07:06:23 -06:00
|
|
|
assert message =~ " deleted"
|
2020-10-12 16:42:27 -06:00
|
|
|
assert %{is_active: false} = User.get_by_nickname(user.nickname)
|
2020-05-11 07:06:23 -06:00
|
|
|
|
|
|
|
assert called(Pleroma.Web.Federator.publish(:_))
|
2020-07-07 00:10:02 -06:00
|
|
|
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
|
2020-05-11 07:06:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
refute Activity.get_by_id(post.id)
|
|
|
|
end
|
|
|
|
|
2018-12-15 17:14:23 -07:00
|
|
|
test "no user to delete" do
|
2018-12-16 09:04:31 -07:00
|
|
|
Mix.Tasks.Pleroma.User.run(["rm", "nonexistent"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-20 23:06:57 -06:00
|
|
|
describe "running deactivate" do
|
2021-01-25 09:48:28 -07:00
|
|
|
test "active user is deactivated and unsubscribed" do
|
2018-12-15 17:14:23 -07:00
|
|
|
followed = insert(:user)
|
2020-05-11 21:44:33 -06:00
|
|
|
remote_followed = insert(:user, local: false)
|
2019-10-10 13:35:32 -06:00
|
|
|
user = insert(:user)
|
2020-05-11 21:44:33 -06:00
|
|
|
|
2020-03-28 09:49:03 -06:00
|
|
|
User.follow(user, followed, :follow_accept)
|
2020-05-11 21:44:33 -06:00
|
|
|
User.follow(user, remote_followed, :follow_accept)
|
2018-12-15 17:14:23 -07:00
|
|
|
|
2020-05-20 23:06:57 -06:00
|
|
|
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2018-12-15 17:14:23 -07:00
|
|
|
# Note that the task has delay :timer.sleep(500)
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2021-01-25 09:48:28 -07:00
|
|
|
|
|
|
|
assert message ==
|
|
|
|
"Successfully deactivated #{user.nickname} and unsubscribed all local followers"
|
2018-12-15 17:14:23 -07:00
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
user = User.get_cached_by_nickname(user.nickname)
|
2020-05-11 21:44:33 -06:00
|
|
|
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
|
2020-10-12 16:42:27 -06:00
|
|
|
refute user.is_active
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
|
2021-01-25 09:48:28 -07:00
|
|
|
test "user is deactivated" do
|
|
|
|
%{id: id, nickname: nickname} = insert(:user, is_active: false)
|
|
|
|
|
|
|
|
assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2021-01-25 09:48:28 -07:00
|
|
|
assert message == "User #{nickname} already deactivated"
|
|
|
|
|
|
|
|
user = Repo.get(User, id)
|
|
|
|
refute user.is_active
|
|
|
|
end
|
|
|
|
|
2020-05-20 23:06:57 -06:00
|
|
|
test "no user to deactivate" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "No user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "running set" do
|
|
|
|
test "All statuses set" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-09-08 16:59:25 -06:00
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"set",
|
|
|
|
user.nickname,
|
|
|
|
"--admin",
|
|
|
|
"--confirmed",
|
|
|
|
"--locked",
|
|
|
|
"--moderator"
|
|
|
|
])
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-09-08 16:59:25 -06:00
|
|
|
assert message =~ ~r/Admin status .* true/
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-10-13 13:29:34 -06:00
|
|
|
assert message =~ ~r/Confirmation status.* true/
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-16 09:04:31 -07:00
|
|
|
assert message =~ ~r/Locked status .* true/
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-09-08 16:59:25 -06:00
|
|
|
assert message =~ ~r/Moderator status .* true/
|
2018-12-15 17:14:23 -07:00
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
user = User.get_cached_by_nickname(user.nickname)
|
2019-10-16 12:59:21 -06:00
|
|
|
assert user.is_moderator
|
2020-10-13 08:31:13 -06:00
|
|
|
assert user.is_locked
|
2019-10-16 12:59:21 -06:00
|
|
|
assert user.is_admin
|
2020-10-13 13:29:34 -06:00
|
|
|
assert user.is_confirmed
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "All statuses unset" do
|
2020-09-08 16:59:25 -06:00
|
|
|
user =
|
2020-10-13 11:49:43 -06:00
|
|
|
insert(:user,
|
|
|
|
is_locked: true,
|
|
|
|
is_moderator: true,
|
|
|
|
is_admin: true,
|
2020-10-13 13:29:34 -06:00
|
|
|
is_confirmed: false
|
2020-10-13 11:49:43 -06:00
|
|
|
)
|
2018-12-15 17:14:23 -07:00
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"set",
|
|
|
|
user.nickname,
|
|
|
|
"--no-admin",
|
2020-09-08 16:59:25 -06:00
|
|
|
"--no-confirmed",
|
|
|
|
"--no-locked",
|
|
|
|
"--no-moderator"
|
2018-12-15 17:14:23 -07:00
|
|
|
])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-09-08 16:59:25 -06:00
|
|
|
assert message =~ ~r/Admin status .* false/
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-10-13 13:29:34 -06:00
|
|
|
assert message =~ ~r/Confirmation status.* false/
|
2018-12-16 09:04:31 -07:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-16 09:04:31 -07:00
|
|
|
assert message =~ ~r/Locked status .* false/
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-09-08 16:59:25 -06:00
|
|
|
assert message =~ ~r/Moderator status .* false/
|
2018-12-15 17:14:23 -07:00
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
user = User.get_cached_by_nickname(user.nickname)
|
2019-10-16 12:59:21 -06:00
|
|
|
refute user.is_moderator
|
2020-10-13 08:31:13 -06:00
|
|
|
refute user.is_locked
|
2019-10-16 12:59:21 -06:00
|
|
|
refute user.is_admin
|
2020-10-13 13:29:34 -06:00
|
|
|
refute user.is_confirmed
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "no user to set status" do
|
2018-12-16 09:04:31 -07:00
|
|
|
Mix.Tasks.Pleroma.User.run(["set", "nonexistent", "--moderator"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "running reset_password" do
|
|
|
|
test "password reset token is generated" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname])
|
|
|
|
end) =~ "URL:"
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "Generated"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "no user to reset password" do
|
2018-12-16 09:04:31 -07:00
|
|
|
Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2018-12-15 17:14:23 -07:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-11 14:54:39 -06:00
|
|
|
describe "running reset_mfa" do
|
|
|
|
test "disables MFA" do
|
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
multi_factor_authentication_settings: %MFA.Settings{
|
|
|
|
enabled: true,
|
|
|
|
totp: %MFA.Settings.TOTP{secret: "xx", confirmed: true}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.User.run(["reset_mfa", user.nickname])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-06-11 14:54:39 -06:00
|
|
|
assert message == "Multi-Factor Authentication disabled for #{user.nickname}"
|
|
|
|
|
|
|
|
assert %{enabled: false, totp: false} ==
|
|
|
|
user.nickname
|
|
|
|
|> User.get_cached_by_nickname()
|
|
|
|
|> MFA.mfa_settings()
|
|
|
|
end
|
|
|
|
|
|
|
|
test "no user to reset MFA" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2020-06-11 14:54:39 -06:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-15 17:14:23 -07:00
|
|
|
describe "running invite" do
|
|
|
|
test "invite token is generated" do
|
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run(["invite"])
|
|
|
|
end) =~ "http"
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Generated user invite token one time"
|
|
|
|
end
|
|
|
|
|
2019-04-08 03:01:28 -06:00
|
|
|
test "token is generated with expires_at" do
|
2019-04-06 03:58:22 -06:00
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"invite",
|
2019-04-08 03:01:28 -06:00
|
|
|
"--expires-at",
|
2019-04-06 03:58:22 -06:00
|
|
|
Date.to_string(Date.utc_today())
|
|
|
|
])
|
|
|
|
end)
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Generated user invite token date limited"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "token is generated with max use" do
|
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"invite",
|
|
|
|
"--max-use",
|
|
|
|
"5"
|
|
|
|
])
|
|
|
|
end)
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Generated user invite token reusable"
|
|
|
|
end
|
|
|
|
|
2019-04-08 03:01:28 -06:00
|
|
|
test "token is generated with max use and expires date" do
|
2019-04-06 03:58:22 -06:00
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"invite",
|
|
|
|
"--max-use",
|
|
|
|
"5",
|
2019-04-08 03:01:28 -06:00
|
|
|
"--expires-at",
|
2019-04-06 03:58:22 -06:00
|
|
|
Date.to_string(Date.utc_today())
|
|
|
|
])
|
|
|
|
end)
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Generated user invite token reusable date limited"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-06 09:38:35 -06:00
|
|
|
describe "running invites" do
|
2019-04-06 03:58:22 -06:00
|
|
|
test "invites are listed" do
|
2019-04-06 07:24:22 -06:00
|
|
|
{:ok, invite} = Pleroma.UserInviteToken.create_invite()
|
2019-04-06 03:58:22 -06:00
|
|
|
|
|
|
|
{:ok, invite2} =
|
2019-04-08 03:01:28 -06:00
|
|
|
Pleroma.UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 15})
|
2019-04-06 03:58:22 -06:00
|
|
|
|
2019-04-06 09:38:35 -06:00
|
|
|
# assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
|
|
|
"invites"
|
|
|
|
])
|
|
|
|
|
|
|
|
# end)
|
2019-04-06 03:58:22 -06:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
|
|
|
assert_receive {:mix_shell, :info, [message2]}
|
|
|
|
assert_receive {:mix_shell, :info, [message3]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Invites list:"
|
2019-04-06 07:49:43 -06:00
|
|
|
assert message2 =~ invite.invite_type
|
|
|
|
assert message3 =~ invite2.invite_type
|
2019-04-06 03:58:22 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-06 09:38:35 -06:00
|
|
|
describe "running revoke_invite" do
|
2019-04-06 03:58:22 -06:00
|
|
|
test "invite is revoked" do
|
2019-04-08 03:01:28 -06:00
|
|
|
{:ok, invite} = Pleroma.UserInviteToken.create_invite(%{expires_at: Date.utc_today()})
|
2019-04-06 03:58:22 -06:00
|
|
|
|
|
|
|
assert capture_io(fn ->
|
|
|
|
Mix.Tasks.Pleroma.User.run([
|
2019-04-06 09:38:35 -06:00
|
|
|
"revoke_invite",
|
2019-04-06 03:58:22 -06:00
|
|
|
invite.token
|
|
|
|
])
|
|
|
|
end)
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-06 03:58:22 -06:00
|
|
|
assert message =~ "Invite for token #{invite.token} was revoked."
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|
|
|
|
end
|
2019-04-02 03:30:11 -06:00
|
|
|
|
|
|
|
describe "running delete_activities" do
|
|
|
|
test "activities are deleted" do
|
|
|
|
%{nickname: nickname} = insert(:user)
|
|
|
|
|
|
|
|
assert :ok == Mix.Tasks.Pleroma.User.run(["delete_activities", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-04-02 03:30:11 -06:00
|
|
|
assert message == "User #{nickname} statuses deleted."
|
|
|
|
end
|
2019-07-21 20:43:15 -06:00
|
|
|
|
|
|
|
test "it prints an error message when user is not exist" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["delete_activities", "foo"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2019-07-21 20:43:15 -06:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
2019-04-02 03:30:11 -06:00
|
|
|
end
|
2019-05-16 07:23:41 -06:00
|
|
|
|
2020-10-13 20:52:06 -06:00
|
|
|
describe "running confirm" do
|
2019-05-16 07:23:41 -06:00
|
|
|
test "user is confirmed" do
|
2020-10-13 13:29:34 -06:00
|
|
|
%{id: id, nickname: nickname} = insert(:user, is_confirmed: true)
|
2019-05-16 07:23:41 -06:00
|
|
|
|
2020-10-13 20:52:06 -06:00
|
|
|
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2020-10-13 20:52:06 -06:00
|
|
|
assert message == "#{nickname} doesn't need confirmation."
|
2019-05-16 07:23:41 -06:00
|
|
|
|
|
|
|
user = Repo.get(User, id)
|
2020-10-13 13:29:34 -06:00
|
|
|
assert user.is_confirmed
|
2020-10-13 20:52:06 -06:00
|
|
|
refute user.confirmation_token
|
2019-05-16 07:23:41 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "user is not confirmed" do
|
|
|
|
%{id: id, nickname: nickname} =
|
2020-10-13 13:29:34 -06:00
|
|
|
insert(:user, is_confirmed: false, confirmation_token: "some token")
|
2019-05-16 07:23:41 -06:00
|
|
|
|
2020-10-13 20:52:06 -06:00
|
|
|
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-05-16 07:23:41 -06:00
|
|
|
assert message == "#{nickname} doesn't need confirmation."
|
|
|
|
|
|
|
|
user = Repo.get(User, id)
|
2020-10-13 13:29:34 -06:00
|
|
|
assert user.is_confirmed
|
2019-10-16 12:59:21 -06:00
|
|
|
refute user.confirmation_token
|
2019-05-16 07:23:41 -06:00
|
|
|
end
|
2019-07-21 20:43:15 -06:00
|
|
|
|
|
|
|
test "it prints an error message when user is not exist" do
|
2020-10-13 20:52:06 -06:00
|
|
|
Mix.Tasks.Pleroma.User.run(["confirm", "foo"])
|
2019-07-21 20:43:15 -06:00
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2019-07-21 20:43:15 -06:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
2019-05-16 07:23:41 -06:00
|
|
|
end
|
2019-06-06 08:18:27 -06:00
|
|
|
|
2021-01-25 09:36:51 -07:00
|
|
|
describe "running activate" do
|
|
|
|
test "user is activated" do
|
|
|
|
%{id: id, nickname: nickname} = insert(:user, is_active: true)
|
|
|
|
|
|
|
|
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2021-01-25 09:36:51 -07:00
|
|
|
assert message == "User #{nickname} already activated"
|
|
|
|
|
|
|
|
user = Repo.get(User, id)
|
|
|
|
assert user.is_active
|
|
|
|
end
|
|
|
|
|
|
|
|
test "user is not activated" do
|
|
|
|
%{id: id, nickname: nickname} = insert(:user, is_active: false)
|
|
|
|
|
|
|
|
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2021-01-25 09:36:51 -07:00
|
|
|
assert message == "Successfully activated #{nickname}"
|
|
|
|
|
|
|
|
user = Repo.get(User, id)
|
|
|
|
assert user.is_active
|
|
|
|
end
|
|
|
|
|
2021-01-25 09:48:28 -07:00
|
|
|
test "no user to activate" do
|
2021-01-25 09:36:51 -07:00
|
|
|
Mix.Tasks.Pleroma.User.run(["activate", "foo"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2021-01-25 09:36:51 -07:00
|
|
|
assert message =~ "No user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-06 08:18:27 -06:00
|
|
|
describe "search" do
|
|
|
|
test "it returns users matching" do
|
|
|
|
user = insert(:user)
|
|
|
|
moon = insert(:user, nickname: "moon", name: "fediverse expert moon")
|
|
|
|
moot = insert(:user, nickname: "moot")
|
|
|
|
kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
|
|
|
|
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, user, moon} = User.follow(user, moon)
|
2019-06-06 08:18:27 -06:00
|
|
|
|
|
|
|
assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
|
2020-07-08 04:14:18 -06:00
|
|
|
|
2019-06-06 08:18:27 -06:00
|
|
|
res = User.search("moo") |> Enum.map(& &1.id)
|
2020-07-08 04:14:18 -06:00
|
|
|
assert Enum.sort([moon.id, moot.id, kawen.id]) == Enum.sort(res)
|
|
|
|
|
|
|
|
assert [kawen.id, moon.id] == User.Search.search("expert fediverse") |> Enum.map(& &1.id)
|
2019-06-06 08:18:27 -06:00
|
|
|
|
2020-07-08 04:14:18 -06:00
|
|
|
assert [moon.id, kawen.id] ==
|
|
|
|
User.Search.search("expert fediverse", for_user: user) |> Enum.map(& &1.id)
|
2019-06-06 08:18:27 -06:00
|
|
|
end
|
|
|
|
end
|
2019-07-21 20:43:15 -06:00
|
|
|
|
|
|
|
describe "signing out" do
|
|
|
|
test "it deletes all user's tokens and authorizations" do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:oauth_token, user: user)
|
|
|
|
insert(:oauth_authorization, user: user)
|
|
|
|
|
|
|
|
assert Repo.get_by(Token, user_id: user.id)
|
|
|
|
assert Repo.get_by(Authorization, user_id: user.id)
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.User.run(["sign_out", user.nickname])
|
|
|
|
|
|
|
|
refute Repo.get_by(Token, user_id: user.id)
|
|
|
|
refute Repo.get_by(Authorization, user_id: user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it prints an error message when user is not exist" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["sign_out", "foo"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2019-07-21 20:43:15 -06:00
|
|
|
assert message =~ "No local user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "tagging" do
|
|
|
|
test "it add tags to a user" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.User.run(["tag", user.nickname, "pleroma"])
|
|
|
|
|
|
|
|
user = User.get_cached_by_nickname(user.nickname)
|
|
|
|
assert "pleroma" in user.tags
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it prints an error message when user is not exist" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["tag", "foo"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2019-07-21 20:43:15 -06:00
|
|
|
assert message =~ "Could not change user tags"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "untagging" do
|
|
|
|
test "it deletes tags from a user" do
|
|
|
|
user = insert(:user, tags: ["pleroma"])
|
|
|
|
assert "pleroma" in user.tags
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.User.run(["untag", user.nickname, "pleroma"])
|
|
|
|
|
|
|
|
user = User.get_cached_by_nickname(user.nickname)
|
|
|
|
assert Enum.empty?(user.tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it prints an error message when user is not exist" do
|
|
|
|
Mix.Tasks.Pleroma.User.run(["untag", "foo"])
|
|
|
|
|
2023-08-01 04:43:50 -06:00
|
|
|
assert_receive {:mix_shell, :error, [message]}
|
2019-07-21 20:43:15 -06:00
|
|
|
assert message =~ "Could not change user tags"
|
|
|
|
end
|
|
|
|
end
|
2020-09-09 08:02:07 -06:00
|
|
|
|
|
|
|
describe "bulk confirm and unconfirm" do
|
|
|
|
test "confirm all" do
|
2020-10-13 13:29:34 -06:00
|
|
|
user1 = insert(:user, is_confirmed: false)
|
|
|
|
user2 = insert(:user, is_confirmed: false)
|
2020-09-09 08:02:07 -06:00
|
|
|
|
2020-10-13 13:29:34 -06:00
|
|
|
refute user1.is_confirmed
|
|
|
|
refute user2.is_confirmed
|
2020-09-09 08:02:07 -06:00
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.User.run(["confirm_all"])
|
|
|
|
|
|
|
|
user1 = User.get_cached_by_nickname(user1.nickname)
|
|
|
|
user2 = User.get_cached_by_nickname(user2.nickname)
|
|
|
|
|
2020-10-13 13:29:34 -06:00
|
|
|
assert user1.is_confirmed
|
|
|
|
assert user2.is_confirmed
|
2020-09-09 08:02:07 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "unconfirm all" do
|
2020-10-13 13:29:34 -06:00
|
|
|
user1 = insert(:user, is_confirmed: true)
|
|
|
|
user2 = insert(:user, is_confirmed: true)
|
|
|
|
admin = insert(:user, is_admin: true, is_confirmed: true)
|
|
|
|
mod = insert(:user, is_moderator: true, is_confirmed: true)
|
2020-09-09 08:02:07 -06:00
|
|
|
|
2020-10-13 13:29:34 -06:00
|
|
|
assert user1.is_confirmed
|
|
|
|
assert user2.is_confirmed
|
2020-09-09 08:02:07 -06:00
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.User.run(["unconfirm_all"])
|
|
|
|
|
|
|
|
user1 = User.get_cached_by_nickname(user1.nickname)
|
|
|
|
user2 = User.get_cached_by_nickname(user2.nickname)
|
|
|
|
admin = User.get_cached_by_nickname(admin.nickname)
|
|
|
|
mod = User.get_cached_by_nickname(mod.nickname)
|
|
|
|
|
2020-10-13 13:29:34 -06:00
|
|
|
refute user1.is_confirmed
|
|
|
|
refute user2.is_confirmed
|
|
|
|
assert admin.is_confirmed
|
|
|
|
assert mod.is_confirmed
|
2020-09-09 08:02:07 -06:00
|
|
|
end
|
|
|
|
end
|
2018-12-15 17:14:23 -07:00
|
|
|
end
|