aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/config/config_db_test.exs9
-rw-r--r--test/config/transfer_task_test.exs13
-rw-r--r--test/tasks/config_test.exs48
-rw-r--r--test/user_test.exs36
-rw-r--r--test/web/activity_pub/utils_test.exs13
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs5
-rw-r--r--test/web/oauth/oauth_controller_test.exs51
-rw-r--r--test/web/pleroma_api/controllers/pleroma_api_controller_test.exs2
8 files changed, 126 insertions, 51 deletions
diff --git a/test/config/config_db_test.exs b/test/config/config_db_test.exs
index 61a0b1d5d..812709fd8 100644
--- a/test/config/config_db_test.exs
+++ b/test/config/config_db_test.exs
@@ -307,6 +307,15 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.from_binary(binary) == Quack.Logger
end
+ test "Swoosh.Adapters modules" do
+ binary = ConfigDB.transform("Swoosh.Adapters.SMTP")
+ assert binary == :erlang.term_to_binary(Swoosh.Adapters.SMTP)
+ assert ConfigDB.from_binary(binary) == Swoosh.Adapters.SMTP
+ binary = ConfigDB.transform("Swoosh.Adapters.AmazonSES")
+ assert binary == :erlang.term_to_binary(Swoosh.Adapters.AmazonSES)
+ assert ConfigDB.from_binary(binary) == Swoosh.Adapters.AmazonSES
+ end
+
test "sigil" do
binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs
index b9072e0fc..53e8703fd 100644
--- a/test/config/transfer_task_test.exs
+++ b/test/config/transfer_task_test.exs
@@ -105,17 +105,4 @@ defmodule Pleroma.Config.TransferTaskTest do
Application.put_env(:pleroma, :assets, assets)
end)
end
-
- test "non existing atom" do
- ConfigDB.create(%{
- group: ":pleroma",
- key: ":undefined_atom_key",
- value: [live: 2, com: 3]
- })
-
- assert ExUnit.CaptureLog.capture_log(fn ->
- TransferTask.start_link([])
- end) =~
- "updating env causes error, group: \":pleroma\" key: \":undefined_atom_key\" value: [live: 2, com: 3] error: %ArgumentError{message: \"argument error\"}"
- end
end
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index 2e56e6cfe..d79d34276 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -25,30 +25,50 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "error if file with custom settings doesn't exist" do
- Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
+ Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs")
assert_receive {:mix_shell, :info,
[
- "To migrate settings, you must define custom settings in config/test.secret.exs."
+ "To migrate settings, you must define custom settings in config/not_existance_config_file.exs."
]},
15
end
- test "settings are migrated to db" do
- initial = Application.get_env(:quack, :level)
- on_exit(fn -> Application.put_env(:quack, :level, initial) end)
- assert Repo.all(ConfigDB) == []
+ describe "migrate_to_db/1" do
+ setup do
+ initial = Application.get_env(:quack, :level)
+ on_exit(fn -> Application.put_env(:quack, :level, initial) end)
+ end
+
+ test "settings are migrated to db" do
+ assert Repo.all(ConfigDB) == []
+
+ Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+
+ config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
+ config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
+ config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
+ refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
+
+ assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
+ assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
+ assert ConfigDB.from_binary(config3.value) == :info
+ end
- Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+ test "config table is truncated before migration" do
+ ConfigDB.create(%{
+ group: ":pleroma",
+ key: ":first_setting",
+ value: [key: "value", key2: ["Activity"]]
+ })
+
+ assert Repo.aggregate(ConfigDB, :count, :id) == 1
- config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
- config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
- config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
- refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
+ Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
- assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
- assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
- assert ConfigDB.from_binary(config3.value) == :info
+ config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
+ assert ConfigDB.from_binary(config.value) == [key: "value", key2: [Repo]]
+ end
end
describe "with deletion temp file" do
diff --git a/test/user_test.exs b/test/user_test.exs
index 9da1e02a9..158f98e66 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1286,23 +1286,35 @@ defmodule Pleroma.UserTest do
end
end
- test "auth_active?/1 works correctly" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ describe "account_status/1" do
+ clear_config([:instance, :account_activation_required])
- local_user = insert(:user, local: true, confirmation_pending: true)
- confirmed_user = insert(:user, local: true, confirmation_pending: false)
- remote_user = insert(:user, local: false)
+ test "return confirmation_pending for unconfirm user" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ user = insert(:user, confirmation_pending: true)
+ assert User.account_status(user) == :confirmation_pending
+ end
- refute User.auth_active?(local_user)
- assert User.auth_active?(confirmed_user)
- assert User.auth_active?(remote_user)
+ test "return active for confirmed user" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ user = insert(:user, confirmation_pending: false)
+ assert User.account_status(user) == :active
+ end
- # also shows unactive for deactivated users
+ test "return active for remote user" do
+ user = insert(:user, local: false)
+ assert User.account_status(user) == :active
+ end
- deactivated_but_confirmed =
- insert(:user, local: true, confirmation_pending: false, deactivated: true)
+ test "returns :password_reset_pending for user with reset password" do
+ user = insert(:user, password_reset_pending: true)
+ assert User.account_status(user) == :password_reset_pending
+ end
- refute User.auth_active?(deactivated_but_confirmed)
+ test "returns :deactivated for deactivated user" do
+ user = insert(:user, local: true, confirmation_pending: false, deactivated: true)
+ assert User.account_status(user) == :deactivated
+ end
end
describe "superuser?/1" do
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index 586eb1d2f..211fa6c95 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -636,4 +636,17 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert updated_object.data["announcement_count"] == 1
end
end
+
+ describe "get_cached_emoji_reactions/1" do
+ test "returns the data or an emtpy list" do
+ object = insert(:note)
+ assert Utils.get_cached_emoji_reactions(object) == []
+
+ object = insert(:note, data: %{"reactions" => [["x", ["lain"]]]})
+ assert Utils.get_cached_emoji_reactions(object) == [["x", ["lain"]]]
+
+ object = insert(:note, data: %{"reactions" => %{}})
+ assert Utils.get_cached_emoji_reactions(object) == []
+ end
+ end
end
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 069bb8eac..25777b011 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -36,7 +36,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)
- assert status[:pleroma][:emoji_reactions] == [["☕", 2], ["🍵", 1]]
+ assert status[:pleroma][:emoji_reactions] == [
+ %{emoji: "☕", count: 2},
+ %{emoji: "🍵", count: 1}
+ ]
end
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 59f4674eb..adeff8e25 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -819,7 +819,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|> User.confirmation_changeset(need_confirmation: true)
|> User.update_and_set_cache()
- refute Pleroma.User.auth_active?(user)
+ refute Pleroma.User.account_status(user) == :active
app = insert(:oauth_app)
@@ -849,7 +849,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
app = insert(:oauth_app)
- conn =
+ resp =
build_conn()
|> post("/oauth/token", %{
"grant_type" => "password",
@@ -858,10 +858,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"client_id" => app.client_id,
"client_secret" => app.client_secret
})
+ |> json_response(403)
- assert resp = json_response(conn, 403)
- assert %{"error" => _} = resp
- refute Map.has_key?(resp, "access_token")
+ assert resp == %{
+ "error" => "Your account is currently disabled",
+ "identifier" => "account_is_disabled"
+ }
end
test "rejects token exchange for user with password_reset_pending set to true" do
@@ -875,7 +877,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
app = insert(:oauth_app, scopes: ["read", "write"])
- conn =
+ resp =
build_conn()
|> post("/oauth/token", %{
"grant_type" => "password",
@@ -884,12 +886,41 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"client_id" => app.client_id,
"client_secret" => app.client_secret
})
+ |> json_response(403)
- assert resp = json_response(conn, 403)
+ assert resp == %{
+ "error" => "Password reset is required",
+ "identifier" => "password_reset_required"
+ }
+ end
- assert resp["error"] == "Password reset is required"
- assert resp["identifier"] == "password_reset_required"
- refute Map.has_key?(resp, "access_token")
+ test "rejects token exchange for user with confirmation_pending set to true" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ password = "testpassword"
+
+ user =
+ insert(:user,
+ password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
+ confirmation_pending: true
+ )
+
+ app = insert(:oauth_app, scopes: ["read", "write"])
+
+ resp =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "password",
+ "username" => user.nickname,
+ "password" => password,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+ |> json_response(403)
+
+ assert resp == %{
+ "error" => "Your login is missing a confirmed e-mail address",
+ "identifier" => "missing_confirmed_email"
+ }
end
test "rejects an invalid authorization code" do
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index a79ecd05b..3978c2ec5 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
|> json_response(200)
- [["🎅", [represented_user]]] = result
+ [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result
assert represented_user["id"] == other_user.id
end