Merge branch 'develop' into '1865-media-only'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
7d542450b1
81 changed files with 1658 additions and 1053 deletions
|
|
@ -7,40 +7,28 @@ defmodule Pleroma.ConfigDBTest do
|
|||
import Pleroma.Factory
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
test "get_by_key/1" do
|
||||
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 "create/1" do
|
||||
{:ok, config} = ConfigDB.create(%{group: ":pleroma", key: ":some_key", value: "some_value"})
|
||||
assert config == ConfigDB.get_by_params(%{group: ":pleroma", key: ":some_key"})
|
||||
end
|
||||
|
||||
test "update/1" do
|
||||
config = insert(:config)
|
||||
{:ok, updated} = ConfigDB.update(config, %{value: "some_value"})
|
||||
loaded = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
assert loaded == updated
|
||||
end
|
||||
|
||||
test "get_all_as_keyword/0" do
|
||||
saved = insert(:config)
|
||||
insert(:config, group: ":quack", key: ":level", value: ConfigDB.to_binary(:info))
|
||||
insert(:config, group: ":quack", key: ":meta", value: ConfigDB.to_binary([:none]))
|
||||
insert(:config, group: ":quack", key: ":level", value: :info)
|
||||
insert(:config, group: ":quack", key: ":meta", value: [:none])
|
||||
|
||||
insert(:config,
|
||||
group: ":quack",
|
||||
key: ":webhook_url",
|
||||
value: ConfigDB.to_binary("https://hooks.slack.com/services/KEY/some_val")
|
||||
value: "https://hooks.slack.com/services/KEY/some_val"
|
||||
)
|
||||
|
||||
config = ConfigDB.get_all_as_keyword()
|
||||
|
||||
assert config[:pleroma] == [
|
||||
{ConfigDB.from_string(saved.key), ConfigDB.from_binary(saved.value)}
|
||||
{saved.key, saved.value}
|
||||
]
|
||||
|
||||
assert config[:quack][:level] == :info
|
||||
|
|
@ -51,11 +39,11 @@ defmodule Pleroma.ConfigDBTest do
|
|||
describe "update_or_create/1" do
|
||||
test "common" do
|
||||
config = insert(:config)
|
||||
key2 = "another_key"
|
||||
key2 = :another_key
|
||||
|
||||
params = [
|
||||
%{group: "pleroma", key: key2, value: "another_value"},
|
||||
%{group: config.group, key: config.key, value: "new_value"}
|
||||
%{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
|
||||
|
|
@ -65,16 +53,16 @@ defmodule Pleroma.ConfigDBTest do
|
|||
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})
|
||||
config2 = ConfigDB.get_by_params(%{group: :pleroma, key: key2})
|
||||
|
||||
assert config1.value == ConfigDB.transform("new_value")
|
||||
assert config2.value == ConfigDB.transform("another_value")
|
||||
assert config1.value == [a: 1, b: 2, c: "new_value"]
|
||||
assert config2.value == "another_value"
|
||||
end
|
||||
|
||||
test "partial update" do
|
||||
config = insert(:config, value: ConfigDB.to_binary(key1: "val1", key2: :val2))
|
||||
config = insert(:config, value: [key1: "val1", key2: :val2])
|
||||
|
||||
{:ok, _config} =
|
||||
{:ok, config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
|
|
@ -83,15 +71,14 @@ defmodule Pleroma.ConfigDBTest do
|
|||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
value = ConfigDB.from_binary(updated.value)
|
||||
assert length(value) == 3
|
||||
assert value[:key1] == :val1
|
||||
assert value[:key2] == :val2
|
||||
assert value[:key3] == :val3
|
||||
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: ConfigDB.to_binary(key1: "val1", key2: [k1: :v1, k2: "v2"]))
|
||||
config = insert(:config, value: [key1: "val1", key2: [k1: :v1, k2: "v2"]])
|
||||
|
||||
{:ok, config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
|
|
@ -103,18 +90,15 @@ defmodule Pleroma.ConfigDBTest do
|
|||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert config.value == updated.value
|
||||
|
||||
value = ConfigDB.from_binary(updated.value)
|
||||
assert value[:key1] == :val1
|
||||
assert value[:key2] == [k1: :v1, k2: :v2, k3: :v3]
|
||||
assert value[:key3] == :val3
|
||||
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: ConfigDB.to_binary(repo: Pleroma.Repo))
|
||||
config1 = insert(:config, key: :ecto_repos, value: [repo: Pleroma.Repo])
|
||||
|
||||
config2 =
|
||||
insert(:config, group: ":cors_plug", key: ":max_age", value: ConfigDB.to_binary(18))
|
||||
config2 = insert(:config, group: :cors_plug, key: :max_age, value: 18)
|
||||
|
||||
{:ok, _config} =
|
||||
ConfigDB.update_or_create(%{
|
||||
|
|
@ -133,8 +117,8 @@ defmodule Pleroma.ConfigDBTest do
|
|||
updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key})
|
||||
updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key})
|
||||
|
||||
assert ConfigDB.from_binary(updated1.value) == [another_repo: [Pleroma.Repo]]
|
||||
assert ConfigDB.from_binary(updated2.value) == 777
|
||||
assert updated1.value == [another_repo: [Pleroma.Repo]]
|
||||
assert updated2.value == 777
|
||||
end
|
||||
|
||||
test "full update if value is not keyword" do
|
||||
|
|
@ -142,7 +126,7 @@ defmodule Pleroma.ConfigDBTest do
|
|||
insert(:config,
|
||||
group: ":tesla",
|
||||
key: ":adapter",
|
||||
value: ConfigDB.to_binary(Tesla.Adapter.Hackney)
|
||||
value: Tesla.Adapter.Hackney
|
||||
)
|
||||
|
||||
{:ok, _config} =
|
||||
|
|
@ -154,20 +138,20 @@ defmodule Pleroma.ConfigDBTest do
|
|||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
assert ConfigDB.from_binary(updated.value) == Tesla.Adapter.Httpc
|
||||
assert updated.value == Tesla.Adapter.Httpc
|
||||
end
|
||||
|
||||
test "only full update for some subkeys" do
|
||||
config1 =
|
||||
insert(:config,
|
||||
key: ":emoji",
|
||||
value: ConfigDB.to_binary(groups: [a: 1, b: 2], key: [a: 1])
|
||||
value: [groups: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
config2 =
|
||||
insert(:config,
|
||||
key: ":assets",
|
||||
value: ConfigDB.to_binary(mascots: [a: 1, b: 2], key: [a: 1])
|
||||
value: [mascots: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
{:ok, _config} =
|
||||
|
|
@ -187,8 +171,8 @@ defmodule Pleroma.ConfigDBTest do
|
|||
updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key})
|
||||
updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key})
|
||||
|
||||
assert ConfigDB.from_binary(updated1.value) == [groups: [c: 3, d: 4], key: [a: 1, b: 2]]
|
||||
assert ConfigDB.from_binary(updated2.value) == [mascots: [c: 3, d: 4], key: [a: 1, b: 2]]
|
||||
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
|
||||
|
||||
|
|
@ -206,14 +190,14 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "partial subkeys delete" do
|
||||
config = insert(:config, value: ConfigDB.to_binary(groups: [a: 1, b: 2], key: [a: 1]))
|
||||
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 == ConfigDB.to_binary(key: [a: 1])
|
||||
assert deleted.value == [key: [a: 1]]
|
||||
|
||||
updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
|
||||
|
||||
|
|
@ -221,7 +205,7 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "full delete if remaining value after subkeys deletion is empty list" do
|
||||
config = insert(:config, value: ConfigDB.to_binary(groups: [a: 1, b: 2]))
|
||||
config = insert(:config, value: [groups: [a: 1, b: 2]])
|
||||
|
||||
{:ok, deleted} =
|
||||
ConfigDB.delete(%{group: config.group, key: config.key, subkeys: [":groups"]})
|
||||
|
|
@ -232,234 +216,159 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "transform/1" do
|
||||
describe "to_elixir_types/1" do
|
||||
test "string" do
|
||||
binary = ConfigDB.transform("value as string")
|
||||
assert binary == :erlang.term_to_binary("value as string")
|
||||
assert ConfigDB.from_binary(binary) == "value as string"
|
||||
assert ConfigDB.to_elixir_types("value as string") == "value as string"
|
||||
end
|
||||
|
||||
test "boolean" do
|
||||
binary = ConfigDB.transform(false)
|
||||
assert binary == :erlang.term_to_binary(false)
|
||||
assert ConfigDB.from_binary(binary) == false
|
||||
assert ConfigDB.to_elixir_types(false) == false
|
||||
end
|
||||
|
||||
test "nil" do
|
||||
binary = ConfigDB.transform(nil)
|
||||
assert binary == :erlang.term_to_binary(nil)
|
||||
assert ConfigDB.from_binary(binary) == nil
|
||||
assert ConfigDB.to_elixir_types(nil) == nil
|
||||
end
|
||||
|
||||
test "integer" do
|
||||
binary = ConfigDB.transform(150)
|
||||
assert binary == :erlang.term_to_binary(150)
|
||||
assert ConfigDB.from_binary(binary) == 150
|
||||
assert ConfigDB.to_elixir_types(150) == 150
|
||||
end
|
||||
|
||||
test "atom" do
|
||||
binary = ConfigDB.transform(":atom")
|
||||
assert binary == :erlang.term_to_binary(:atom)
|
||||
assert ConfigDB.from_binary(binary) == :atom
|
||||
assert ConfigDB.to_elixir_types(":atom") == :atom
|
||||
end
|
||||
|
||||
test "ssl options" do
|
||||
binary = ConfigDB.transform([":tlsv1", ":tlsv1.1", ":tlsv1.2"])
|
||||
assert binary == :erlang.term_to_binary([:tlsv1, :"tlsv1.1", :"tlsv1.2"])
|
||||
assert ConfigDB.from_binary(binary) == [:tlsv1, :"tlsv1.1", :"tlsv1.2"]
|
||||
assert ConfigDB.to_elixir_types([":tlsv1", ":tlsv1.1", ":tlsv1.2"]) == [
|
||||
:tlsv1,
|
||||
:"tlsv1.1",
|
||||
:"tlsv1.2"
|
||||
]
|
||||
end
|
||||
|
||||
test "pleroma module" do
|
||||
binary = ConfigDB.transform("Pleroma.Bookmark")
|
||||
assert binary == :erlang.term_to_binary(Pleroma.Bookmark)
|
||||
assert ConfigDB.from_binary(binary) == Pleroma.Bookmark
|
||||
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
|
||||
end
|
||||
|
||||
test "pleroma string" do
|
||||
binary = ConfigDB.transform("Pleroma")
|
||||
assert binary == :erlang.term_to_binary("Pleroma")
|
||||
assert ConfigDB.from_binary(binary) == "Pleroma"
|
||||
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
|
||||
end
|
||||
|
||||
test "phoenix module" do
|
||||
binary = ConfigDB.transform("Phoenix.Socket.V1.JSONSerializer")
|
||||
assert binary == :erlang.term_to_binary(Phoenix.Socket.V1.JSONSerializer)
|
||||
assert ConfigDB.from_binary(binary) == Phoenix.Socket.V1.JSONSerializer
|
||||
assert ConfigDB.to_elixir_types("Phoenix.Socket.V1.JSONSerializer") ==
|
||||
Phoenix.Socket.V1.JSONSerializer
|
||||
end
|
||||
|
||||
test "tesla module" do
|
||||
binary = ConfigDB.transform("Tesla.Adapter.Hackney")
|
||||
assert binary == :erlang.term_to_binary(Tesla.Adapter.Hackney)
|
||||
assert ConfigDB.from_binary(binary) == Tesla.Adapter.Hackney
|
||||
assert ConfigDB.to_elixir_types("Tesla.Adapter.Hackney") == Tesla.Adapter.Hackney
|
||||
end
|
||||
|
||||
test "ExSyslogger module" do
|
||||
binary = ConfigDB.transform("ExSyslogger")
|
||||
assert binary == :erlang.term_to_binary(ExSyslogger)
|
||||
assert ConfigDB.from_binary(binary) == ExSyslogger
|
||||
assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger
|
||||
end
|
||||
|
||||
test "Quack.Logger module" do
|
||||
binary = ConfigDB.transform("Quack.Logger")
|
||||
assert binary == :erlang.term_to_binary(Quack.Logger)
|
||||
assert ConfigDB.from_binary(binary) == Quack.Logger
|
||||
assert ConfigDB.to_elixir_types("Quack.Logger") == 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
|
||||
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
|
||||
binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
|
||||
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
|
||||
assert ConfigDB.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
|
||||
assert ConfigDB.to_elixir_types("~r[comp[lL][aA][iI][nN]er]") == ~r/comp[lL][aA][iI][nN]er/
|
||||
end
|
||||
|
||||
test "link sigil" do
|
||||
binary = ConfigDB.transform("~r/https:\/\/example.com/")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
|
||||
assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/") == ~r/https:\/\/example.com/
|
||||
end
|
||||
|
||||
test "link sigil with um modifiers" do
|
||||
binary = ConfigDB.transform("~r/https:\/\/example.com/um")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/um)
|
||||
assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/um
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/um") ==
|
||||
~r/https:\/\/example.com/um
|
||||
end
|
||||
|
||||
test "link sigil with i modifier" do
|
||||
binary = ConfigDB.transform("~r/https:\/\/example.com/i")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
|
||||
assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/i
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/i") == ~r/https:\/\/example.com/i
|
||||
end
|
||||
|
||||
test "link sigil with s modifier" do
|
||||
binary = ConfigDB.transform("~r/https:\/\/example.com/s")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
|
||||
assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/s
|
||||
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.transform("~r/https://[]{}<>\"'()|example.com/s")
|
||||
ConfigDB.to_elixir_types("~r/https://[]{}<>\"'()|example.com/s")
|
||||
end
|
||||
end
|
||||
|
||||
test "2 child tuple" do
|
||||
binary = ConfigDB.transform(%{"tuple" => ["v1", ":v2"]})
|
||||
assert binary == :erlang.term_to_binary({"v1", :v2})
|
||||
assert ConfigDB.from_binary(binary) == {"v1", :v2}
|
||||
assert ConfigDB.to_elixir_types(%{"tuple" => ["v1", ":v2"]}) == {"v1", :v2}
|
||||
end
|
||||
|
||||
test "proxy tuple with localhost" do
|
||||
binary =
|
||||
ConfigDB.transform(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]
|
||||
})
|
||||
|
||||
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, :localhost, 1234}})
|
||||
assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, :localhost, 1234}}
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]
|
||||
}) == {:proxy_url, {:socks5, :localhost, 1234}}
|
||||
end
|
||||
|
||||
test "proxy tuple with domain" do
|
||||
binary =
|
||||
ConfigDB.transform(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]
|
||||
})
|
||||
|
||||
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, 'domain.com', 1234}})
|
||||
assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, 'domain.com', 1234}}
|
||||
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
|
||||
binary =
|
||||
ConfigDB.transform(%{
|
||||
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]
|
||||
})
|
||||
|
||||
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}})
|
||||
assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}}
|
||||
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
|
||||
binary =
|
||||
ConfigDB.transform(%{
|
||||
"tuple" => [
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Bookmark",
|
||||
150,
|
||||
false,
|
||||
"Phoenix.Socket.V1.JSONSerializer"
|
||||
]
|
||||
})
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) ==
|
||||
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
|
||||
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
|
||||
binary = ConfigDB.transform(%{"key" => "value"})
|
||||
assert binary == :erlang.term_to_binary(%{"key" => "value"})
|
||||
assert ConfigDB.from_binary(binary) == %{"key" => "value"}
|
||||
assert ConfigDB.to_elixir_types(%{"key" => "value"}) == %{"key" => "value"}
|
||||
end
|
||||
|
||||
test "map with atom key" do
|
||||
binary = ConfigDB.transform(%{":key" => "value"})
|
||||
assert binary == :erlang.term_to_binary(%{key: "value"})
|
||||
assert ConfigDB.from_binary(binary) == %{key: "value"}
|
||||
assert ConfigDB.to_elixir_types(%{":key" => "value"}) == %{key: "value"}
|
||||
end
|
||||
|
||||
test "list of strings" do
|
||||
binary = ConfigDB.transform(["v1", "v2", "v3"])
|
||||
assert binary == :erlang.term_to_binary(["v1", "v2", "v3"])
|
||||
assert ConfigDB.from_binary(binary) == ["v1", "v2", "v3"]
|
||||
assert ConfigDB.to_elixir_types(["v1", "v2", "v3"]) == ["v1", "v2", "v3"]
|
||||
end
|
||||
|
||||
test "list of modules" do
|
||||
binary = ConfigDB.transform(["Pleroma.Repo", "Pleroma.Activity"])
|
||||
assert binary == :erlang.term_to_binary([Pleroma.Repo, Pleroma.Activity])
|
||||
assert ConfigDB.from_binary(binary) == [Pleroma.Repo, Pleroma.Activity]
|
||||
assert ConfigDB.to_elixir_types(["Pleroma.Repo", "Pleroma.Activity"]) == [
|
||||
Pleroma.Repo,
|
||||
Pleroma.Activity
|
||||
]
|
||||
end
|
||||
|
||||
test "list of atoms" do
|
||||
binary = ConfigDB.transform([":v1", ":v2", ":v3"])
|
||||
assert binary == :erlang.term_to_binary([:v1, :v2, :v3])
|
||||
assert ConfigDB.from_binary(binary) == [:v1, :v2, :v3]
|
||||
assert ConfigDB.to_elixir_types([":v1", ":v2", ":v3"]) == [:v1, :v2, :v3]
|
||||
end
|
||||
|
||||
test "list of mixed values" do
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Repo",
|
||||
"Phoenix.Socket.V1.JSONSerializer",
|
||||
15,
|
||||
false
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary([
|
||||
"v1",
|
||||
:v2,
|
||||
Pleroma.Repo,
|
||||
Phoenix.Socket.V1.JSONSerializer,
|
||||
15,
|
||||
false
|
||||
])
|
||||
|
||||
assert ConfigDB.from_binary(binary) == [
|
||||
assert ConfigDB.to_elixir_types([
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Repo",
|
||||
"Phoenix.Socket.V1.JSONSerializer",
|
||||
15,
|
||||
false
|
||||
]) == [
|
||||
"v1",
|
||||
:v2,
|
||||
Pleroma.Repo,
|
||||
|
|
@ -470,40 +379,17 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "simple keyword" do
|
||||
binary = ConfigDB.transform([%{"tuple" => [":key", "value"]}])
|
||||
assert binary == :erlang.term_to_binary([{:key, "value"}])
|
||||
assert ConfigDB.from_binary(binary) == [{:key, "value"}]
|
||||
assert ConfigDB.from_binary(binary) == [key: "value"]
|
||||
end
|
||||
|
||||
test "keyword with partial_chain key" do
|
||||
binary =
|
||||
ConfigDB.transform([%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}])
|
||||
|
||||
assert binary == :erlang.term_to_binary(partial_chain: &:hackney_connect.partial_chain/1)
|
||||
assert ConfigDB.from_binary(binary) == [partial_chain: &:hackney_connect.partial_chain/1]
|
||||
assert ConfigDB.to_elixir_types([%{"tuple" => [":key", "value"]}]) == [key: "value"]
|
||||
end
|
||||
|
||||
test "keyword" do
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
%{"tuple" => [":types", "Pleroma.PostgresTypes"]},
|
||||
%{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]},
|
||||
%{"tuple" => [":migration_lock", nil]},
|
||||
%{"tuple" => [":key1", 150]},
|
||||
%{"tuple" => [":key2", "string"]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
types: Pleroma.PostgresTypes,
|
||||
telemetry_event: [Pleroma.Repo.Instrumenter],
|
||||
migration_lock: nil,
|
||||
key1: 150,
|
||||
key2: "string"
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) == [
|
||||
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,
|
||||
|
|
@ -512,86 +398,60 @@ defmodule Pleroma.ConfigDBTest do
|
|||
]
|
||||
end
|
||||
|
||||
test "complex keyword with nested mixed childs" do
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
%{"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"]}]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
])
|
||||
test "trandformed keyword" do
|
||||
assert ConfigDB.to_elixir_types(a: 1, b: 2, c: "string") == [a: 1, b: 2, c: "string"]
|
||||
end
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
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
|
||||
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"]}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) ==
|
||||
[
|
||||
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
|
||||
]
|
||||
}
|
||||
]) == [
|
||||
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
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
%{"tuple" => [":level", ":warn"]},
|
||||
%{"tuple" => [":meta", [":all"]]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":val", nil]},
|
||||
%{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
level: :warn,
|
||||
meta: [:all],
|
||||
path: "",
|
||||
val: nil,
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) == [
|
||||
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: "",
|
||||
|
|
@ -601,98 +461,73 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "complex keyword with sigil" do
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
%{"tuple" => [":federated_timeline_removal", []]},
|
||||
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
|
||||
%{"tuple" => [":replace", []]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
federated_timeline_removal: [],
|
||||
reject: [~r/comp[lL][aA][iI][nN]er/],
|
||||
replace: []
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) ==
|
||||
[federated_timeline_removal: [], reject: [~r/comp[lL][aA][iI][nN]er/], replace: []]
|
||||
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
|
||||
binary =
|
||||
ConfigDB.transform([
|
||||
%{
|
||||
"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", []]}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
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, []}}
|
||||
]
|
||||
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", []]}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
assert ConfigDB.from_binary(binary) == [
|
||||
}
|
||||
]) == [
|
||||
http: [
|
||||
key1: [
|
||||
{:_,
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config.TransferTask
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
|
|
@ -19,31 +19,11 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
refute Application.get_env(:postgrex, :test_key)
|
||||
initial = Application.get_env(:logger, :level)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":test_key",
|
||||
value: [live: 2, com: 3]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":idna",
|
||||
key: ":test_key",
|
||||
value: [live: 15, com: 35]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":quack",
|
||||
key: ":test_key",
|
||||
value: [:test_value1, :test_value2]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":postgrex",
|
||||
key: ":test_key",
|
||||
value: :value
|
||||
})
|
||||
|
||||
ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
|
||||
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([])
|
||||
|
||||
|
|
@ -66,17 +46,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
level = Application.get_env(:quack, :level)
|
||||
meta = Application.get_env(:quack, :meta)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":quack",
|
||||
key: ":level",
|
||||
value: :info
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":quack",
|
||||
key: ":meta",
|
||||
value: [:none]
|
||||
})
|
||||
insert(:config, group: :quack, key: :level, value: :info)
|
||||
insert(:config, group: :quack, key: :meta, value: [:none])
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
|
|
@ -95,17 +66,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
clear_config(:emoji)
|
||||
clear_config(:assets)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":emoji",
|
||||
value: [groups: [a: 1, b: 2]]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":assets",
|
||||
value: [mascots: [a: 1, b: 2]]
|
||||
})
|
||||
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
|
||||
insert(:config, key: :assets, value: [mascots: [a: 1, b: 2]])
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
|
|
@ -122,12 +84,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
|
||||
test "don't restart if no reboot time settings were changed" do
|
||||
clear_config(:emoji)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":emoji",
|
||||
value: [groups: [a: 1, b: 2]]
|
||||
})
|
||||
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
|
||||
|
||||
refute String.contains?(
|
||||
capture_log(fn -> TransferTask.start_link([]) end),
|
||||
|
|
@ -137,25 +94,13 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
|
||||
test "on reboot time key" do
|
||||
clear_config(:chat)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":chat",
|
||||
value: [enabled: false]
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Captcha",
|
||||
value: [seconds_valid: 60]
|
||||
})
|
||||
|
||||
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
|
|
@ -163,17 +108,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
clear_config(:chat)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":chat",
|
||||
value: [enabled: false]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Captcha",
|
||||
value: [seconds_valid: 60]
|
||||
})
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ defmodule Pleroma.Factory do
|
|||
user
|
||||
| ap_id: User.ap_id(user),
|
||||
follower_address: User.ap_followers(user),
|
||||
following_address: User.ap_following(user)
|
||||
following_address: User.ap_following(user),
|
||||
raw_bio: user.bio
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -396,24 +397,17 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def config_factory do
|
||||
def config_factory(attrs \\ %{}) do
|
||||
%Pleroma.ConfigDB{
|
||||
key:
|
||||
sequence(:key, fn key ->
|
||||
# Atom dynamic registration hack in tests
|
||||
"some_key_#{key}"
|
||||
|> String.to_atom()
|
||||
|> inspect()
|
||||
end),
|
||||
group: ":pleroma",
|
||||
key: sequence(:key, &String.to_atom("some_key_#{&1}")),
|
||||
group: :pleroma,
|
||||
value:
|
||||
sequence(
|
||||
:value,
|
||||
fn key ->
|
||||
:erlang.term_to_binary(%{another_key: "#{key}somevalue", another: "#{key}somevalue"})
|
||||
end
|
||||
&%{another_key: "#{&1}somevalue", another: "#{&1}somevalue"}
|
||||
)
|
||||
}
|
||||
|> merge_attributes(attrs)
|
||||
end
|
||||
|
||||
def marker_factory do
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
defmodule Mix.Tasks.Pleroma.ConfigTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.ConfigDB
|
||||
alias Pleroma.Repo
|
||||
|
||||
|
|
@ -49,24 +51,19 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
|
||||
refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
|
||||
|
||||
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
|
||||
assert config1.value == [key: "value", key2: [Repo]]
|
||||
assert config2.value == [key: "value2", key2: ["Activity"]]
|
||||
assert config3.value == :info
|
||||
end
|
||||
|
||||
test "config table is truncated before migration" do
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":first_setting",
|
||||
value: [key: "value", key2: ["Activity"]]
|
||||
})
|
||||
|
||||
insert(:config, 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]]
|
||||
assert config.value == [key: "value", key2: [Repo]]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -82,19 +79,9 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
end
|
||||
|
||||
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":setting_first",
|
||||
value: [key: "value", key2: ["Activity"]]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":setting_second",
|
||||
value: [key: "value2", key2: [Repo]]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{group: ":quack", key: ":level", value: :info})
|
||||
insert(:config, key: :setting_first, value: [key: "value", key2: ["Activity"]])
|
||||
insert(:config, key: :setting_second, value: [key: "value2", key2: [Repo]])
|
||||
insert(:config, group: :quack, key: :level, value: :info)
|
||||
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
|
||||
|
||||
|
|
@ -107,9 +94,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
end
|
||||
|
||||
test "load a settings with large values and pass to file", %{temp_file: temp_file} do
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
key: ":instance",
|
||||
insert(:config,
|
||||
key: :instance,
|
||||
value: [
|
||||
name: "Pleroma",
|
||||
email: "example@example.com",
|
||||
|
|
@ -163,7 +149,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
extended_nickname_format: true,
|
||||
multi_factor_authentication: [
|
||||
totp: [
|
||||
# digits 6 or 8
|
||||
digits: 6,
|
||||
period: 30
|
||||
],
|
||||
|
|
@ -173,7 +158,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
]
|
||||
]
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,17 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
|
|||
use Pleroma.DataCase
|
||||
import Mock
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Upload
|
||||
alias Pleroma.Upload.Filter
|
||||
|
||||
setup do: clear_config([Filter.Mogrify, :args])
|
||||
|
||||
test "apply mogrify filter" do
|
||||
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
|
||||
clear_config(Filter.Mogrify, args: [{"tint", "40"}])
|
||||
|
||||
File.cp!(
|
||||
"test/fixtures/image.jpg",
|
||||
"test/fixtures/image_tmp.jpg"
|
||||
)
|
||||
|
||||
upload = %Upload{
|
||||
upload = %Pleroma.Upload{
|
||||
name: "an… image.jpg",
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTimeTest do
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTime
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "it validates an xsd:Datetime" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ObjectValidators.Types.ObjectIDTest do
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
|
||||
use Pleroma.DataCase
|
||||
|
||||
@uris [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Pleroma.Web.ObjectValidators.Types.RecipientsTest do
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types.Recipients
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "it asserts that all elements of the list are object ids" do
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeTextTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeText
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
|
||||
|
||||
test "it lets normal text go through" do
|
||||
text = "hey how are you"
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
]
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert key1 == config1.key
|
||||
assert key2 == config2.key
|
||||
assert key1 == inspect(config1.key)
|
||||
assert key2 == inspect(config2.key)
|
||||
end
|
||||
|
||||
test "db is added to settings that are in db", %{conn: conn} do
|
||||
_config = insert(:config, key: ":instance", value: ConfigDB.to_binary(name: "Some name"))
|
||||
_config = insert(:config, key: ":instance", value: [name: "Some name"])
|
||||
|
||||
%{"configs" => configs} =
|
||||
conn
|
||||
|
|
@ -83,7 +83,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|
||||
config3 =
|
||||
insert(:config,
|
||||
value: ConfigDB.to_binary(k1: :v1, k2: :v2)
|
||||
value: [k1: :v1, k2: :v2]
|
||||
)
|
||||
|
||||
%{"configs" => configs} =
|
||||
|
|
@ -93,42 +93,45 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|
||||
assert length(configs) > 3
|
||||
|
||||
saved_configs = [config1, config2, config3]
|
||||
keys = Enum.map(saved_configs, &inspect(&1.key))
|
||||
|
||||
received_configs =
|
||||
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
||||
group == ":pleroma" and key in [config1.key, config2.key, config3.key]
|
||||
group == ":pleroma" and key in keys
|
||||
end)
|
||||
|
||||
assert length(received_configs) == 3
|
||||
|
||||
db_keys =
|
||||
config3.value
|
||||
|> ConfigDB.from_binary()
|
||||
|> Keyword.keys()
|
||||
|> ConfigDB.convert()
|
||||
|> ConfigDB.to_json_types()
|
||||
|
||||
keys = Enum.map(saved_configs -- [config3], &inspect(&1.key))
|
||||
|
||||
values = Enum.map(saved_configs, &ConfigDB.to_json_types(&1.value))
|
||||
|
||||
mapset_keys = MapSet.new(keys ++ db_keys)
|
||||
|
||||
Enum.each(received_configs, fn %{"value" => value, "db" => db} ->
|
||||
assert db in [[config1.key], [config2.key], db_keys]
|
||||
db = MapSet.new(db)
|
||||
assert MapSet.subset?(db, mapset_keys)
|
||||
|
||||
assert value in [
|
||||
ConfigDB.from_binary_with_convert(config1.value),
|
||||
ConfigDB.from_binary_with_convert(config2.value),
|
||||
ConfigDB.from_binary_with_convert(config3.value)
|
||||
]
|
||||
assert value in values
|
||||
end)
|
||||
end
|
||||
|
||||
test "subkeys with full update right merge", %{conn: conn} do
|
||||
config1 =
|
||||
insert(:config,
|
||||
key: ":emoji",
|
||||
value: ConfigDB.to_binary(groups: [a: 1, b: 2], key: [a: 1])
|
||||
)
|
||||
insert(:config,
|
||||
key: ":emoji",
|
||||
value: [groups: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
config2 =
|
||||
insert(:config,
|
||||
key: ":assets",
|
||||
value: ConfigDB.to_binary(mascots: [a: 1, b: 2], key: [a: 1])
|
||||
)
|
||||
insert(:config,
|
||||
key: ":assets",
|
||||
value: [mascots: [a: 1, b: 2], key: [a: 1]]
|
||||
)
|
||||
|
||||
%{"configs" => configs} =
|
||||
conn
|
||||
|
|
@ -137,14 +140,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|
||||
vals =
|
||||
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
||||
group == ":pleroma" and key in [config1.key, config2.key]
|
||||
group == ":pleroma" and key in [":emoji", ":assets"]
|
||||
end)
|
||||
|
||||
emoji = Enum.find(vals, fn %{"key" => key} -> key == ":emoji" end)
|
||||
assets = Enum.find(vals, fn %{"key" => key} -> key == ":assets" end)
|
||||
|
||||
emoji_val = ConfigDB.transform_with_out_binary(emoji["value"])
|
||||
assets_val = ConfigDB.transform_with_out_binary(assets["value"])
|
||||
emoji_val = ConfigDB.to_elixir_types(emoji["value"])
|
||||
assets_val = ConfigDB.to_elixir_types(assets["value"])
|
||||
|
||||
assert emoji_val[:groups] == [a: 1, b: 2]
|
||||
assert assets_val[:mascots] == [a: 1, b: 2]
|
||||
|
|
@ -277,7 +280,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
|
||||
"db" => [":key5"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:pleroma, :key1) == "value1"
|
||||
|
|
@ -357,7 +361,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"value" => "https://hooks.slack.com/services/KEY",
|
||||
"db" => [":webhook_url"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:quack, :level) == :info
|
||||
|
|
@ -366,14 +371,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving config with partial update", %{conn: conn} do
|
||||
config = insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
|
||||
insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: config.group, key: config.key, value: [%{"tuple" => [":key3", 3]}]}
|
||||
%{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
|
||||
]
|
||||
})
|
||||
|
||||
|
|
@ -389,7 +394,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":key1", ":key2", ":key3"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -500,8 +506,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving config with nested merge", %{conn: conn} do
|
||||
config =
|
||||
insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: [k1: 1, k2: 2]))
|
||||
insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -509,8 +514,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
group: ":pleroma",
|
||||
key: ":key1",
|
||||
value: [
|
||||
%{"tuple" => [":key3", 3]},
|
||||
%{
|
||||
|
|
@ -548,7 +553,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":key1", ":key3", ":key2"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -588,7 +594,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":ssl_options"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:pleroma, :key1) == [
|
||||
|
|
@ -600,12 +607,11 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
backends = Application.get_env(:logger, :backends)
|
||||
on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
|
||||
|
||||
config =
|
||||
insert(:config,
|
||||
group: ":logger",
|
||||
key: ":backends",
|
||||
value: :erlang.term_to_binary([])
|
||||
)
|
||||
insert(:config,
|
||||
group: :logger,
|
||||
key: :backends,
|
||||
value: []
|
||||
)
|
||||
|
||||
Pleroma.Config.TransferTask.load_and_update_env([], false)
|
||||
|
||||
|
|
@ -617,8 +623,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
group: ":logger",
|
||||
key: ":backends",
|
||||
value: [":console"]
|
||||
}
|
||||
]
|
||||
|
|
@ -634,7 +640,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":backends"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:logger, :backends) == [
|
||||
|
|
@ -643,19 +650,18 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving full setting if value is not keyword", %{conn: conn} do
|
||||
config =
|
||||
insert(:config,
|
||||
group: ":tesla",
|
||||
key: ":adapter",
|
||||
value: :erlang.term_to_binary(Tesla.Adapter.Hackey)
|
||||
)
|
||||
insert(:config,
|
||||
group: :tesla,
|
||||
key: :adapter,
|
||||
value: Tesla.Adapter.Hackey
|
||||
)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: config.group, key: config.key, value: "Tesla.Adapter.Httpc"}
|
||||
%{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
|
||||
]
|
||||
})
|
||||
|
||||
|
|
@ -667,7 +673,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"value" => "Tesla.Adapter.Httpc",
|
||||
"db" => [":adapter"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -677,13 +684,13 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
token: token
|
||||
} do
|
||||
ueberauth = Application.get_env(:ueberauth, Ueberauth)
|
||||
config1 = insert(:config, key: ":keyaa1")
|
||||
config2 = insert(:config, key: ":keyaa2")
|
||||
insert(:config, key: :keyaa1)
|
||||
insert(:config, key: :keyaa2)
|
||||
|
||||
config3 =
|
||||
insert(:config,
|
||||
group: ":ueberauth",
|
||||
key: "Ueberauth"
|
||||
group: :ueberauth,
|
||||
key: Ueberauth
|
||||
)
|
||||
|
||||
conn =
|
||||
|
|
@ -691,8 +698,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: config1.group, key: config1.key, value: "another_value"},
|
||||
%{group: config2.group, key: config2.key, value: "another_value"}
|
||||
%{group: ":pleroma", key: ":keyaa1", value: "another_value"},
|
||||
%{group: ":pleroma", key: ":keyaa2", value: "another_value"}
|
||||
]
|
||||
})
|
||||
|
||||
|
|
@ -700,22 +707,23 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"configs" => [
|
||||
%{
|
||||
"group" => ":pleroma",
|
||||
"key" => config1.key,
|
||||
"key" => ":keyaa1",
|
||||
"value" => "another_value",
|
||||
"db" => [":keyaa1"]
|
||||
},
|
||||
%{
|
||||
"group" => ":pleroma",
|
||||
"key" => config2.key,
|
||||
"key" => ":keyaa2",
|
||||
"value" => "another_value",
|
||||
"db" => [":keyaa2"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:pleroma, :keyaa1) == "another_value"
|
||||
assert Application.get_env(:pleroma, :keyaa2) == "another_value"
|
||||
assert Application.get_env(:ueberauth, Ueberauth) == ConfigDB.from_binary(config3.value)
|
||||
assert Application.get_env(:ueberauth, Ueberauth) == config3.value
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -724,7 +732,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: config2.group, key: config2.key, delete: true},
|
||||
%{group: ":pleroma", key: ":keyaa2", delete: true},
|
||||
%{
|
||||
group: ":ueberauth",
|
||||
key: "Ueberauth",
|
||||
|
|
@ -734,7 +742,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
})
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"configs" => []
|
||||
"configs" => [],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
|
||||
|
|
@ -801,7 +810,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
":name"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -935,7 +945,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":http"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1000,7 +1011,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
],
|
||||
"db" => [":key2", ":key3"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1027,7 +1039,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"value" => %{"key" => "some_val"},
|
||||
"db" => [":key1"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1077,16 +1090,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
":background"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
test "delete part of settings by atom subkeys", %{conn: conn} do
|
||||
config =
|
||||
insert(:config,
|
||||
key: ":keyaa1",
|
||||
value: :erlang.term_to_binary(subkey1: "val1", subkey2: "val2", subkey3: "val3")
|
||||
)
|
||||
insert(:config,
|
||||
key: :keyaa1,
|
||||
value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
|
||||
)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1094,8 +1107,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
group: ":pleroma",
|
||||
key: ":keyaa1",
|
||||
subkeys: [":subkey1", ":subkey3"],
|
||||
delete: true
|
||||
}
|
||||
|
|
@ -1110,7 +1123,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"value" => [%{"tuple" => [":subkey2", "val2"]}],
|
||||
"db" => [":subkey2"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1236,6 +1250,90 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
|
||||
assert Application.get_env(:not_real, :anything) == "value6"
|
||||
end
|
||||
|
||||
test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
|
||||
clear_config(Pleroma.Upload.Filter.Mogrify)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Upload.Filter.Mogrify",
|
||||
value: [
|
||||
%{"tuple" => [":args", ["auto-orient", "strip"]]}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|> json_response_and_validate_schema(200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => ":pleroma",
|
||||
"key" => "Pleroma.Upload.Filter.Mogrify",
|
||||
"value" => [
|
||||
%{"tuple" => [":args", ["auto-orient", "strip"]]}
|
||||
],
|
||||
"db" => [":args"]
|
||||
}
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Upload.Filter.Mogrify",
|
||||
value: [
|
||||
%{
|
||||
"tuple" => [
|
||||
":args",
|
||||
[
|
||||
"auto-orient",
|
||||
"strip",
|
||||
"{\"implode\", \"1\"}",
|
||||
"{\"resize\", \"3840x1080>\"}"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|> json_response(200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => ":pleroma",
|
||||
"key" => "Pleroma.Upload.Filter.Mogrify",
|
||||
"value" => [
|
||||
%{
|
||||
"tuple" => [
|
||||
":args",
|
||||
[
|
||||
"auto-orient",
|
||||
"strip",
|
||||
"{\"implode\", \"1\"}",
|
||||
"{\"resize\", \"3840x1080>\"}"
|
||||
]
|
||||
]
|
||||
}
|
||||
],
|
||||
"db" => [":args"]
|
||||
}
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
|
||||
args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/config/descriptions" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,145 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
setup do: clear_config([:media_proxy])
|
||||
|
||||
setup do
|
||||
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
|
||||
end
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
|
||||
|
||||
{:ok, %{admin: admin, token: token, conn: conn}}
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/media_proxy_caches" do
|
||||
test "shows banned MediaProxy URLs", %{conn: conn} do
|
||||
MediaProxy.put_in_banned_urls([
|
||||
"http://localhost:4001/media/a688346.jpg",
|
||||
"http://localhost:4001/media/fb1f4d.jpg"
|
||||
])
|
||||
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/gb1f44.jpg")
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/tb13f47.jpg")
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/wb1f46.jpg")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/fb1f4d.jpg",
|
||||
"http://localhost:4001/media/a688346.jpg"
|
||||
]
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=2")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/gb1f44.jpg",
|
||||
"http://localhost:4001/media/tb13f47.jpg"
|
||||
]
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=3")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == ["http://localhost:4001/media/wb1f46.jpg"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/media_proxy_caches/delete" do
|
||||
test "deleted MediaProxy URLs from banned", %{conn: conn} do
|
||||
MediaProxy.put_in_banned_urls([
|
||||
"http://localhost:4001/media/a688346.jpg",
|
||||
"http://localhost:4001/media/fb1f4d.jpg"
|
||||
])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/delete", %{
|
||||
urls: ["http://localhost:4001/media/a688346.jpg"]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == ["http://localhost:4001/media/a688346.jpg"]
|
||||
refute MediaProxy.in_banned_urls("http://localhost:4001/media/a688346.jpg")
|
||||
assert MediaProxy.in_banned_urls("http://localhost:4001/media/fb1f4d.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/media_proxy_caches/purge" do
|
||||
test "perform invalidates cache of MediaProxy", %{conn: conn} do
|
||||
urls = [
|
||||
"http://example.com/media/a688346.jpg",
|
||||
"http://example.com/media/fb1f4d.jpg"
|
||||
]
|
||||
|
||||
with_mocks [
|
||||
{MediaProxy.Invalidation.Script, [],
|
||||
[
|
||||
purge: fn _, _ -> {"ok", 0} end
|
||||
]}
|
||||
] do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/purge", %{urls: urls, ban: false})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == urls
|
||||
|
||||
refute MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
|
||||
refute MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
test "perform invalidates cache of MediaProxy and adds url to banned", %{conn: conn} do
|
||||
urls = [
|
||||
"http://example.com/media/a688346.jpg",
|
||||
"http://example.com/media/fb1f4d.jpg"
|
||||
]
|
||||
|
||||
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/purge", %{
|
||||
urls: urls,
|
||||
ban: true
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == urls
|
||||
|
||||
assert MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
|
||||
assert MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -83,10 +83,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
test "updates the user's bio", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
})
|
||||
raw_bio = "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"note" => raw_bio})
|
||||
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
|
|
@ -94,6 +93,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
user2.id
|
||||
}" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
||||
|
||||
assert user_data["source"]["note"] == raw_bio
|
||||
|
||||
user = Repo.get(User, user_data["id"])
|
||||
|
||||
assert user.raw_bio == raw_bio
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -151,6 +151,22 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
]
|
||||
end
|
||||
|
||||
test "supports pagination of hashtags search results", %{conn: conn} do
|
||||
results =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v2/search?#{
|
||||
URI.encode_query(%{q: "#some #text #with #hashtags", limit: 2, offset: 1})
|
||||
}"
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "text", "url" => "#{Web.base_url()}/tag/text"},
|
||||
%{"name" => "with", "url" => "#{Web.base_url()}/tag/with"}
|
||||
]
|
||||
end
|
||||
|
||||
test "excludes a blocked users from search results", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_smith = insert(:user, %{nickname: "Agent", name: "I love 2hu"})
|
||||
|
|
|
|||
|
|
@ -1561,7 +1561,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
# Using the header for pagination works correctly
|
||||
[next, _] = get_resp_header(result, "link") |> hd() |> String.split(", ")
|
||||
[_, max_id] = Regex.run(~r/max_id=(.*)>;/, next)
|
||||
[_, max_id] = Regex.run(~r/max_id=([^&]+)/, next)
|
||||
|
||||
assert max_id == third_favorite.id
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
bio:
|
||||
"<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f '&<>\"",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036],
|
||||
emoji: %{"karjalanpiirakka" => "/file.png"}
|
||||
emoji: %{"karjalanpiirakka" => "/file.png"},
|
||||
raw_bio: "valid html. a\nb\nc\nd\nf '&<>\""
|
||||
})
|
||||
|
||||
expected = %{
|
||||
|
|
|
|||
|
|
@ -15,8 +15,17 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, parent} = CommonAPI.post(user, %{status: "parent"})
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{status: "hey @#{other_user.nickname}", visibility: "direct"})
|
||||
CommonAPI.post(user, %{
|
||||
status: "hey @#{other_user.nickname}",
|
||||
visibility: "direct",
|
||||
in_reply_to_id: parent.id
|
||||
})
|
||||
|
||||
{:ok, _reply_activity} =
|
||||
CommonAPI.post(user, %{status: "hu", visibility: "public", in_reply_to_id: parent.id})
|
||||
|
||||
[participation] = Participation.for_user_with_last_activity_id(user)
|
||||
|
||||
|
|
|
|||
64
test/web/media_proxy/invalidation_test.exs
Normal file
64
test/web/media_proxy/invalidation_test.exs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Tesla.Mock
|
||||
|
||||
setup do: clear_config([:media_proxy])
|
||||
|
||||
setup do
|
||||
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
|
||||
end
|
||||
|
||||
describe "Invalidation.Http" do
|
||||
test "perform request to clear cache" do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], Invalidation.Http)
|
||||
|
||||
Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
|
||||
image_url = "http://example.com/media/example.jpg"
|
||||
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
||||
|
||||
mock(fn
|
||||
%{
|
||||
method: :purge,
|
||||
url: "http://example.com/media/example.jpg",
|
||||
headers: [{"x-refresh", 1}]
|
||||
} ->
|
||||
%Tesla.Env{status: 200}
|
||||
end)
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
||||
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
||||
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
||||
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Invalidation.Script" do
|
||||
test "run script to clear cache" do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], Invalidation.Script)
|
||||
Config.put([Invalidation.Script], script_path: "purge-nginx")
|
||||
|
||||
image_url = "http://example.com/media/example.jpg"
|
||||
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
||||
|
||||
with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
|
||||
assert capture_log(fn ->
|
||||
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
||||
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
||||
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
||||
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,10 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
|
||||
end
|
||||
|
||||
test "logs hasn't error message when request is valid" do
|
||||
mock(fn
|
||||
%{method: :purge, url: "http://example.com/media/example.jpg"} ->
|
||||
|
|
@ -14,8 +18,8 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
|
|||
refute capture_log(fn ->
|
||||
assert Invalidation.Http.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{}
|
||||
) == {:ok, "success"}
|
||||
[]
|
||||
) == {:ok, ["http://example.com/media/example.jpg"]}
|
||||
end) =~ "Error while cache purge"
|
||||
end
|
||||
|
||||
|
|
@ -28,8 +32,8 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
|
|||
assert capture_log(fn ->
|
||||
assert Invalidation.Http.purge(
|
||||
["http://example.com/media/example1.jpg"],
|
||||
%{}
|
||||
) == {:ok, "success"}
|
||||
[]
|
||||
) == {:ok, ["http://example.com/media/example1.jpg"]}
|
||||
end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,17 +4,23 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
|
|||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
setup do
|
||||
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
|
||||
end
|
||||
|
||||
test "it logger error when script not found" do
|
||||
assert capture_log(fn ->
|
||||
assert Invalidation.Script.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{script_path: "./example"}
|
||||
) == {:error, "\"%ErlangError{original: :enoent}\""}
|
||||
end) =~ "Error while cache purge: \"%ErlangError{original: :enoent}\""
|
||||
script_path: "./example"
|
||||
) == {:error, "%ErlangError{original: :enoent}"}
|
||||
end) =~ "Error while cache purge: %ErlangError{original: :enoent}"
|
||||
|
||||
assert Invalidation.Script.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{}
|
||||
) == {:error, "not found script path"}
|
||||
capture_log(fn ->
|
||||
assert Invalidation.Script.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
[]
|
||||
) == {:error, "\"not found script path\""}
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
setup do: clear_config(:media_proxy)
|
||||
setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base])
|
||||
|
||||
setup do
|
||||
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
|
||||
end
|
||||
|
||||
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
|
||||
|
|
@ -66,4 +70,16 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
assert %Plug.Conn{status: :success} = get(conn, url)
|
||||
end
|
||||
end
|
||||
|
||||
test "it returns 404 when url contains in banned_urls cache", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
|
||||
Pleroma.Web.MediaProxy.put_in_banned_urls("https://google.fn/test.png")
|
||||
|
||||
with_mock Pleroma.ReverseProxy,
|
||||
call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
|
||||
assert %Plug.Conn{status: 404, resp_body: "Not Found"} = get(conn, url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue