Merge remote-tracking branch 'remotes/origin/develop' into tests-clear-config-tweaks
# Conflicts: # test/web/admin_api/admin_api_controller_test.exs
This commit is contained in:
commit
226f4d5ef9
49 changed files with 371 additions and 211 deletions
|
|
@ -109,6 +109,10 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
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
|
||||
emoji = Application.get_env(:pleroma, :emoji)
|
||||
on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
|
||||
|
|
@ -125,7 +129,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
)
|
||||
end
|
||||
|
||||
test "restart pleroma on reboot time key" do
|
||||
test "on reboot time key" do
|
||||
chat = Application.get_env(:pleroma, :chat)
|
||||
on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
|
||||
|
||||
|
|
@ -138,7 +142,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
test "restart pleroma on reboot time subkey" do
|
||||
test "on reboot time subkey" do
|
||||
captcha = Application.get_env(:pleroma, Pleroma.Captcha)
|
||||
on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ConfigDB
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.ModerationLog
|
||||
|
|
@ -19,7 +23,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
alias Pleroma.Web.MediaProxy
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -41,7 +44,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
|
||||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
|
||||
|
|
@ -91,7 +94,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
|
||||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires " <>
|
||||
|
|
@ -579,11 +582,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
|
||||
clear_config([:instance, :invites_enabled]) do
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
end
|
||||
|
||||
test "sends invitation and returns 204", %{admin: admin, conn: conn} do
|
||||
|
|
@ -602,8 +605,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert token_record
|
||||
refute token_record.used
|
||||
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
email =
|
||||
Pleroma.Emails.UserEmail.user_invitation_email(
|
||||
|
|
@ -639,8 +642,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
clear_config([:instance, :invites_enabled])
|
||||
|
||||
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], false)
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
Config.put([:instance, :invites_enabled], false)
|
||||
|
||||
conn = post(conn, "/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD")
|
||||
|
||||
|
|
@ -648,8 +651,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "it returns 500 if `registrations_open` is enabled", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :registrations_open], true)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
Config.put([:instance, :registrations_open], true)
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
|
||||
conn = post(conn, "/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD")
|
||||
|
||||
|
|
@ -1886,11 +1889,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/config" do
|
||||
clear_config(:configurable_from_database) do
|
||||
Pleroma.Config.put(:configurable_from_database, true)
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
|
||||
test "when configuration from database is off", %{conn: conn} do
|
||||
Pleroma.Config.put(:configurable_from_database, false)
|
||||
Config.put(:configurable_from_database, false)
|
||||
conn = get(conn, "/api/pleroma/admin/config")
|
||||
|
||||
assert json_response(conn, 400) ==
|
||||
|
|
@ -2034,11 +2037,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
|
||||
Application.put_env(:pleroma, :http, http)
|
||||
Application.put_env(:tesla, :adapter, Tesla.Mock)
|
||||
Restarter.Pleroma.refresh()
|
||||
end)
|
||||
end
|
||||
|
||||
clear_config(:configurable_from_database) do
|
||||
Pleroma.Config.put(:configurable_from_database, true)
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
|
|
@ -2247,21 +2251,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "saving config which need pleroma reboot", %{conn: conn} do
|
||||
chat = Pleroma.Config.get(:chat)
|
||||
on_exit(fn -> Pleroma.Config.put(:chat, chat) end)
|
||||
chat = Config.get(:chat)
|
||||
on_exit(fn -> Config.put(:chat, chat) end)
|
||||
|
||||
conn =
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/admin/config",
|
||||
%{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert post(
|
||||
conn,
|
||||
"/api/pleroma/admin/config",
|
||||
%{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|> json_response(200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"db" => [":enabled"],
|
||||
|
|
@ -2272,6 +2274,80 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
],
|
||||
"need_reboot" => true
|
||||
}
|
||||
|
||||
configs =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/config")
|
||||
|> json_response(200)
|
||||
|
||||
assert configs["need_reboot"]
|
||||
|
||||
capture_log(fn ->
|
||||
assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
|
||||
end) =~ "pleroma restarted"
|
||||
|
||||
configs =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/config")
|
||||
|> json_response(200)
|
||||
|
||||
refute Map.has_key?(configs, "need_reboot")
|
||||
end
|
||||
|
||||
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
||||
chat = Config.get(:chat)
|
||||
on_exit(fn -> Config.put(:chat, chat) end)
|
||||
|
||||
assert post(
|
||||
conn,
|
||||
"/api/pleroma/admin/config",
|
||||
%{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|> json_response(200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"db" => [":enabled"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":chat",
|
||||
"value" => [%{"tuple" => [":enabled", true]}]
|
||||
}
|
||||
],
|
||||
"need_reboot" => true
|
||||
}
|
||||
|
||||
assert post(conn, "/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
|
||||
]
|
||||
})
|
||||
|> json_response(200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => ":pleroma",
|
||||
"key" => ":key1",
|
||||
"value" => [
|
||||
%{"tuple" => [":key3", 3]}
|
||||
],
|
||||
"db" => [":key3"]
|
||||
}
|
||||
],
|
||||
"need_reboot" => true
|
||||
}
|
||||
|
||||
capture_log(fn ->
|
||||
assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
|
||||
end) =~ "pleroma restarted"
|
||||
|
||||
configs =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/config")
|
||||
|> json_response(200)
|
||||
|
||||
refute Map.has_key?(configs, "need_reboot")
|
||||
end
|
||||
|
||||
test "saving config with nested merge", %{conn: conn} do
|
||||
|
|
@ -2408,7 +2484,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
{ExSyslogger, :ex_syslogger}
|
||||
]
|
||||
|
||||
ExUnit.CaptureLog.capture_log(fn ->
|
||||
capture_log(fn ->
|
||||
require Logger
|
||||
Logger.warn("Ooops...")
|
||||
end) =~ "Ooops..."
|
||||
|
|
@ -2541,7 +2617,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
})
|
||||
|
||||
assert Application.get_env(:tesla, :adapter) == Tesla.Adapter.Httpc
|
||||
assert Pleroma.Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
|
||||
assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"configs" => [
|
||||
|
|
@ -2977,13 +3053,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/restart" do
|
||||
clear_config(:configurable_from_database) do
|
||||
Pleroma.Config.put(:configurable_from_database, true)
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
|
||||
test "pleroma restarts", %{conn: conn} do
|
||||
ExUnit.CaptureLog.capture_log(fn ->
|
||||
capture_log(fn ->
|
||||
assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
|
||||
end) =~ "pleroma restarted"
|
||||
|
||||
refute Restarter.Pleroma.need_reboot?()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -491,7 +491,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
title: "Example website"
|
||||
}
|
||||
|
||||
%{provider_name: "Example site name"} =
|
||||
%{provider_name: "example.com"} =
|
||||
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
||||
end
|
||||
|
||||
|
|
@ -506,7 +506,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
description: "Example description"
|
||||
}
|
||||
|
||||
%{provider_name: "Example site name"} =
|
||||
%{provider_name: "example.com"} =
|
||||
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,11 +7,14 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
|||
alias Pleroma.Web.RichMedia.Parsers.TwitterCard
|
||||
|
||||
test "returns error when html not contains twitter card" do
|
||||
assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"}
|
||||
assert TwitterCard.parse([{"html", [], [{"head", [], []}, {"body", [], []}]}], %{}) ==
|
||||
{:error, "No twitter card metadata found"}
|
||||
end
|
||||
|
||||
test "parses twitter card with only name attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
|
||||
html =
|
||||
File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
|
||||
|> Floki.parse_document!()
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
|
|
@ -26,7 +29,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
|||
end
|
||||
|
||||
test "parses twitter card with only property attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
|
||||
html =
|
||||
File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
|
||||
|> Floki.parse_document!()
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
|
|
@ -45,7 +50,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
|||
end
|
||||
|
||||
test "parses twitter card with name & property attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
|
||||
html =
|
||||
File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
|
||||
|> Floki.parse_document!()
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
|
|
@ -73,7 +80,8 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
|||
"YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <>
|
||||
"yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg"
|
||||
|
||||
html = File.read!("test/fixtures/margaret-corbin-grave-west-point.html")
|
||||
html =
|
||||
File.read!("test/fixtures/margaret-corbin-grave-west-point.html") |> Floki.parse_document!()
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
|
|
@ -87,7 +95,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
|||
end
|
||||
|
||||
test "takes first founded title in html head if there is html markup error" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
|
||||
html =
|
||||
File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
|
||||
|> Floki.parse_document!()
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue