tests consistency
This commit is contained in:
parent
6bf85440b3
commit
7dffaef479
258 changed files with 38 additions and 37 deletions
|
|
@ -1,546 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ConfigDBTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
test "get_by_params/1" do
|
||||
config = insert(:config)
|
||||
insert(:config)
|
||||
|
||||
assert config == ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
end
|
||||
|
||||
test "get_all_as_keyword/0" do
|
||||
saved = insert(:config)
|
||||
insert(:config, group: ":quack", key: ":level", value: :info)
|
||||
insert(:config, group: ":quack", key: ":meta", value: [:none])
|
||||
|
||||
insert(:config,
|
||||
group: ":quack",
|
||||
key: ":webhook_url",
|
||||
value: "https://hooks.slack.com/services/KEY/some_val"
|
||||
)
|
||||
|
||||
config = ConfigDB.get_all_as_keyword()
|
||||
|
||||
assert config[:pleroma] == [
|
||||
{saved.key, saved.value}
|
||||
]
|
||||
|
||||
assert config[:quack][:level] == :info
|
||||
assert config[:quack][:meta] == [:none]
|
||||
assert config[:quack][:webhook_url] == "https://hooks.slack.com/services/KEY/some_val"
|
||||
end
|
||||
|
||||
describe "update_or_create/1" do
|
||||
test "common" do
|
||||
config = insert(:config)
|
||||
key2 = :another_key
|
||||
|
||||
params = [
|
||||
%{group: :pleroma, key: key2, value: "another_value"},
|
||||
%{group: :pleroma, key: config.key, value: [a: 1, b: 2, c: "new_value"]}
|
||||
]
|
||||
|
||||
assert Repo.all(ConfigDB) |> length() == 1
|
||||
|
||||
Enum.each(params, &ConfigDB.update_or_create(&1))
|
||||
|
||||
assert Repo.all(ConfigDB) |> length() == 2
|
||||
|
||||
config1 = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
config2 = ConfigDB.get_by_params(%{group: :pleroma, key: key2})
|
||||
|
||||
assert config1.value == [a: 1, b: 2, c: "new_value"]
|
||||
assert config2.value == "another_value"
|
||||
end
|
||||
|
||||
test "partial update" do
|
||||
config = insert(:config, value: [key1: "val1", key2: :val2])
|
||||
|
||||
{:ok, config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
value: [key1: :val1, key3: :val3]
|
||||
})
|
||||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert config.value == updated.value
|
||||
assert updated.value[:key1] == :val1
|
||||
assert updated.value[:key2] == :val2
|
||||
assert updated.value[:key3] == :val3
|
||||
end
|
||||
|
||||
test "deep merge" do
|
||||
config = insert(:config, value: [key1: "val1", key2: [k1: :v1, k2: "v2"]])
|
||||
|
||||
{:ok, config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
value: [key1: :val1, key2: [k2: :v2, k3: :v3], key3: :val3]
|
||||
})
|
||||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert config.value == updated.value
|
||||
assert updated.value[:key1] == :val1
|
||||
assert updated.value[:key2] == [k1: :v1, k2: :v2, k3: :v3]
|
||||
assert updated.value[:key3] == :val3
|
||||
end
|
||||
|
||||
test "only full update for some keys" do
|
||||
config1 = insert(:config, key: :ecto_repos, value: [repo: Pleroma.Repo])
|
||||
|
||||
config2 = insert(:config, group: :cors_plug, key: :max_age, value: 18)
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config1.group,
|
||||
key: config1.key,
|
||||
value: [another_repo: [Pleroma.Repo]]
|
||||
})
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config2.group,
|
||||
key: config2.key,
|
||||
value: 777
|
||||
})
|
||||
|
||||
updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key})
|
||||
updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key})
|
||||
|
||||
assert updated1.value == [another_repo: [Pleroma.Repo]]
|
||||
assert updated2.value == 777
|
||||
end
|
||||
|
||||
test "full update if value is not keyword" do
|
||||
config =
|
||||
insert(:config,
|
||||
group: ":tesla",
|
||||
key: ":adapter",
|
||||
value: Tesla.Adapter.Hackney
|
||||
)
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
value: Tesla.Adapter.Httpc
|
||||
})
|
||||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert updated.value == Tesla.Adapter.Httpc
|
||||
end
|
||||
|
||||
test "only full update for some subkeys" do
|
||||
config1 =
|
||||
insert(:config,
|
||||
key: ":emoji",
|
||||
value: [groups: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
config2 =
|
||||
insert(:config,
|
||||
key: ":assets",
|
||||
value: [mascots: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config1.group,
|
||||
key: config1.key,
|
||||
value: [groups: [c: 3, d: 4], key: [b: 2]]
|
||||
})
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config2.group,
|
||||
key: config2.key,
|
||||
value: [mascots: [c: 3, d: 4], key: [b: 2]]
|
||||
})
|
||||
|
||||
updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key})
|
||||
updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key})
|
||||
|
||||
assert updated1.value == [groups: [c: 3, d: 4], key: [a: 1, b: 2]]
|
||||
assert updated2.value == [mascots: [c: 3, d: 4], key: [a: 1, b: 2]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete/1" do
|
||||
test "error on deleting non existing setting" do
|
||||
{:error, error} = ConfigDB.delete(%{group: ":pleroma", key: ":key"})
|
||||
assert error =~ "Config with params %{group: \":pleroma\", key: \":key\"} not found"
|
||||
end
|
||||
|
||||
test "full delete" do
|
||||
config = insert(:config)
|
||||
{:ok, deleted} = ConfigDB.delete(%{group: config.group, key: config.key})
|
||||
assert Ecto.get_meta(deleted, :state) == :deleted
|
||||
refute ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
end
|
||||
|
||||
test "partial subkeys delete" do
|
||||
config = insert(:config, value: [groups: [a: 1, b: 2], key: [a: 1]])
|
||||
|
||||
{:ok, deleted} =
|
||||
ConfigDB.delete(%{group: config.group, key: config.key, subkeys: [":groups"]})
|
||||
|
||||
assert Ecto.get_meta(deleted, :state) == :loaded
|
||||
|
||||
assert deleted.value == [key: [a: 1]]
|
||||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert updated.value == deleted.value
|
||||
end
|
||||
|
||||
test "full delete if remaining value after subkeys deletion is empty list" do
|
||||
config = insert(:config, value: [groups: [a: 1, b: 2]])
|
||||
|
||||
{:ok, deleted} =
|
||||
ConfigDB.delete(%{group: config.group, key: config.key, subkeys: [":groups"]})
|
||||
|
||||
assert Ecto.get_meta(deleted, :state) == :deleted
|
||||
|
||||
refute ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_elixir_types/1" do
|
||||
test "string" do
|
||||
assert ConfigDB.to_elixir_types("value as string") == "value as string"
|
||||
end
|
||||
|
||||
test "boolean" do
|
||||
assert ConfigDB.to_elixir_types(false) == false
|
||||
end
|
||||
|
||||
test "nil" do
|
||||
assert ConfigDB.to_elixir_types(nil) == nil
|
||||
end
|
||||
|
||||
test "integer" do
|
||||
assert ConfigDB.to_elixir_types(150) == 150
|
||||
end
|
||||
|
||||
test "atom" do
|
||||
assert ConfigDB.to_elixir_types(":atom") == :atom
|
||||
end
|
||||
|
||||
test "ssl options" do
|
||||
assert ConfigDB.to_elixir_types([":tlsv1", ":tlsv1.1", ":tlsv1.2"]) == [
|
||||
:tlsv1,
|
||||
:"tlsv1.1",
|
||||
:"tlsv1.2"
|
||||
]
|
||||
end
|
||||
|
||||
test "pleroma module" do
|
||||
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
|
||||
end
|
||||
|
||||
test "pleroma string" do
|
||||
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
|
||||
end
|
||||
|
||||
test "phoenix module" do
|
||||
assert ConfigDB.to_elixir_types("Phoenix.Socket.V1.JSONSerializer") ==
|
||||
Phoenix.Socket.V1.JSONSerializer
|
||||
end
|
||||
|
||||
test "tesla module" do
|
||||
assert ConfigDB.to_elixir_types("Tesla.Adapter.Hackney") == Tesla.Adapter.Hackney
|
||||
end
|
||||
|
||||
test "ExSyslogger module" do
|
||||
assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger
|
||||
end
|
||||
|
||||
test "Quack.Logger module" do
|
||||
assert ConfigDB.to_elixir_types("Quack.Logger") == Quack.Logger
|
||||
end
|
||||
|
||||
test "Swoosh.Adapters modules" do
|
||||
assert ConfigDB.to_elixir_types("Swoosh.Adapters.SMTP") == Swoosh.Adapters.SMTP
|
||||
assert ConfigDB.to_elixir_types("Swoosh.Adapters.AmazonSES") == Swoosh.Adapters.AmazonSES
|
||||
end
|
||||
|
||||
test "sigil" do
|
||||
assert ConfigDB.to_elixir_types("~r[comp[lL][aA][iI][nN]er]") == ~r/comp[lL][aA][iI][nN]er/
|
||||
end
|
||||
|
||||
test "link sigil" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/") == ~r/https:\/\/example.com/
|
||||
end
|
||||
|
||||
test "link sigil with um modifiers" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/um") ==
|
||||
~r/https:\/\/example.com/um
|
||||
end
|
||||
|
||||
test "link sigil with i modifier" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/i") == ~r/https:\/\/example.com/i
|
||||
end
|
||||
|
||||
test "link sigil with s modifier" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/s") == ~r/https:\/\/example.com/s
|
||||
end
|
||||
|
||||
test "raise if valid delimiter not found" do
|
||||
assert_raise ArgumentError, "valid delimiter for Regex expression not found", fn ->
|
||||
ConfigDB.to_elixir_types("~r/https://[]{}<>\"'()|example.com/s")
|
||||
end
|
||||
end
|
||||
|
||||
test "2 child tuple" do
|
||||
assert ConfigDB.to_elixir_types(%{"tuple" => ["v1", ":v2"]}) == {"v1", :v2}
|
||||
end
|
||||
|
||||
test "proxy tuple with localhost" do
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]
|
||||
}) == {:proxy_url, {:socks5, :localhost, 1234}}
|
||||
end
|
||||
|
||||
test "proxy tuple with domain" do
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]
|
||||
}) == {:proxy_url, {:socks5, 'domain.com', 1234}}
|
||||
end
|
||||
|
||||
test "proxy tuple with ip" do
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]
|
||||
}) == {:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}}
|
||||
end
|
||||
|
||||
test "tuple with n childs" do
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Bookmark",
|
||||
150,
|
||||
false,
|
||||
"Phoenix.Socket.V1.JSONSerializer"
|
||||
]
|
||||
}) == {"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
|
||||
end
|
||||
|
||||
test "map with string key" do
|
||||
assert ConfigDB.to_elixir_types(%{"key" => "value"}) == %{"key" => "value"}
|
||||
end
|
||||
|
||||
test "map with atom key" do
|
||||
assert ConfigDB.to_elixir_types(%{":key" => "value"}) == %{key: "value"}
|
||||
end
|
||||
|
||||
test "list of strings" do
|
||||
assert ConfigDB.to_elixir_types(["v1", "v2", "v3"]) == ["v1", "v2", "v3"]
|
||||
end
|
||||
|
||||
test "list of modules" do
|
||||
assert ConfigDB.to_elixir_types(["Pleroma.Repo", "Pleroma.Activity"]) == [
|
||||
Pleroma.Repo,
|
||||
Pleroma.Activity
|
||||
]
|
||||
end
|
||||
|
||||
test "list of atoms" do
|
||||
assert ConfigDB.to_elixir_types([":v1", ":v2", ":v3"]) == [:v1, :v2, :v3]
|
||||
end
|
||||
|
||||
test "list of mixed values" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Repo",
|
||||
"Phoenix.Socket.V1.JSONSerializer",
|
||||
15,
|
||||
false
|
||||
]) == [
|
||||
"v1",
|
||||
:v2,
|
||||
Pleroma.Repo,
|
||||
Phoenix.Socket.V1.JSONSerializer,
|
||||
15,
|
||||
false
|
||||
]
|
||||
end
|
||||
|
||||
test "simple keyword" do
|
||||
assert ConfigDB.to_elixir_types([%{"tuple" => [":key", "value"]}]) == [key: "value"]
|
||||
end
|
||||
|
||||
test "keyword" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":types", "Pleroma.PostgresTypes"]},
|
||||
%{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]},
|
||||
%{"tuple" => [":migration_lock", nil]},
|
||||
%{"tuple" => [":key1", 150]},
|
||||
%{"tuple" => [":key2", "string"]}
|
||||
]) == [
|
||||
types: Pleroma.PostgresTypes,
|
||||
telemetry_event: [Pleroma.Repo.Instrumenter],
|
||||
migration_lock: nil,
|
||||
key1: 150,
|
||||
key2: "string"
|
||||
]
|
||||
end
|
||||
|
||||
test "trandformed keyword" do
|
||||
assert ConfigDB.to_elixir_types(a: 1, b: 2, c: "string") == [a: 1, b: 2, c: "string"]
|
||||
end
|
||||
|
||||
test "complex keyword with nested mixed childs" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]},
|
||||
%{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]},
|
||||
%{"tuple" => [":link_name", true]},
|
||||
%{"tuple" => [":proxy_remote", false]},
|
||||
%{"tuple" => [":common_map", %{":key" => "value"}]},
|
||||
%{
|
||||
"tuple" => [
|
||||
":proxy_opts",
|
||||
[
|
||||
%{"tuple" => [":redirect_on_failure", false]},
|
||||
%{"tuple" => [":max_body_length", 1_048_576]},
|
||||
%{
|
||||
"tuple" => [
|
||||
":http",
|
||||
[
|
||||
%{"tuple" => [":follow_redirect", true]},
|
||||
%{"tuple" => [":pool", ":upload"]}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]) == [
|
||||
uploader: Pleroma.Uploaders.Local,
|
||||
filters: [Pleroma.Upload.Filter.Dedupe],
|
||||
link_name: true,
|
||||
proxy_remote: false,
|
||||
common_map: %{key: "value"},
|
||||
proxy_opts: [
|
||||
redirect_on_failure: false,
|
||||
max_body_length: 1_048_576,
|
||||
http: [
|
||||
follow_redirect: true,
|
||||
pool: :upload
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
test "common keyword" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":level", ":warn"]},
|
||||
%{"tuple" => [":meta", [":all"]]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":val", nil]},
|
||||
%{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
|
||||
]) == [
|
||||
level: :warn,
|
||||
meta: [:all],
|
||||
path: "",
|
||||
val: nil,
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||
]
|
||||
end
|
||||
|
||||
test "complex keyword with sigil" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":federated_timeline_removal", []]},
|
||||
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
|
||||
%{"tuple" => [":replace", []]}
|
||||
]) == [
|
||||
federated_timeline_removal: [],
|
||||
reject: [~r/comp[lL][aA][iI][nN]er/],
|
||||
replace: []
|
||||
]
|
||||
end
|
||||
|
||||
test "complex keyword with tuples with more than 2 values" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{
|
||||
"tuple" => [
|
||||
":http",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
":key1",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
"/api/v1/streaming",
|
||||
"Pleroma.Web.MastodonAPI.WebsocketHandler",
|
||||
[]
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
"/websocket",
|
||||
"Phoenix.Endpoint.CowboyWebSocket",
|
||||
%{
|
||||
"tuple" => [
|
||||
"Phoenix.Transports.WebSocket",
|
||||
%{
|
||||
"tuple" => [
|
||||
"Pleroma.Web.Endpoint",
|
||||
"Pleroma.Web.UserSocket",
|
||||
[]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
"Phoenix.Endpoint.Cowboy2Handler",
|
||||
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]) == [
|
||||
http: [
|
||||
key1: [
|
||||
{:_,
|
||||
[
|
||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, []}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]}
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Config.DeprecationWarnings
|
||||
|
||||
test "check_old_mrf_config/0" do
|
||||
clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
|
||||
clear_config([:instance, :mrf_transparency], true)
|
||||
clear_config([:instance, :mrf_transparency_exclusions], [])
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
|
||||
|
||||
* `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
|
||||
* `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
|
||||
* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
|
||||
"""
|
||||
end
|
||||
|
||||
test "move_namespace_and_warn/2" do
|
||||
old_group1 = [:group, :key]
|
||||
old_group2 = [:group, :key2]
|
||||
old_group3 = [:group, :key3]
|
||||
|
||||
new_group1 = [:another_group, :key4]
|
||||
new_group2 = [:another_group, :key5]
|
||||
new_group3 = [:another_group, :key6]
|
||||
|
||||
clear_config(old_group1, 1)
|
||||
clear_config(old_group2, 2)
|
||||
clear_config(old_group3, 3)
|
||||
|
||||
clear_config(new_group1)
|
||||
clear_config(new_group2)
|
||||
clear_config(new_group3)
|
||||
|
||||
config_map = [
|
||||
{old_group1, new_group1, "\n error :key"},
|
||||
{old_group2, new_group2, "\n error :key2"},
|
||||
{old_group3, new_group3, "\n error :key3"}
|
||||
]
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.move_namespace_and_warn(
|
||||
config_map,
|
||||
"Warning preface"
|
||||
)
|
||||
end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
|
||||
|
||||
assert Config.get(new_group1) == 1
|
||||
assert Config.get(new_group2) == 2
|
||||
assert Config.get(new_group3) == 3
|
||||
end
|
||||
|
||||
test "check_media_proxy_whitelist_config/0" do
|
||||
clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_media_proxy_whitelist_config()
|
||||
end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
|
||||
end
|
||||
|
||||
test "check_welcome_message_config/0" do
|
||||
clear_config([:instance, :welcome_user_nickname], "LainChan")
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_welcome_message_config()
|
||||
end) =~ "Your config is using the old namespace for Welcome messages configuration."
|
||||
end
|
||||
|
||||
test "check_hellthread_threshold/0" do
|
||||
clear_config([:mrf_hellthread, :threshold], 16)
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_hellthread_threshold()
|
||||
end) =~ "You are using the old configuration mechanism for the hellthread filter."
|
||||
end
|
||||
|
||||
test "check_activity_expiration_config/0" do
|
||||
clear_config([Pleroma.ActivityExpiration, :enabled], true)
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_activity_expiration_config()
|
||||
end) =~ "Your config is using old namespace for activity expiration configuration."
|
||||
end
|
||||
|
||||
describe "check_gun_pool_options/0" do
|
||||
test "await_up_timeout" do
|
||||
config = Config.get(:connections_pool)
|
||||
clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_gun_pool_options()
|
||||
end) =~
|
||||
"Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
|
||||
end
|
||||
|
||||
test "pool timeout" do
|
||||
old_config = [
|
||||
federation: [
|
||||
size: 50,
|
||||
max_waiting: 10,
|
||||
timeout: 10_000
|
||||
],
|
||||
media: [
|
||||
size: 50,
|
||||
max_waiting: 10,
|
||||
timeout: 10_000
|
||||
],
|
||||
upload: [
|
||||
size: 25,
|
||||
max_waiting: 5,
|
||||
timeout: 15_000
|
||||
],
|
||||
default: [
|
||||
size: 10,
|
||||
max_waiting: 2,
|
||||
timeout: 5_000
|
||||
]
|
||||
]
|
||||
|
||||
clear_config(:pools, old_config)
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_gun_pool_options()
|
||||
end) =~
|
||||
"Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config.HolderTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pleroma.Config.Holder
|
||||
|
||||
test "default_config/0" do
|
||||
config = Holder.default_config()
|
||||
assert config[:pleroma][Pleroma.Uploaders.Local][:uploads] == "test/uploads"
|
||||
|
||||
refute config[:pleroma][Pleroma.Repo]
|
||||
refute config[:pleroma][Pleroma.Web.Endpoint]
|
||||
refute config[:pleroma][:env]
|
||||
refute config[:pleroma][:configurable_from_database]
|
||||
refute config[:pleroma][:database]
|
||||
refute config[:phoenix][:serve_endpoints]
|
||||
refute config[:tesla][:adapter]
|
||||
end
|
||||
|
||||
test "default_config/1" do
|
||||
pleroma_config = Holder.default_config(:pleroma)
|
||||
assert pleroma_config[Pleroma.Uploaders.Local][:uploads] == "test/uploads"
|
||||
end
|
||||
|
||||
test "default_config/2" do
|
||||
assert Holder.default_config(:pleroma, Pleroma.Uploaders.Local) == [uploads: "test/uploads"]
|
||||
end
|
||||
end
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config.LoaderTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pleroma.Config.Loader
|
||||
|
||||
test "read/1" do
|
||||
config = Loader.read("test/fixtures/config/temp.secret.exs")
|
||||
assert config[:pleroma][:first_setting][:key] == "value"
|
||||
assert config[:pleroma][:first_setting][:key2] == [Pleroma.Repo]
|
||||
assert config[:quack][:level] == :info
|
||||
end
|
||||
|
||||
test "filter_group/2" do
|
||||
assert Loader.filter_group(:pleroma,
|
||||
pleroma: [
|
||||
{Pleroma.Repo, [a: 1, b: 2]},
|
||||
{Pleroma.Upload, [a: 1, b: 2]},
|
||||
{Pleroma.Web.Endpoint, []},
|
||||
env: :test,
|
||||
configurable_from_database: true,
|
||||
database: []
|
||||
]
|
||||
) == [{Pleroma.Upload, [a: 1, b: 2]}]
|
||||
end
|
||||
end
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config.TransferTaskTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config.TransferTask
|
||||
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
test "transfer config values from db to env" do
|
||||
refute Application.get_env(:pleroma, :test_key)
|
||||
refute Application.get_env(:idna, :test_key)
|
||||
refute Application.get_env(:quack, :test_key)
|
||||
refute Application.get_env(:postgrex, :test_key)
|
||||
initial = Application.get_env(:logger, :level)
|
||||
|
||||
insert(:config, key: :test_key, value: [live: 2, com: 3])
|
||||
insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
|
||||
insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
|
||||
insert(:config, group: :postgrex, key: :test_key, value: :value)
|
||||
insert(:config, group: :logger, key: :level, value: :debug)
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
|
||||
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
|
||||
assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
|
||||
assert Application.get_env(:logger, :level) == :debug
|
||||
assert Application.get_env(:postgrex, :test_key) == :value
|
||||
|
||||
on_exit(fn ->
|
||||
Application.delete_env(:pleroma, :test_key)
|
||||
Application.delete_env(:idna, :test_key)
|
||||
Application.delete_env(:quack, :test_key)
|
||||
Application.delete_env(:postgrex, :test_key)
|
||||
Application.put_env(:logger, :level, initial)
|
||||
end)
|
||||
end
|
||||
|
||||
test "transfer config values for 1 group and some keys" do
|
||||
level = Application.get_env(:quack, :level)
|
||||
meta = Application.get_env(:quack, :meta)
|
||||
|
||||
insert(:config, group: :quack, key: :level, value: :info)
|
||||
insert(:config, group: :quack, key: :meta, value: [:none])
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
assert Application.get_env(:quack, :level) == :info
|
||||
assert Application.get_env(:quack, :meta) == [:none]
|
||||
default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
|
||||
assert Application.get_env(:quack, :webhook_url) == default
|
||||
|
||||
on_exit(fn ->
|
||||
Application.put_env(:quack, :level, level)
|
||||
Application.put_env(:quack, :meta, meta)
|
||||
end)
|
||||
end
|
||||
|
||||
test "transfer config values with full subkey update" do
|
||||
clear_config(:emoji)
|
||||
clear_config(:assets)
|
||||
|
||||
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
|
||||
insert(:config, key: :assets, value: [mascots: [a: 1, b: 2]])
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
emoji_env = Application.get_env(:pleroma, :emoji)
|
||||
assert emoji_env[:groups] == [a: 1, b: 2]
|
||||
assets_env = Application.get_env(:pleroma, :assets)
|
||||
assert assets_env[:mascots] == [a: 1, b: 2]
|
||||
end
|
||||
|
||||
describe "pleroma restart" do
|
||||
setup do
|
||||
on_exit(fn -> Restarter.Pleroma.refresh() end)
|
||||
end
|
||||
|
||||
test "don't restart if no reboot time settings were changed" do
|
||||
clear_config(:emoji)
|
||||
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
|
||||
|
||||
refute String.contains?(
|
||||
capture_log(fn -> TransferTask.start_link([]) end),
|
||||
"pleroma restarted"
|
||||
)
|
||||
end
|
||||
|
||||
test "on reboot time key" do
|
||||
clear_config(:chat)
|
||||
insert(:config, key: :chat, value: [enabled: false])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
test "on reboot time subkey" do
|
||||
clear_config(Pleroma.Captcha)
|
||||
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
|
||||
clear_config(:chat)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
||||
insert(:config, key: :chat, value: [enabled: false])
|
||||
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
|
||||
|
||||
refute String.contains?(
|
||||
capture_log(fn -> TransferTask.load_and_update_env([], false) end),
|
||||
"pleroma restarted"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue