Merge branch 'develop' into issue/1383
This commit is contained in:
commit
bfc70fdf29
23 changed files with 401 additions and 245 deletions
|
|
@ -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/)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||
test "settings are migrated to db" do
|
||||
assert Repo.all(ConfigDB) == []
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue