added test helpers to clear config after tests
This commit is contained in:
parent
49ae3191df
commit
a320358703
|
@ -5,14 +5,8 @@
|
||||||
defmodule Pleroma.Config.TransferTaskTest do
|
defmodule Pleroma.Config.TransferTaskTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
setup do
|
clear_config([:instance, :dynamic_configuration]) do
|
||||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "transfer config values from db to env" do
|
test "transfer config values from db to env" do
|
||||||
|
|
|
@ -11,14 +11,8 @@ defmodule Pleroma.ConversationTest do
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup_all do
|
clear_config_all([:instance, :federating]) do
|
||||||
config_path = [:instance, :federating]
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it goes through old direct conversations" do
|
test "it goes through old direct conversations" do
|
||||||
|
|
|
@ -15,11 +15,7 @@ defmodule Pleroma.Emails.MailerTest do
|
||||||
to: [{"Test User", "user1@example.com"}]
|
to: [{"Test User", "user1@example.com"}]
|
||||||
}
|
}
|
||||||
|
|
||||||
setup do
|
clear_config([Pleroma.Emails.Mailer, :enabled])
|
||||||
value = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
|
|
||||||
on_exit(fn -> Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], value) end)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "not send email when mailer is disabled" do
|
test "not send email when mailer is disabled" do
|
||||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||||
|
|
|
@ -4,21 +4,19 @@
|
||||||
|
|
||||||
defmodule Pleroma.HTTP.RequestBuilderTest do
|
defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
alias Pleroma.HTTP.RequestBuilder
|
alias Pleroma.HTTP.RequestBuilder
|
||||||
|
|
||||||
describe "headers/2" do
|
describe "headers/2" do
|
||||||
|
clear_config([:http, :send_user_agent])
|
||||||
|
|
||||||
test "don't send pleroma user agent" do
|
test "don't send pleroma user agent" do
|
||||||
assert RequestBuilder.headers(%{}, []) == %{headers: []}
|
assert RequestBuilder.headers(%{}, []) == %{headers: []}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "send pleroma user agent" do
|
test "send pleroma user agent" do
|
||||||
send = Pleroma.Config.get([:http, :send_user_agent])
|
|
||||||
Pleroma.Config.put([:http, :send_user_agent], true)
|
Pleroma.Config.put([:http, :send_user_agent], true)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:http, :send_user_agent], send)
|
|
||||||
end)
|
|
||||||
|
|
||||||
assert RequestBuilder.headers(%{}, []) == %{
|
assert RequestBuilder.headers(%{}, []) == %{
|
||||||
headers: [{"User-Agent", Pleroma.Application.user_agent()}]
|
headers: [{"User-Agent", Pleroma.Application.user_agent()}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,32 +159,28 @@ test "it can refetch pruned objects" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "signed fetches" do
|
describe "signed fetches" do
|
||||||
|
clear_config([:activitypub, :sign_object_fetches])
|
||||||
|
|
||||||
test_with_mock "it signs fetches when configured to do so",
|
test_with_mock "it signs fetches when configured to do so",
|
||||||
Pleroma.Signature,
|
Pleroma.Signature,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
|
|
||||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
|
Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
|
||||||
|
|
||||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||||
|
|
||||||
assert called(Pleroma.Signature.sign(:_, :_))
|
assert called(Pleroma.Signature.sign(:_, :_))
|
||||||
|
|
||||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test_with_mock "it doesn't sign fetches when not configured to do so",
|
test_with_mock "it doesn't sign fetches when not configured to do so",
|
||||||
Pleroma.Signature,
|
Pleroma.Signature,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
|
|
||||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
|
Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
|
||||||
|
|
||||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||||
|
|
||||||
refute called(Pleroma.Signature.sign(:_, :_))
|
refute called(Pleroma.Signature.sign(:_, :_))
|
||||||
|
|
||||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,10 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
||||||
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
|
clear_config([:instance, :public])
|
||||||
|
|
||||||
test "it halts if not public and no user is assigned", %{conn: conn} do
|
test "it halts if not public and no user is assigned", %{conn: conn} do
|
||||||
set_public_to(false)
|
Config.put([:instance, :public], false)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -21,7 +23,7 @@ test "it halts if not public and no user is assigned", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it continues if public", %{conn: conn} do
|
test "it continues if public", %{conn: conn} do
|
||||||
set_public_to(true)
|
Config.put([:instance, :public], true)
|
||||||
|
|
||||||
ret_conn =
|
ret_conn =
|
||||||
conn
|
conn
|
||||||
|
@ -31,7 +33,7 @@ test "it continues if public", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
||||||
set_public_to(false)
|
Config.put([:instance, :public], false)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -43,13 +45,4 @@ test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
||||||
|
|
||||||
assert ret_conn == conn
|
assert ret_conn == conn
|
||||||
end
|
end
|
||||||
|
|
||||||
defp set_public_to(value) do
|
|
||||||
orig = Config.get!([:instance, :public])
|
|
||||||
Config.put([:instance, :public], value)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([:instance, :public], orig)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,17 +7,12 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Plug.Conn
|
alias Plug.Conn
|
||||||
|
|
||||||
|
clear_config([:http_securiy, :enabled])
|
||||||
|
clear_config([:http_security, :sts])
|
||||||
|
|
||||||
describe "http security enabled" do
|
describe "http security enabled" do
|
||||||
setup do
|
setup do
|
||||||
enabled = Config.get([:http_securiy, :enabled])
|
|
||||||
|
|
||||||
Config.put([:http_security, :enabled], true)
|
Config.put([:http_security, :enabled], true)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([:http_security, :enabled], enabled)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it sends CSP headers when enabled", %{conn: conn} do
|
test "it sends CSP headers when enabled", %{conn: conn} do
|
||||||
|
@ -81,14 +76,8 @@ test "it sends `report-to` & `report-uri` CSP response headers" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not send CSP headers when disabled", %{conn: conn} do
|
test "it does not send CSP headers when disabled", %{conn: conn} do
|
||||||
enabled = Config.get([:http_securiy, :enabled])
|
|
||||||
|
|
||||||
Config.put([:http_security, :enabled], false)
|
Config.put([:http_security, :enabled], false)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([:http_security, :enabled], enabled)
|
|
||||||
end)
|
|
||||||
|
|
||||||
conn = get(conn, "/api/v1/instance")
|
conn = get(conn, "/api/v1/instance")
|
||||||
|
|
||||||
assert Conn.get_resp_header(conn, "x-xss-protection") == []
|
assert Conn.get_resp_header(conn, "x-xss-protection") == []
|
||||||
|
|
|
@ -8,14 +8,12 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
||||||
@dir "test/tmp/instance_static"
|
@dir "test/tmp/instance_static"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
|
||||||
Pleroma.Config.put([:instance, :static_dir], @dir)
|
|
||||||
File.mkdir_p!(@dir)
|
File.mkdir_p!(@dir)
|
||||||
|
on_exit(fn -> File.rm_rf(@dir) end)
|
||||||
|
end
|
||||||
|
|
||||||
on_exit(fn ->
|
clear_config([:instance, :static_dir]) do
|
||||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
Pleroma.Config.put([:instance, :static_dir], @dir)
|
||||||
File.rm_rf(@dir)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "overrides index" do
|
test "overrides index" do
|
||||||
|
|
|
@ -7,8 +7,52 @@ defmodule Pleroma.Tests.Helpers do
|
||||||
Helpers for use in tests.
|
Helpers for use in tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
defmacro clear_config(config_path) do
|
||||||
|
quote do
|
||||||
|
clear_config(unquote(config_path)) do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defmacro clear_config(config_path, do: yield) do
|
||||||
|
quote do
|
||||||
|
setup do
|
||||||
|
initial_setting = Pleroma.Config.get(unquote(config_path))
|
||||||
|
unquote(yield)
|
||||||
|
on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defmacro clear_config_all(config_path) do
|
||||||
|
quote do
|
||||||
|
clear_config_all(unquote(config_path)) do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defmacro clear_config_all(config_path, do: yield) do
|
||||||
|
quote do
|
||||||
|
setup_all do
|
||||||
|
initial_setting = Pleroma.Config.get(unquote(config_path))
|
||||||
|
unquote(yield)
|
||||||
|
on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defmacro __using__(_opts) do
|
defmacro __using__(_opts) do
|
||||||
quote do
|
quote do
|
||||||
|
import Pleroma.Tests.Helpers,
|
||||||
|
only: [
|
||||||
|
clear_config: 1,
|
||||||
|
clear_config: 2,
|
||||||
|
clear_config_all: 1,
|
||||||
|
clear_config_all: 2
|
||||||
|
]
|
||||||
|
|
||||||
def collect_ids(collection) do
|
def collect_ids(collection) do
|
||||||
collection
|
collection
|
||||||
|> Enum.map(& &1.id)
|
|> Enum.map(& &1.id)
|
||||||
|
@ -30,6 +74,15 @@ def render_json(view, template, assigns) do
|
||||||
|> Poison.encode!()
|
|> Poison.encode!()
|
||||||
|> Poison.decode!()
|
|> Poison.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmacro guards_config(config_path) do
|
||||||
|
quote do
|
||||||
|
initial_setting = Pleroma.Config.get(config_path)
|
||||||
|
|
||||||
|
Pleroma.Config.put(config_path, true)
|
||||||
|
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,21 +11,20 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
||||||
Mix.shell(Mix.Shell.Process)
|
Mix.shell(Mix.Shell.Process)
|
||||||
temp_file = "config/temp.exported_from_db.secret.exs"
|
temp_file = "config/temp.exported_from_db.secret.exs"
|
||||||
|
|
||||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Mix.shell(Mix.Shell.IO)
|
Mix.shell(Mix.Shell.IO)
|
||||||
Application.delete_env(:pleroma, :first_setting)
|
Application.delete_env(:pleroma, :first_setting)
|
||||||
Application.delete_env(:pleroma, :second_setting)
|
Application.delete_env(:pleroma, :second_setting)
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
|
||||||
:ok = File.rm(temp_file)
|
:ok = File.rm(temp_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, temp_file: temp_file}
|
{:ok, temp_file: temp_file}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config_all([:instance, :dynamic_configuration]) do
|
||||||
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "settings are migrated to db" do
|
test "settings are migrated to db" do
|
||||||
assert Repo.all(Config) == []
|
assert Repo.all(Config) == []
|
||||||
|
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
|
|
||||||
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
alias Mix.Tasks.Pleroma.RobotsTxt
|
alias Mix.Tasks.Pleroma.RobotsTxt
|
||||||
|
|
||||||
|
clear_config([:instance, :static_dir])
|
||||||
|
|
||||||
test "creates new dir" do
|
test "creates new dir" do
|
||||||
path = "test/fixtures/new_dir/"
|
path = "test/fixtures/new_dir/"
|
||||||
file_path = path <> "robots.txt"
|
file_path = path <> "robots.txt"
|
||||||
|
|
||||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
|
||||||
Pleroma.Config.put([:instance, :static_dir], path)
|
Pleroma.Config.put([:instance, :static_dir], path)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
|
||||||
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
|
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -29,11 +29,9 @@ test "creates new dir" do
|
||||||
test "to existance folder" do
|
test "to existance folder" do
|
||||||
path = "test/fixtures/"
|
path = "test/fixtures/"
|
||||||
file_path = path <> "robots.txt"
|
file_path = path <> "robots.txt"
|
||||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
|
||||||
Pleroma.Config.put([:instance, :static_dir], path)
|
Pleroma.Config.put([:instance, :static_dir], path)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
|
||||||
:ok = File.rm(file_path)
|
:ok = File.rm(file_path)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,6 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
custom_filename = Config.get([Upload.Filter.AnonymizeFilename, :text])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([Upload.Filter.AnonymizeFilename, :text], custom_filename)
|
|
||||||
end)
|
|
||||||
|
|
||||||
upload_file = %Upload{
|
upload_file = %Upload{
|
||||||
name: "an… image.jpg",
|
name: "an… image.jpg",
|
||||||
content_type: "image/jpg",
|
content_type: "image/jpg",
|
||||||
|
@ -24,6 +18,8 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
||||||
%{upload_file: upload_file}
|
%{upload_file: upload_file}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
||||||
|
|
||||||
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
|
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
|
||||||
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
||||||
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||||
|
|
|
@ -10,13 +10,7 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
alias Pleroma.Upload.Filter
|
alias Pleroma.Upload.Filter
|
||||||
|
|
||||||
setup do
|
clear_config([Filter.Mogrify, :args])
|
||||||
filter = Config.get([Filter.Mogrify, :args])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([Filter.Mogrify, :args], filter)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "apply mogrify filter" do
|
test "apply mogrify filter" do
|
||||||
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
|
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
|
||||||
|
|
|
@ -8,13 +8,7 @@ defmodule Pleroma.Upload.FilterTest do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Upload.Filter
|
alias Pleroma.Upload.Filter
|
||||||
|
|
||||||
setup do
|
clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
||||||
custom_filename = Config.get([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], custom_filename)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "applies filters" do
|
test "applies filters" do
|
||||||
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
||||||
|
|
|
@ -250,12 +250,8 @@ test "escapes reserved uri characters" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Setting a custom base_url for uploaded media" do
|
describe "Setting a custom base_url for uploaded media" do
|
||||||
setup do
|
clear_config([Pleroma.Upload, :base_url]) do
|
||||||
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([Pleroma.Upload, :base_url], nil)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns a media url with configured base_url" do
|
test "returns a media url with configured base_url" do
|
||||||
|
|
|
@ -11,19 +11,11 @@ defmodule Pleroma.Uploaders.S3Test do
|
||||||
import Mock
|
import Mock
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
|
||||||
setup do
|
clear_config([Pleroma.Uploaders.S3]) do
|
||||||
config = Config.get([Pleroma.Uploaders.S3])
|
|
||||||
|
|
||||||
Config.put([Pleroma.Uploaders.S3],
|
Config.put([Pleroma.Uploaders.S3],
|
||||||
bucket: "test_bucket",
|
bucket: "test_bucket",
|
||||||
public_endpoint: "https://s3.amazonaws.com"
|
public_endpoint: "https://s3.amazonaws.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([Pleroma.Uploaders.S3], config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "get_file/1" do
|
describe "get_file/1" do
|
||||||
|
|
|
@ -21,6 +21,8 @@ defmodule Pleroma.UserTest do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :account_activation_required])
|
||||||
|
|
||||||
describe "when tags are nil" do
|
describe "when tags are nil" do
|
||||||
test "tagging a user" do
|
test "tagging a user" do
|
||||||
user = insert(:user, %{tags: nil})
|
user = insert(:user, %{tags: nil})
|
||||||
|
@ -287,6 +289,9 @@ test "fetches correct profile for nickname beginning with number" do
|
||||||
password_confirmation: "test",
|
password_confirmation: "test",
|
||||||
email: "email@example.com"
|
email: "email@example.com"
|
||||||
}
|
}
|
||||||
|
clear_config([:instance, :autofollowed_nicknames])
|
||||||
|
clear_config([:instance, :welcome_message])
|
||||||
|
clear_config([:instance, :welcome_user_nickname])
|
||||||
|
|
||||||
test "it autofollows accounts that are set for it" do
|
test "it autofollows accounts that are set for it" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -303,8 +308,6 @@ test "it autofollows accounts that are set for it" do
|
||||||
|
|
||||||
assert User.following?(registered_user, user)
|
assert User.following?(registered_user, user)
|
||||||
refute User.following?(registered_user, remote_user)
|
refute User.following?(registered_user, remote_user)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it sends a welcome message if it is set" do
|
test "it sends a welcome message if it is set" do
|
||||||
|
@ -320,9 +323,6 @@ test "it sends a welcome message if it is set" do
|
||||||
assert registered_user.ap_id in activity.recipients
|
assert registered_user.ap_id in activity.recipients
|
||||||
assert Object.normalize(activity).data["content"] =~ "cool site"
|
assert Object.normalize(activity).data["content"] =~ "cool site"
|
||||||
assert activity.actor == welcome_user.ap_id
|
assert activity.actor == welcome_user.ap_id
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
|
|
||||||
Pleroma.Config.put([:instance, :welcome_message], nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it requires an email, name, nickname and password, bio is optional" do
|
test "it requires an email, name, nickname and password, bio is optional" do
|
||||||
|
@ -388,15 +388,8 @@ test "it ensures info is not nil" do
|
||||||
email: "email@example.com"
|
email: "email@example.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup do
|
clear_config([:instance, :account_activation_required]) do
|
||||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
|
||||||
|
|
||||||
unless setting do
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it creates unconfirmed user" do
|
test "it creates unconfirmed user" do
|
||||||
|
@ -1043,6 +1036,8 @@ test "hide a user's statuses from timelines and notifications" do
|
||||||
[user: user]
|
[user: user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :federating])
|
||||||
|
|
||||||
test ".delete_user_activities deletes all create activities", %{user: user} do
|
test ".delete_user_activities deletes all create activities", %{user: user} do
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||||
|
|
||||||
|
@ -1093,9 +1088,7 @@ test "it deletes a user, all follow relationships and all activities", %{user: u
|
||||||
Pleroma.Web.ActivityPub.Publisher,
|
Pleroma.Web.ActivityPub.Publisher,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
config_path = [:instance, :federating]
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
|
|
||||||
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||||
{:ok, _} = User.follow(follower, user)
|
{:ok, _} = User.follow(follower, user)
|
||||||
|
@ -1107,8 +1100,6 @@ test "it deletes a user, all follow relationships and all activities", %{user: u
|
||||||
inbox: "http://mastodon.example.org/inbox"
|
inbox: "http://mastodon.example.org/inbox"
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, initial_setting)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1174,8 +1165,6 @@ test "auth_active?/1 works correctly" do
|
||||||
refute User.auth_active?(local_user)
|
refute User.auth_active?(local_user)
|
||||||
assert User.auth_active?(confirmed_user)
|
assert User.auth_active?(confirmed_user)
|
||||||
assert User.auth_active?(remote_user)
|
assert User.auth_active?(remote_user)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "superuser?/1" do
|
describe "superuser?/1" do
|
||||||
|
@ -1220,8 +1209,6 @@ test "returns false when the account is unauthenticated and auth is required" do
|
||||||
other_user = insert(:user, local: true)
|
other_user = insert(:user, local: true)
|
||||||
|
|
||||||
refute User.visible_for?(user, other_user)
|
refute User.visible_for?(user, other_user)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns true when the account is unauthenticated and auth is not required" do
|
test "returns true when the account is unauthenticated and auth is not required" do
|
||||||
|
@ -1238,8 +1225,6 @@ test "returns true when the account is unauthenticated and being viewed by a pri
|
||||||
other_user = insert(:user, local: true, info: %{is_admin: true})
|
other_user = insert(:user, local: true, info: %{is_admin: true})
|
||||||
|
|
||||||
assert User.visible_for?(user, other_user)
|
assert User.visible_for?(user, other_user)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1552,10 +1537,7 @@ test "performs update cache if user updated" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "following/followers synchronization" do
|
describe "following/followers synchronization" do
|
||||||
setup do
|
clear_config([:instance, :external_user_synchronization])
|
||||||
sync = Pleroma.Config.get([:instance, :external_user_synchronization])
|
|
||||||
on_exit(fn -> Pleroma.Config.put([:instance, :external_user_synchronization], sync) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "updates the counters normally on following/getting a follow when disabled" do
|
test "updates the counters normally on following/getting a follow when disabled" do
|
||||||
Pleroma.Config.put([:instance, :external_user_synchronization], false)
|
Pleroma.Config.put([:instance, :external_user_synchronization], false)
|
||||||
|
|
|
@ -16,17 +16,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
config_path = [:instance, :federating]
|
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config_all([:instance, :federating],
|
||||||
|
do: Pleroma.Config.put([:instance, :federating], true)
|
||||||
|
)
|
||||||
|
|
||||||
describe "/relay" do
|
describe "/relay" do
|
||||||
|
clear_config([:instance, :allow_relay])
|
||||||
|
|
||||||
test "with the relay active, it returns the relay user", %{conn: conn} do
|
test "with the relay active, it returns the relay user", %{conn: conn} do
|
||||||
res =
|
res =
|
||||||
conn
|
conn
|
||||||
|
@ -43,8 +42,6 @@ test "with the relay disabled, it returns 404", %{conn: conn} do
|
||||||
|> get(activity_pub_path(conn, :relay))
|
|> get(activity_pub_path(conn, :relay))
|
||||||
|> json_response(404)
|
|> json_response(404)
|
||||||
|> assert
|
|> assert
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :allow_relay], true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
test "subdomains_regex/1" do
|
test "subdomains_regex/1" do
|
||||||
|
@ -59,6 +60,8 @@ test "matches are case-insensitive" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "describe/0" do
|
describe "describe/0" do
|
||||||
|
clear_config([:instance, :rewrite_policy])
|
||||||
|
|
||||||
test "it works as expected with noop policy" do
|
test "it works as expected with noop policy" do
|
||||||
expected = %{
|
expected = %{
|
||||||
mrf_policies: ["NoOpPolicy"],
|
mrf_policies: ["NoOpPolicy"],
|
||||||
|
@ -69,7 +72,6 @@ test "it works as expected with noop policy" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it works as expected with mock policy" do
|
test "it works as expected with mock policy" do
|
||||||
config = Pleroma.Config.get([:instance, :rewrite_policy])
|
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
|
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
|
@ -79,8 +81,6 @@ test "it works as expected with mock policy" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, ^expected} = MRF.describe()
|
{:ok, ^expected} = MRF.describe()
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], config)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,12 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
|
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
|
||||||
|
|
||||||
setup do
|
clear_config([:mrf_rejectnonpublic])
|
||||||
policy = Pleroma.Config.get([:mrf_rejectnonpublic])
|
|
||||||
on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "public message" do
|
describe "public message" do
|
||||||
test "it's allowed when address is public" do
|
test "it's allowed when address is public" do
|
||||||
|
|
|
@ -8,9 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||||
|
|
||||||
setup do
|
clear_config([:mrf_simple]) do
|
||||||
orig = Config.get!(:mrf_simple)
|
|
||||||
|
|
||||||
Config.put(:mrf_simple,
|
Config.put(:mrf_simple,
|
||||||
media_removal: [],
|
media_removal: [],
|
||||||
media_nsfw: [],
|
media_nsfw: [],
|
||||||
|
@ -21,10 +19,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
||||||
avatar_removal: [],
|
avatar_removal: [],
|
||||||
banner_removal: []
|
banner_removal: []
|
||||||
)
|
)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put(:mrf_simple, orig)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when :media_removal" do
|
describe "when :media_removal" do
|
||||||
|
|
|
@ -7,12 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
|
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
|
||||||
|
|
||||||
setup do
|
clear_config([:mrf_user_allowlist, :localhost])
|
||||||
policy = Pleroma.Config.get([:mrf_user_allowlist]) || []
|
|
||||||
on_exit(fn -> Pleroma.Config.put([:mrf_user_allowlist], policy) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "pass filter if allow list is empty" do
|
test "pass filter if allow list is empty" do
|
||||||
actor = insert(:user)
|
actor = insert(:user)
|
||||||
|
|
|
@ -8,8 +8,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
||||||
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
|
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
|
||||||
|
|
||||||
describe "accept" do
|
describe "accept" do
|
||||||
|
clear_config([:mrf_vocabulary, :accept])
|
||||||
|
|
||||||
test "it accepts based on parent activity type" do
|
test "it accepts based on parent activity type" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :accept])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
|
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -18,12 +19,9 @@ test "it accepts based on parent activity type" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it accepts based on child object type" do
|
test "it accepts based on child object type" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :accept])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -35,12 +33,9 @@ test "it accepts based on child object type" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not accept disallowed child objects" do
|
test "it does not accept disallowed child objects" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :accept])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -52,12 +47,9 @@ test "it does not accept disallowed child objects" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not accept disallowed parent types" do
|
test "it does not accept disallowed parent types" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :accept])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -69,14 +61,13 @@ test "it does not accept disallowed parent types" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :accept], config)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "reject" do
|
describe "reject" do
|
||||||
|
clear_config([:mrf_vocabulary, :reject])
|
||||||
|
|
||||||
test "it rejects based on parent activity type" do
|
test "it rejects based on parent activity type" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :reject])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -85,12 +76,9 @@ test "it rejects based on parent activity type" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it rejects based on child object type" do
|
test "it rejects based on child object type" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :reject])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
|
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -102,12 +90,9 @@ test "it rejects based on child object type" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it passes through objects that aren't disallowed" do
|
test "it passes through objects that aren't disallowed" do
|
||||||
config = Pleroma.Config.get([:mrf_vocabulary, :reject])
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||||
|
|
||||||
message = %{
|
message = %{
|
||||||
|
@ -116,8 +101,6 @@ test "it passes through objects that aren't disallowed" do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||||
|
|
||||||
Pleroma.Config.put([:mrf_vocabulary, :reject], config)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -294,20 +294,17 @@ test "returns 403 when requested by a non-admin", %{conn: conn} do
|
||||||
|
|
||||||
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
||||||
setup do
|
setup do
|
||||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
|
||||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
|
||||||
:ok
|
|
||||||
end)
|
|
||||||
|
|
||||||
[user: insert(:user, info: %{is_admin: true})]
|
[user: insert(:user, info: %{is_admin: true})]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :registrations_open]) do
|
||||||
|
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||||
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :invites_enabled]) do
|
||||||
|
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "sends invitation and returns 204", %{conn: conn, user: user} do
|
test "sends invitation and returns 204", %{conn: conn, user: user} do
|
||||||
recipient_email = "foo@bar.com"
|
recipient_email = "foo@bar.com"
|
||||||
recipient_name = "J. D."
|
recipient_name = "J. D."
|
||||||
|
@ -360,18 +357,13 @@ test "it returns 403 if requested by a non-admin", %{conn: conn} do
|
||||||
[user: insert(:user, info: %{is_admin: true})]
|
[user: insert(:user, info: %{is_admin: true})]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :registrations_open])
|
||||||
|
clear_config([:instance, :invites_enabled])
|
||||||
|
|
||||||
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
|
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
|
||||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
|
||||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], false)
|
Pleroma.Config.put([:instance, :invites_enabled], false)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
|
||||||
:ok
|
|
||||||
end)
|
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|
@ -381,17 +373,9 @@ test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: u
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
|
test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
|
||||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
|
||||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], true)
|
Pleroma.Config.put([:instance, :registrations_open], true)
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
|
||||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
|
||||||
:ok
|
|
||||||
end)
|
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|
@ -1402,17 +1386,13 @@ test "with settings in db", %{conn: conn} do
|
||||||
:ok = File.rm(temp_file)
|
:ok = File.rm(temp_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
|
||||||
end)
|
|
||||||
|
|
||||||
%{conn: assign(conn, :user, admin)}
|
%{conn: assign(conn, :user, admin)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :dynamic_configuration]) do
|
||||||
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "create new config setting in db", %{conn: conn} do
|
test "create new config setting in db", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
post(conn, "/api/pleroma/admin/config", %{
|
||||||
|
@ -1961,17 +1941,13 @@ test "delete part of settings by atom subkeys", %{conn: conn} do
|
||||||
:ok = File.rm(temp_file)
|
:ok = File.rm(temp_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
|
||||||
end)
|
|
||||||
|
|
||||||
%{conn: assign(conn, :user, admin), admin: admin}
|
%{conn: assign(conn, :user, admin), admin: admin}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :dynamic_configuration]) do
|
||||||
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
|
test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
|
||||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||||
conn = get(conn, "/api/pleroma/admin/config/migrate_to_db")
|
conn = get(conn, "/api/pleroma/admin/config/migrate_to_db")
|
||||||
|
|
|
@ -14,6 +14,10 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
clear_config([:instance, :safe_dm_mentions])
|
||||||
|
clear_config([:instance, :limit])
|
||||||
|
clear_config([:instance, :max_pinned_statuses])
|
||||||
|
|
||||||
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||||
|
@ -61,7 +65,6 @@ test "with the safe_dm_mention option set, it does not mention people beyond the
|
||||||
har = insert(:user)
|
har = insert(:user)
|
||||||
jafnhar = insert(:user)
|
jafnhar = insert(:user)
|
||||||
tridi = insert(:user)
|
tridi = insert(:user)
|
||||||
option = Pleroma.Config.get([:instance, :safe_dm_mentions])
|
|
||||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
|
@ -72,7 +75,6 @@ test "with the safe_dm_mention option set, it does not mention people beyond the
|
||||||
|
|
||||||
refute tridi.ap_id in activity.recipients
|
refute tridi.ap_id in activity.recipients
|
||||||
assert jafnhar.ap_id in activity.recipients
|
assert jafnhar.ap_id in activity.recipients
|
||||||
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it de-duplicates tags" do
|
test "it de-duplicates tags" do
|
||||||
|
@ -195,15 +197,12 @@ test "it returns error when status is empty and no attachments" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns error when character limit is exceeded" do
|
test "it returns error when character limit is exceeded" do
|
||||||
limit = Pleroma.Config.get([:instance, :limit])
|
|
||||||
Pleroma.Config.put([:instance, :limit], 5)
|
Pleroma.Config.put([:instance, :limit], 5)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
assert {:error, "The status is over the character limit"} =
|
assert {:error, "The status is over the character limit"} =
|
||||||
CommonAPI.post(user, %{"status" => "foobar"})
|
CommonAPI.post(user, %{"status" => "foobar"})
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :limit], limit)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,17 @@ defmodule Pleroma.Web.FederatorTest do
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
config_path = [:instance, :federating]
|
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config_all([:instance, :federating]) do
|
||||||
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :allow_relay])
|
||||||
|
clear_config([:instance, :rewrite_policy])
|
||||||
|
clear_config([:mrf_keyword])
|
||||||
|
|
||||||
describe "Publisher.perform" do
|
describe "Publisher.perform" do
|
||||||
test "call `perform` with unknown task" do
|
test "call `perform` with unknown task" do
|
||||||
assert {
|
assert {
|
||||||
|
@ -67,8 +69,6 @@ test "with relays deactivated, it does not publish to the relay", %{
|
||||||
end
|
end
|
||||||
|
|
||||||
refute_received :relay_publish
|
refute_received :relay_publish
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :allow_relay], true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -231,19 +231,18 @@ test "rejects incoming AP docs with incorrect origin" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not crash if MRF rejects the post" do
|
test "it does not crash if MRF rejects the post" do
|
||||||
policies = Pleroma.Config.get([:instance, :rewrite_policy])
|
|
||||||
mrf_keyword_policy = Pleroma.Config.get(:mrf_keyword)
|
|
||||||
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
|
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.KeywordPolicy)
|
|
||||||
|
Pleroma.Config.put(
|
||||||
|
[:instance, :rewrite_policy],
|
||||||
|
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
|
||||||
|
)
|
||||||
|
|
||||||
params =
|
params =
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||||
|> Poison.decode!()
|
|> Poison.decode!()
|
||||||
|
|
||||||
assert Federator.incoming_ap_doc(params) == :error
|
assert Federator.incoming_ap_doc(params) == :error
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], policies)
|
|
||||||
Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,14 +10,8 @@ defmodule Pleroma.Instances.InstanceTest do
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup_all do
|
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||||
config_path = [:instance, :federation_reachability_timeout_days]
|
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, 1)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "set_reachable/1" do
|
describe "set_reachable/1" do
|
||||||
|
|
|
@ -7,14 +7,8 @@ defmodule Pleroma.InstancesTest do
|
||||||
|
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
setup_all do
|
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||||
config_path = [:instance, :federation_reachability_timeout_days]
|
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, 1)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "reachable?/1" do
|
describe "reachable?/1" do
|
||||||
|
|
|
@ -33,6 +33,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :public])
|
||||||
|
clear_config([:rich_media, :enabled])
|
||||||
|
|
||||||
test "the home timeline", %{conn: conn} do
|
test "the home timeline", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
following = insert(:user)
|
following = insert(:user)
|
||||||
|
@ -86,13 +89,8 @@ test "the public timeline", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "the public timeline when public is set to false", %{conn: conn} do
|
test "the public timeline when public is set to false", %{conn: conn} do
|
||||||
public = Config.get([:instance, :public])
|
|
||||||
Config.put([:instance, :public], false)
|
Config.put([:instance, :public], false)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([:instance, :public], public)
|
|
||||||
end)
|
|
||||||
|
|
||||||
assert conn
|
assert conn
|
||||||
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
||||||
|> json_response(403) == %{"error" => "This resource requires authentication."}
|
|> json_response(403) == %{"error" => "This resource requires authentication."}
|
||||||
|
@ -261,7 +259,6 @@ test "posting a status with OGP link preview", %{conn: conn} do
|
||||||
|
|
||||||
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
|
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
|
||||||
assert Activity.get_by_id(id)
|
assert Activity.get_by_id(id)
|
||||||
Config.put([:rich_media, :enabled], false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "posting a direct status", %{conn: conn} do
|
test "posting a direct status", %{conn: conn} do
|
||||||
|
@ -1634,14 +1631,6 @@ test "returns the relationships for the current user", %{conn: conn} do
|
||||||
|
|
||||||
describe "media upload" do
|
describe "media upload" do
|
||||||
setup do
|
setup do
|
||||||
upload_config = Config.get([Pleroma.Upload])
|
|
||||||
proxy_config = Config.get([:media_proxy])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([Pleroma.Upload], upload_config)
|
|
||||||
Config.put([:media_proxy], proxy_config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
|
@ -1657,6 +1646,9 @@ test "returns the relationships for the current user", %{conn: conn} do
|
||||||
[conn: conn, image: image]
|
[conn: conn, image: image]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:media_proxy])
|
||||||
|
clear_config([Pleroma.Upload])
|
||||||
|
|
||||||
test "returns uploaded image", %{conn: conn, image: image} do
|
test "returns uploaded image", %{conn: conn, image: image} do
|
||||||
desc = "Description of the image"
|
desc = "Description of the image"
|
||||||
|
|
||||||
|
@ -2667,14 +2659,16 @@ test "put settings", %{conn: conn} do
|
||||||
|
|
||||||
describe "pinned statuses" do
|
describe "pinned statuses" do
|
||||||
setup do
|
setup do
|
||||||
Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||||
|
|
||||||
[user: user, activity: activity]
|
[user: user, activity: activity]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :max_pinned_statuses]) do
|
||||||
|
Config.put([:instance, :max_pinned_statuses], 1)
|
||||||
|
end
|
||||||
|
|
||||||
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
|
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
|
||||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||||
|
|
||||||
|
@ -2769,10 +2763,6 @@ test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
|
||||||
setup do
|
setup do
|
||||||
Config.put([:rich_media, :enabled], true)
|
Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Config.put([:rich_media, :enabled], false)
|
|
||||||
end)
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
%{user: user}
|
%{user: user}
|
||||||
end
|
end
|
||||||
|
@ -3127,15 +3117,12 @@ test "redirects not logged-in users to the login page on private instances", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
path: path
|
path: path
|
||||||
} do
|
} do
|
||||||
is_public = Config.get([:instance, :public])
|
|
||||||
Config.put([:instance, :public], false)
|
Config.put([:instance, :public], false)
|
||||||
|
|
||||||
conn = get(conn, path)
|
conn = get(conn, path)
|
||||||
|
|
||||||
assert conn.status == 302
|
assert conn.status == 302
|
||||||
assert redirected_to(conn) == "/web/login"
|
assert redirected_to(conn) == "/web/login"
|
||||||
|
|
||||||
Config.put([:instance, :public], is_public)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||||
|
@ -3910,13 +3897,6 @@ test "it returns 400 when user is not local", %{conn: conn, user: user} do
|
||||||
|
|
||||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||||
setup do
|
setup do
|
||||||
setting = Config.get([:instance, :account_activation_required])
|
|
||||||
|
|
||||||
unless setting do
|
|
||||||
Config.put([:instance, :account_activation_required], true)
|
|
||||||
on_exit(fn -> Config.put([:instance, :account_activation_required], setting) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||||
|
|
||||||
|
@ -3931,6 +3911,10 @@ test "it returns 400 when user is not local", %{conn: conn, user: user} do
|
||||||
[user: user]
|
[user: user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :account_activation_required]) do
|
||||||
|
Config.put([:instance, :account_activation_required], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "resend account confirmation email", %{conn: conn, user: user} do
|
test "resend account confirmation email", %{conn: conn, user: user} do
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|
@ -3953,9 +3937,6 @@ test "resend account confirmation email", %{conn: conn, user: user} do
|
||||||
setup do
|
setup do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
config = Config.get(:suggestions)
|
|
||||||
on_exit(fn -> Config.put(:suggestions, config) end)
|
|
||||||
|
|
||||||
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
|
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||||
url500 = "http://test500?#{host}&#{user.nickname}"
|
url500 = "http://test500?#{host}&#{user.nickname}"
|
||||||
url200 = "http://test200?#{host}&#{user.nickname}"
|
url200 = "http://test200?#{host}&#{user.nickname}"
|
||||||
|
@ -3977,6 +3958,8 @@ test "resend account confirmation email", %{conn: conn, user: user} do
|
||||||
[user: user, other_user: other_user]
|
[user: user, other_user: other_user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config(:suggestions)
|
||||||
|
|
||||||
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
|
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
|
||||||
Config.put([:suggestions, :enabled], false)
|
Config.put([:suggestions, :enabled], false)
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,11 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.MediaProxyTest do
|
defmodule Pleroma.Web.MediaProxyTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
import Pleroma.Web.MediaProxy
|
import Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Web.MediaProxy.MediaProxyController
|
alias Pleroma.Web.MediaProxy.MediaProxyController
|
||||||
|
|
||||||
setup do
|
clear_config([:media_proxy, :enabled])
|
||||||
enabled = Pleroma.Config.get([:media_proxy, :enabled])
|
|
||||||
on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "when enabled" do
|
describe "when enabled" do
|
||||||
setup do
|
setup do
|
||||||
|
|
|
@ -12,21 +12,12 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
||||||
|
|
||||||
@skip if !Code.ensure_loaded?(:eldap), do: :skip
|
@skip if !Code.ensure_loaded?(:eldap), do: :skip
|
||||||
|
|
||||||
setup_all do
|
clear_config_all([:ldap, :enabled]) do
|
||||||
ldap_authenticator =
|
|
||||||
Pleroma.Config.get(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator)
|
|
||||||
|
|
||||||
ldap_enabled = Pleroma.Config.get([:ldap, :enabled])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, ldap_authenticator)
|
|
||||||
Pleroma.Config.put([:ldap, :enabled], ldap_enabled)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
|
||||||
Pleroma.Config.put([:ldap, :enabled], true)
|
Pleroma.Config.put([:ldap, :enabled], true)
|
||||||
|
end
|
||||||
|
|
||||||
:ok
|
clear_config_all(Pleroma.Web.Auth.Authenticator) do
|
||||||
|
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag @skip
|
@tag @skip
|
||||||
|
|
|
@ -11,23 +11,15 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
||||||
alias Pleroma.Web.OAuth.OAuthController
|
alias Pleroma.Web.OAuth.OAuthController
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
@oauth_config_path [:oauth2, :issue_new_refresh_token]
|
|
||||||
@session_opts [
|
@session_opts [
|
||||||
store: :cookie,
|
store: :cookie,
|
||||||
key: "_test",
|
key: "_test",
|
||||||
signing_salt: "cooldude"
|
signing_salt: "cooldude"
|
||||||
]
|
]
|
||||||
|
clear_config_all([:instance, :account_activation_required])
|
||||||
|
|
||||||
describe "in OAuth consumer mode, " do
|
describe "in OAuth consumer mode, " do
|
||||||
setup do
|
setup do
|
||||||
oauth_consumer_strategies_path = [:auth, :oauth_consumer_strategies]
|
|
||||||
oauth_consumer_strategies = Pleroma.Config.get(oauth_consumer_strategies_path)
|
|
||||||
Pleroma.Config.put(oauth_consumer_strategies_path, ~w(twitter facebook))
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put(oauth_consumer_strategies_path, oauth_consumer_strategies)
|
|
||||||
end)
|
|
||||||
|
|
||||||
[
|
[
|
||||||
app: insert(:oauth_app),
|
app: insert(:oauth_app),
|
||||||
conn:
|
conn:
|
||||||
|
@ -37,6 +29,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:auth, :oauth_consumer_strategies]) do
|
||||||
|
Pleroma.Config.put(
|
||||||
|
[:auth, :oauth_consumer_strategies],
|
||||||
|
~w(twitter facebook)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
|
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
|
||||||
app: app,
|
app: app,
|
||||||
conn: conn
|
conn: conn
|
||||||
|
@ -775,12 +774,7 @@ test "rejects token exchange with invalid client credentials" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
|
||||||
|
|
||||||
unless setting do
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
password = "testpassword"
|
password = "testpassword"
|
||||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||||
|
@ -857,16 +851,10 @@ test "rejects an invalid authorization code" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /oauth/token - refresh token" do
|
describe "POST /oauth/token - refresh token" do
|
||||||
setup do
|
clear_config([:oauth2, :issue_new_refresh_token])
|
||||||
oauth_token_config = Pleroma.Config.get(@oauth_config_path)
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.get(@oauth_config_path, oauth_token_config)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "issues a new access token with keep fresh token" do
|
test "issues a new access token with keep fresh token" do
|
||||||
Pleroma.Config.put(@oauth_config_path, true)
|
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||||
|
|
||||||
|
@ -906,7 +894,7 @@ test "issues a new access token with keep fresh token" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "issues a new access token with new fresh token" do
|
test "issues a new access token with new fresh token" do
|
||||||
Pleroma.Config.put(@oauth_config_path, false)
|
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||||
|
|
||||||
|
|
|
@ -15,16 +15,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
config_path = [:instance, :federating]
|
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config_all([:instance, :federating]) do
|
||||||
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
|
end
|
||||||
|
|
||||||
describe "salmon_incoming" do
|
describe "salmon_incoming" do
|
||||||
test "decodes a salmon", %{conn: conn} do
|
test "decodes a salmon", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
|
@ -4,15 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.FederatingPlugTest do
|
defmodule Pleroma.Web.FederatingPlugTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
clear_config_all([:instance, :federating])
|
||||||
setup_all do
|
|
||||||
config_path = [:instance, :federating]
|
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "returns and halt the conn when federating is disabled" do
|
test "returns and halt the conn when federating is disabled" do
|
||||||
Pleroma.Config.put([:instance, :federating], false)
|
Pleroma.Config.put([:instance, :federating], false)
|
||||||
|
|
|
@ -15,12 +15,12 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
rich_media = Config.get([:rich_media, :enabled])
|
|
||||||
on_exit(fn -> Config.put([:rich_media, :enabled], rich_media) end)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:rich_media, :enabled])
|
||||||
|
|
||||||
test "refuses to crawl incomplete URLs" do
|
test "refuses to crawl incomplete URLs" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
|
@ -11,15 +11,7 @@ defmodule Pleroma.Web.StreamerTest do
|
||||||
alias Pleroma.Web.Streamer
|
alias Pleroma.Web.Streamer
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do
|
clear_config_all([:instance, :skip_thread_containment])
|
||||||
skip_thread_containment = Pleroma.Config.get([:instance, :skip_thread_containment])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :skip_thread_containment], skip_thread_containment)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "user streams" do
|
describe "user streams" do
|
||||||
setup do
|
setup do
|
||||||
|
|
|
@ -151,6 +151,7 @@ test "with credentials", %{conn: conn, user: user} do
|
||||||
|
|
||||||
describe "GET /statuses/public_timeline.json" do
|
describe "GET /statuses/public_timeline.json" do
|
||||||
setup [:valid_user]
|
setup [:valid_user]
|
||||||
|
clear_config([:instance, :public])
|
||||||
|
|
||||||
test "returns statuses", %{conn: conn} do
|
test "returns statuses", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -173,8 +174,6 @@ test "returns 403 to unauthenticated request when the instance is not public", %
|
||||||
conn
|
conn
|
||||||
|> get("/api/statuses/public_timeline.json")
|
|> get("/api/statuses/public_timeline.json")
|
||||||
|> json_response(403)
|
|> json_response(403)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :public], true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to authenticated request when the instance is not public",
|
test "returns 200 to authenticated request when the instance is not public",
|
||||||
|
@ -185,8 +184,6 @@ test "returns 200 to authenticated request when the instance is not public",
|
||||||
|> with_credentials(user.nickname, "test")
|
|> with_credentials(user.nickname, "test")
|
||||||
|> get("/api/statuses/public_timeline.json")
|
|> get("/api/statuses/public_timeline.json")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :public], true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||||
|
@ -220,6 +217,7 @@ test "returns 200 to authenticated request when the instance is public",
|
||||||
|
|
||||||
describe "GET /statuses/public_and_external_timeline.json" do
|
describe "GET /statuses/public_and_external_timeline.json" do
|
||||||
setup [:valid_user]
|
setup [:valid_user]
|
||||||
|
clear_config([:instance, :public])
|
||||||
|
|
||||||
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
||||||
Pleroma.Config.put([:instance, :public], false)
|
Pleroma.Config.put([:instance, :public], false)
|
||||||
|
@ -227,8 +225,6 @@ test "returns 403 to unauthenticated request when the instance is not public", %
|
||||||
conn
|
conn
|
||||||
|> get("/api/statuses/public_and_external_timeline.json")
|
|> get("/api/statuses/public_and_external_timeline.json")
|
||||||
|> json_response(403)
|
|> json_response(403)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :public], true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to authenticated request when the instance is not public",
|
test "returns 200 to authenticated request when the instance is not public",
|
||||||
|
@ -239,8 +235,6 @@ test "returns 200 to authenticated request when the instance is not public",
|
||||||
|> with_credentials(user.nickname, "test")
|
|> with_credentials(user.nickname, "test")
|
||||||
|> get("/api/statuses/public_and_external_timeline.json")
|
|> get("/api/statuses/public_and_external_timeline.json")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :public], true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||||
|
@ -1176,13 +1170,6 @@ test "it returns 500 if token is invalid", %{conn: conn, user: user} do
|
||||||
|
|
||||||
describe "POST /api/account/resend_confirmation_email" do
|
describe "POST /api/account/resend_confirmation_email" do
|
||||||
setup do
|
setup do
|
||||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
|
||||||
|
|
||||||
unless setting do
|
|
||||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||||
|
|
||||||
|
@ -1197,6 +1184,10 @@ test "it returns 500 if token is invalid", %{conn: conn, user: user} do
|
||||||
[user: user]
|
[user: user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance, :account_activation_required]) do
|
||||||
|
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns 204 No Content", %{conn: conn, user: user} do
|
test "it returns 204 No Content", %{conn: conn, user: user} do
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|
|
|
@ -14,20 +14,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
instance_config = Pleroma.Config.get([:instance])
|
|
||||||
pleroma_fe = Pleroma.Config.get([:frontend_configurations, :pleroma_fe])
|
|
||||||
deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance], instance_config)
|
|
||||||
Pleroma.Config.put([:frontend_configurations, :pleroma_fe], pleroma_fe)
|
|
||||||
Pleroma.Config.put([:user, :deny_follow_blocked], deny_follow_blocked)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config([:instance])
|
||||||
|
clear_config([:frontend_configurations, :pleroma_fe])
|
||||||
|
clear_config([:user, :deny_follow_blocked])
|
||||||
|
|
||||||
describe "POST /api/pleroma/follow_import" do
|
describe "POST /api/pleroma/follow_import" do
|
||||||
test "it returns HTTP 200", %{conn: conn} do
|
test "it returns HTTP 200", %{conn: conn} do
|
||||||
user1 = insert(:user)
|
user1 = insert(:user)
|
||||||
|
@ -260,7 +253,6 @@ test "it returns config in json format", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
|
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
|
||||||
option = Pleroma.Config.get([:instance, :safe_dm_mentions])
|
|
||||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
@ -278,8 +270,6 @@ test "returns the state of safe_dm_mentions flag", %{conn: conn} do
|
||||||
|> json_response(:ok)
|
|> json_response(:ok)
|
||||||
|
|
||||||
assert response["site"]["safeDMMentionsEnabled"] == "0"
|
assert response["site"]["safeDMMentionsEnabled"] == "0"
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns the managed config", %{conn: conn} do
|
test "it returns the managed config", %{conn: conn} do
|
||||||
|
@ -534,15 +524,7 @@ test "returns error when user is blocked", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/healthcheck" do
|
describe "GET /api/pleroma/healthcheck" do
|
||||||
setup do
|
clear_config([:instance, :healthcheck])
|
||||||
config_healthcheck = Pleroma.Config.get([:instance, :healthcheck])
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Pleroma.Config.put([:instance, :healthcheck], config_healthcheck)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "returns 503 when healthcheck disabled", %{conn: conn} do
|
test "returns 503 when healthcheck disabled", %{conn: conn} do
|
||||||
Pleroma.Config.put([:instance, :healthcheck], false)
|
Pleroma.Config.put([:instance, :healthcheck], false)
|
||||||
|
|
|
@ -10,15 +10,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
config_path = [:instance, :federating]
|
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_config_all([:instance, :federating]) do
|
||||||
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
|
end
|
||||||
|
|
||||||
test "GET host-meta" do
|
test "GET host-meta" do
|
||||||
response =
|
response =
|
||||||
build_conn()
|
build_conn()
|
||||||
|
|
|
@ -9,14 +9,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
|
||||||
alias Pleroma.Web.Websub
|
alias Pleroma.Web.Websub
|
||||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||||
|
|
||||||
setup_all do
|
clear_config_all([:instance, :federating]) do
|
||||||
config_path = [:instance, :federating]
|
Pleroma.Config.put([:instance, :federating], true)
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "websub subscription request", %{conn: conn} do
|
test "websub subscription request", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in New Issue