From 0fae04c4e3961baf1f31ae664e5a7fa5de19158e Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 8 Jan 2019 09:55:33 +0100 Subject: Add a setting for users to autofollow on sign up. --- test/user_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 74accb7c8..f8ef2b1dc 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -142,6 +142,23 @@ defmodule Pleroma.UserTest do email: "email@example.com" } + test "it autofollows accounts that are set for it" do + user = insert(:user) + remote_user = insert(:user, %{local: false}) + + Pleroma.Config.put([:instance, :autofollowed_nicknames], [ + user.nickname, + remote_user.nickname + ]) + + cng = User.register_changeset(%User{}, @full_user_data) + + {:ok, registered_user} = User.register(cng) + + assert User.following?(registered_user, user) + refute User.following?(registered_user, remote_user) + end + test "it requires an email, name, nickname and password, bio is optional" do @full_user_data |> Map.keys() -- cgit v1.2.3 From 4124c9aa4aae4622f7a939caa84f01ca0760057c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 05:02:00 +0000 Subject: tests: user: add regression test for remote_or_auth_active?/1 --- test/user_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 74accb7c8..419a576dc 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -767,4 +767,18 @@ defmodule Pleroma.UserTest do |> Map.put(:search_distance, nil) end end + + test "remote_or_auth_active?/1 works correctly" do + Pleroma.Config.put([:instance, :account_activation_required], true) + + local_user = insert(:user, local: true, info: %{confirmation_pending: true}) + confirmed_user = insert(:user, local: true, info: %{confirmation_pending: false}) + remote_user = insert(:user, local: false) + + refute User.remote_or_auth_active?(local_user) + assert User.remote_or_auth_active?(confirmed_user) + assert User.remote_or_auth_active?(remote_user) + + Pleroma.Config.put([:instance, :account_activation_required], false) + end end -- cgit v1.2.3 From 74f48beec3bf78cd94cb6db5cbdb937505891eab Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:36:50 +0000 Subject: user: remove entirely redundant remote_or_auth_active?/1. auth_active?/1 can check remote users and return true directly. --- test/user_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 419a576dc..1c4e84914 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -768,16 +768,16 @@ defmodule Pleroma.UserTest do end end - test "remote_or_auth_active?/1 works correctly" do + test "auth_active?/1 works correctly" do Pleroma.Config.put([:instance, :account_activation_required], true) local_user = insert(:user, local: true, info: %{confirmation_pending: true}) confirmed_user = insert(:user, local: true, info: %{confirmation_pending: false}) remote_user = insert(:user, local: false) - refute User.remote_or_auth_active?(local_user) - assert User.remote_or_auth_active?(confirmed_user) - assert User.remote_or_auth_active?(remote_user) + refute User.auth_active?(local_user) + assert User.auth_active?(confirmed_user) + assert User.auth_active?(remote_user) Pleroma.Config.put([:instance, :account_activation_required], false) end -- cgit v1.2.3 From f2a4f89abef810f1106afa3a9ef82fa748bc783e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:50:31 +0000 Subject: tests: user: add tests for superuser?/1 --- test/user_test.exs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 1c4e84914..582374fb9 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -781,4 +781,32 @@ defmodule Pleroma.UserTest do Pleroma.Config.put([:instance, :account_activation_required], false) end + + describe "superuser?/1" do + test "returns false for unprivileged users" do + user = insert(:user, local: true) + + refute User.superuser?(user) + end + + test "returns false for remote users" do + user = insert(:user, local: false) + remote_admin_user = insert(:user, local: false, info: %{is_admin: true}) + + refute User.superuser?(user) + refute User.superuser?(remote_admin_user) + end + + test "returns true for local moderators" do + user = insert(:user, local: true, info: %{is_moderator: true}) + + assert User.superuser?(user) + end + + test "returns true for local admins" do + user = insert(:user, local: true, info: %{is_admin: true}) + + assert User.superuser?(user) + end + end end -- cgit v1.2.3 From 567651fb3fcacbe5bb2f9c19deb9655edaaad076 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 07:03:32 +0000 Subject: test: user: add tests for visible_for?/2 --- test/user_test.exs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 582374fb9..542eaaaeb 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -809,4 +809,41 @@ defmodule Pleroma.UserTest do assert User.superuser?(user) end end + + describe "visible_for?/2" do + test "returns true when the account is itself" do + user = insert(:user, local: true) + + assert User.visible_for?(user, user) + end + + test "returns false when the account is unauthenticated and auth is required" do + Pleroma.Config.put([:instance, :account_activation_required], true) + + user = insert(:user, local: true, info: %{confirmation_pending: true}) + other_user = insert(:user, local: true) + + refute User.visible_for?(user, other_user) + + Pleroma.Config.put([:instance, :account_activation_required], false) + end + + test "returns true when the account is unauthenticated and auth is not required" do + user = insert(:user, local: true, info: %{confirmation_pending: true}) + other_user = insert(:user, local: true) + + assert User.visible_for?(user, other_user) + end + + test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do + Pleroma.Config.put([:instance, :account_activation_required], true) + + user = insert(:user, local: true, info: %{confirmation_pending: true}) + other_user = insert(:user, local: true, info: %{is_admin: true}) + + assert User.visible_for?(user, other_user) + + Pleroma.Config.put([:instance, :account_activation_required], false) + end + end end -- cgit v1.2.3