test "creates new dir" do
path = "test/fixtures/new_dir/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
test "to existance folder" do
path = "test/fixtures/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
:ok = File.rm(file_path)
test "find only local statuses for unauthenticated users when `limit_to_local_content` is `:all`",
%{local_activity: local_activity} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ clear_config([:instance, :limit_to_local_content], :all)
assert [^local_activity] = Activity.search(nil, "find me")
end
local_activity: local_activity,
remote_activity: remote_activity
} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)
import Mock
alias Pleroma.ApplicationRequirements
- alias Pleroma.Config
alias Pleroma.Repo
describe "check_repo_pool_size!/1" do
setup do: clear_config([Pleroma.Emails.Mailer])
test "raises if welcome email enabled but mail disabled" do
- Pleroma.Config.put([:welcome, :email, :enabled], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
setup do: clear_config([:instance, :account_activation_required])
test "raises if account confirmation is required but mailer isn't enable" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
assert_raise Pleroma.ApplicationRequirements.VerifyError,
"Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
end
test "doesn't do anything if account confirmation is disabled" do
- Pleroma.Config.put([:instance, :account_activation_required], false)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], false)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
assert Pleroma.ApplicationRequirements.verify!() == :ok
end
test "doesn't do anything if account confirmation is required and mailer is enabled" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], true)
assert Pleroma.ApplicationRequirements.verify!() == :ok
end
end
setup do: clear_config([:database, :rum_enabled])
test "raises if rum is enabled and detects unapplied rum migrations" do
- Config.put([:database, :rum_enabled], true)
+ clear_config([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert_raise ApplicationRequirements.VerifyError,
end
test "raises if rum is disabled and detects rum migrations" do
- Config.put([:database, :rum_enabled], false)
+ clear_config([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert_raise ApplicationRequirements.VerifyError,
end
test "doesn't do anything if rum enabled and applied migrations" do
- Config.put([:database, :rum_enabled], true)
+ clear_config([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert ApplicationRequirements.verify!() == :ok
end
test "doesn't do anything if rum disabled" do
- Config.put([:database, :rum_enabled], false)
+ clear_config([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert ApplicationRequirements.verify!() == :ok
end
test "doesn't do anything if disabled" do
- Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
+ clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
assert :ok == ApplicationRequirements.verify!()
end
describe "Captcha Wrapper" do
test "validate" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
end
test "doesn't validate invalid answer" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
end
test "nil answer_data" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
describe "nil values" do
setup do
- Pleroma.Config.put(:lorem, nil)
- Pleroma.Config.put(:ipsum, %{dolor: [sit: nil]})
- Pleroma.Config.put(:dolor, sit: %{amet: nil})
+ clear_config(:lorem, nil)
+ clear_config(:ipsum, %{dolor: [sit: nil]})
+ clear_config(:dolor, sit: %{amet: nil})
on_exit(fn -> Enum.each(~w(lorem ipsum dolor)a, &Pleroma.Config.delete/1) end)
end
end
test "get/1 when value is false" do
- Pleroma.Config.put([:instance, :false_test], false)
- Pleroma.Config.put([:instance, :nested], [])
- Pleroma.Config.put([:instance, :nested, :false_test], false)
+ clear_config([:instance, :false_test], false)
+ clear_config([:instance, :nested], [])
+ clear_config([:instance, :nested, :false_test], false)
assert Pleroma.Config.get([:instance, :false_test]) == false
assert Pleroma.Config.get([:instance, :nested, :false_test]) == false
end
test "get!/1 when value is false" do
- Pleroma.Config.put([:instance, :false_test], false)
- Pleroma.Config.put([:instance, :nested], [])
- Pleroma.Config.put([:instance, :nested, :false_test], false)
+ clear_config([:instance, :false_test], false)
+ clear_config([:instance, :nested], [])
+ clear_config([:instance, :nested, :false_test], false)
assert Pleroma.Config.get!([:instance, :false_test]) == false
assert Pleroma.Config.get!([:instance, :nested, :false_test]) == false
end
test "put/2 with a key" do
- Pleroma.Config.put(:config_test, true)
+ clear_config(:config_test, true)
assert Pleroma.Config.get(:config_test) == true
end
test "put/2 with a list of keys" do
- Pleroma.Config.put([:instance, :config_test], true)
- Pleroma.Config.put([:instance, :config_nested_test], [])
- Pleroma.Config.put([:instance, :config_nested_test, :x], true)
+ clear_config([:instance, :config_test], true)
+ clear_config([:instance, :config_nested_test], [])
+ clear_config([:instance, :config_nested_test, :x], true)
assert Pleroma.Config.get([:instance, :config_test]) == true
assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
end
test "delete/1 with a key" do
- Pleroma.Config.put([:delete_me], :delete_me)
+ clear_config([:delete_me], :delete_me)
Pleroma.Config.delete([:delete_me])
assert Pleroma.Config.get([:delete_me]) == nil
end
test "delete/2 with a list of keys" do
- Pleroma.Config.put([:delete_me], hello: "world", world: "Hello")
+ clear_config([:delete_me], hello: "world", world: "Hello")
Pleroma.Config.delete([:delete_me, :world])
assert Pleroma.Config.get([:delete_me]) == [hello: "world"]
- Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
+ clear_config([:delete_me, :delete_me], hello: "world", world: "Hello")
Pleroma.Config.delete([:delete_me, :delete_me, :world])
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
end
test "fetch/1" do
- Pleroma.Config.put([:lorem], :ipsum)
- Pleroma.Config.put([:ipsum], dolor: :sit)
+ clear_config([:lorem], :ipsum)
+ clear_config([:ipsum], dolor: :sit)
assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
import Mox
import ExUnit.CaptureLog
- alias Pleroma.Config
alias Pleroma.Gun.ConnectionPool
defp gun_mock(_) do
test "connection limit is respected with concurrent requests" do
clear_config([:connections_pool, :max_connections]) do
- Config.put([:connections_pool, :max_connections], 1)
+ clear_config([:connections_pool, :max_connections], 1)
# The supervisor needs a reboot to apply the new config setting
Process.exit(Process.whereis(Pleroma.Gun.ConnectionPool.WorkerSupervisor), :kill)
import Mox
- alias Pleroma.Config
alias Pleroma.HTTP.AdapterHelper.Gun
setup :verify_on_exit!
end
test "parses string proxy host & port" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], "localhost:8123")
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], "localhost:8123")
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
end
test "parses tuple proxy scheme host and port" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], {:socks, 'localhost', 1234})
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], {:socks, 'localhost', 1234})
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
end
test "passed opts have more weight than defaults" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], {:socks5, 'localhost', 1234})
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], {:socks5, 'localhost', 1234})
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
use Pleroma.DataCase
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.Object.Fetcher
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
test "it returns thread depth exceeded error if thread depth is exceeded" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
assert {:error, "Max thread distance exceeded."} =
Fetcher.fetch_object_from_id(@ap_id, depth: 1)
end
test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id)
end
test "it fetches object if requested depth does not exceed max thread depth" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 10)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 10)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id, depth: 10)
end
Pleroma.Signature,
[:passthrough],
[] do
- Config.put([:activitypub, :sign_object_fetches], true)
+ clear_config([:activitypub, :sign_object_fetches], true)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
Pleroma.Signature,
[:passthrough],
[] do
- Config.put([:activitypub, :sign_object_fetches], false)
+ clear_config([:activitypub, :sign_object_fetches], false)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
strip_prefix: false
]
- Pleroma.Config.put(Pleroma.Formatter, new_opts)
+ clear_config(Pleroma.Formatter, new_opts)
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
{text, _mentions, []} =
strip_prefix: false
]
- Pleroma.Config.put(Pleroma.Formatter, new_opts)
+ clear_config(Pleroma.Formatter, new_opts)
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
{text, _mentions, []} =
describe "creation" do
test "scheduled activities with jobs when ScheduledActivity enabled" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
user = insert(:user)
today =
end
test "scheduled activities without jobs when ScheduledActivity disabled" do
- Pleroma.Config.put([ScheduledActivity, :enabled], false)
+ clear_config([ScheduledActivity, :enabled], false)
user = insert(:user)
today =
defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Upload
setup do
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
- Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
+ clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.png"
end
test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do
- Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
+ clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.jpg"
end
defmodule Pleroma.Upload.FilterTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Upload.Filter
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "applies filters" do
- Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
+ clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
File.cp!(
"test/fixtures/image.jpg",
defmodule Pleroma.Uploaders.S3Test do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Uploaders.S3
import Mock
end
test "it returns path without bucket when truncated_namespace set to ''" do
- Config.put([Pleroma.Uploaders.S3],
+ clear_config([Pleroma.Uploaders.S3],
bucket: "test_bucket",
bucket_namespace: "myaccount",
truncated_namespace: ""
)
- Config.put([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
+ clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
assert S3.get_file("test_image.jpg") == {
:ok,
end
test "it returns path with bucket namespace when namespace is set" do
- Config.put([Pleroma.Uploaders.S3],
+ clear_config([Pleroma.Uploaders.S3],
bucket: "test_bucket",
bucket_namespace: "family"
)
end
test "it requries enabled email" do
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
user = insert(:user)
assert {:error, "Backups require enabled email"} == Backup.create(user)
end
end
test "it process a backup record" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
%{id: user_id} = user = insert(:user)
assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
end
test "it removes outdated backups after creating a fresh one" do
- Pleroma.Config.put([Backup, :limit_days], -1)
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Backup, :limit_days], -1)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
user = insert(:user)
assert {:ok, job1} = Backup.create(user)
defmodule Pleroma.User.WelcomeChatMessageTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User.WelcomeChatMessage
import Pleroma.Factory
welcome_user = insert(:user, name: "mewmew")
user = insert(:user)
- Config.put([:welcome, :chat_message, :enabled], true)
- Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Config.put(
+ clear_config(
[:welcome, :chat_message, :message],
"Hello, welcome to Blob/Cat!"
)
test "send a welcome email" do
user = insert(:user, name: "Jimm")
- Config.put([:welcome, :email, :enabled], true)
- Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], "welcome@pleroma.app")
- Config.put(
+ clear_config(
[:welcome, :email, :subject],
"Hello, welcome to pleroma: <%= instance_name %>"
)
- Config.put(
+ clear_config(
[:welcome, :email, :html],
"<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
)
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
)
- Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
+ clear_config([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
{:ok, _job} = WelcomeEmail.send_email(user)
defmodule Pleroma.User.WelcomeMessageTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User.WelcomeMessage
import Pleroma.Factory
welcome_user = insert(:user)
user = insert(:user, name: "Jimm")
- Config.put([:welcome, :direct_message, :enabled], true)
- Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :direct_message, :enabled], true)
+ clear_config([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
- Config.put(
+ clear_config(
[:welcome, :direct_message, :message],
"Hello. Welcome to Pleroma"
)
setup do: clear_config([:instance, :limit_to_local_content])
test "returns a resolved user as the first result" do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
user = insert(:user, %{nickname: "no_relation", ap_id: "https://lain.com/users/lain"})
_user = insert(:user, %{nickname: "com_user"})
end
test "find only local users for authenticated users when `limit_to_local_content` is `:all`" do
- Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ clear_config([:instance, :limit_to_local_content], :all)
%{id: id} = insert(:user, %{name: "lain"})
insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
end
test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
u1 = insert(:user, %{name: "lain"})
u2 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
setup do: clear_config([:instance, :external_user_synchronization])
test "unfollow with syncronizes external user" do
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ clear_config([:instance, :external_user_synchronization], true)
followed =
insert(:user,
user = insert(:user)
remote_user = insert(:user, %{local: false})
- Pleroma.Config.put([:instance, :autofollowed_nicknames], [
+ clear_config([:instance, :autofollowed_nicknames], [
user.nickname,
remote_user.nickname
])
user1 = insert(:user)
user2 = insert(:user)
- Pleroma.Config.put([:instance, :autofollowing_nicknames], [
+ clear_config([:instance, :autofollowing_nicknames], [
user1.nickname,
user2.nickname
])
test "it sends a welcome message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
- Pleroma.Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :direct_message, :message], "Hello, this is a direct message")
+ clear_config([:welcome, :direct_message, :enabled], true)
+ clear_config([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :direct_message, :message], "Hello, this is a direct message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
test "it sends a welcome chat message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :chat_message, :enabled], true)
- Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message")
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :message], "Hello, this is a chat message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
)
test "it sends a welcome chat message when Simple policy applied to local instance" do
- Pleroma.Config.put([:mrf_simple, :media_nsfw], ["localhost"])
+ clear_config([:mrf_simple, :media_nsfw], ["localhost"])
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :chat_message, :enabled], true)
- Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message")
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :message], "Hello, this is a chat message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
test "it sends a welcome email message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :email, :enabled], true)
- Pleroma.Config.put([:welcome, :email, :sender], welcome_user.email)
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], welcome_user.email)
- Pleroma.Config.put(
+ clear_config(
[:welcome, :email, :subject],
"Hello, welcome to cool site: <%= instance_name %>"
)
end
test "it sends a confirm email" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
end
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
@full_user_data
|> Map.keys()
end
test "it requires an name, nickname and password, bio and email are optional when account_activation_required is disabled" do
- Pleroma.Config.put([:instance, :account_activation_required], false)
+ clear_config([:instance, :account_activation_required], false)
@full_user_data
|> Map.keys()
setup do: clear_config([:instance, :account_activation_required])
test "return confirmation_pending for unconfirm user" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: false)
assert User.account_status(user) == :confirmation_pending
end
test "return active for confirmed user" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: true)
assert User.account_status(user) == :active
end
end
test "returns false when the account is unconfirmed and confirmation is required" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, local: true, is_confirmed: false)
other_user = insert(:user, local: true)
end
test "returns true when the account is unconfirmed and confirmation is required but the account is remote" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, local: false, is_confirmed: false)
other_user = insert(:user, local: true)
end
test "returns true when the account is unconfirmed and being viewed by a privileged account (confirmation required)" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, local: true, is_confirmed: false)
other_user = insert(:user, local: true, is_admin: true)
setup do: clear_config([:instance, :external_user_synchronization])
test "updates the counters normally on following/getting a follow when disabled" do
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
other_user =
end
test "syncronizes the counters with the remote instance for the followed when enabled" do
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
assert other_user.following_count == 0
assert other_user.follower_count == 0
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ clear_config([:instance, :external_user_synchronization], true)
{:ok, _user, other_user} = User.follow(user, other_user)
assert other_user.follower_count == 437
end
test "syncronizes the counters with the remote instance for the follower when enabled" do
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
assert other_user.following_count == 0
assert other_user.follower_count == 0
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ clear_config([:instance, :external_user_synchronization], true)
{:ok, other_user, _user} = User.follow(other_user, user)
assert other_user.following_count == 152
test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
remote_user: remote_user
} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
end
test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
%{remote_user: remote_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
end
test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
%{remote_user: remote_user, local_user: local_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
end
test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
%{remote_user: remote_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
end
test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
%{local_user: local_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
end
end
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Delivery
alias Pleroma.Instances
alias Pleroma.Object
end
test "with the relay disabled, it returns 404", %{conn: conn} do
- Config.put([:instance, :allow_relay], false)
+ clear_config([:instance, :allow_relay], false)
conn
|> get(activity_pub_path(conn, :relay))
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
end
test "accept follow activity", %{conn: conn} do
- Pleroma.Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
relay = Relay.get_actor()
assert {:ok, %Activity{} = activity} = Relay.follow("https://relay.mastodon.host/actor")
conn = put_req_header(conn, "content-type", "application/activity+json")
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
conn
|> post("/inbox", data)
|> post("/inbox", non_create_data)
|> json_response(403)
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
ret_conn = post(conn, "/inbox", data)
assert "ok" == json_response(ret_conn, 200)
end
test "Character limitation", %{conn: conn, activity: activity} do
- Pleroma.Config.put([:instance, :limit], 5)
+ clear_config([:instance, :limit], 5)
user = insert(:user)
result =
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
test "it sets the default description depending on the configuration", %{test_file: file} do
clear_config([Pleroma.Upload, :default_description])
- Pleroma.Config.put([Pleroma.Upload, :default_description], nil)
+ clear_config([Pleroma.Upload, :default_description], nil)
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == ""
- Pleroma.Config.put([Pleroma.Upload, :default_description], :filename)
+ clear_config([Pleroma.Upload, :default_description], :filename)
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == "an_image.jpg"
- Pleroma.Config.put([Pleroma.Upload, :default_description], "unnamed attachment")
+ clear_config([Pleroma.Upload, :default_description], "unnamed attachment")
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == "unnamed attachment"
end
setup do: clear_config(:mrf_hellthread)
test "doesn't die on chat messages" do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
user = insert(:user)
other_user = insert(:user)
test "rejects the message if the recipient count is above reject_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
filter(message)
test "does not reject the message if the recipient count is below reject_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
user: user,
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
{:ok, message} = filter(message)
assert user.follower_address in message["to"]
test "does not delist the message if the recipient count is below delist_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
assert {:ok, ^message} = filter(message)
end
end
test "excludes follower collection and public URI from threshold count", %{message: message} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
setup do: clear_config(:mrf_keyword)
setup do
- Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
+ clear_config([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
end
describe "rejecting based on keywords" do
test "rejects if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+ clear_config([:mrf_keyword, :reject], ["pun"])
message = %{
"type" => "Create",
end
test "rejects if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+ clear_config([:mrf_keyword, :reject], ["pun"])
message = %{
"type" => "Create",
end
test "rejects if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
end
test "rejects if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
describe "delisting from ftl based on keywords" do
test "delists if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+ clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
message = %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
end
test "delists if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+ clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
message = %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
end
test "delists if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
end
test "delists if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
describe "replacing keywords" do
test "replaces keyword if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
message = %{
"type" => "Create",
end
test "replaces keyword if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
message = %{
"type" => "Create",
end
test "replaces keyword if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :replace], [
+ clear_config([:mrf_keyword, :replace], [
{~r/open(-|\s)?source\s?(software)?/, "free software"}
])
end
test "replaces keyword if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :replace], [
+ clear_config([:mrf_keyword, :replace], [
{~r/open(-|\s)?source\s?(software)?/, "free software"}
])
describe "allow" do
test "empty" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create"
end
test "to" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
end
test "cc" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
end
test "both" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
describe "deny" do
test "to" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
end
test "cc" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
alias Pleroma.Web.ActivityPub.Visibility
describe "with reject action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data =
get_old_message()
end
test "it rejects an old post" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data = get_old_message()
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data = get_new_message()
describe "with delist action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data =
get_old_message()
end
test "it delists an old post" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data = get_old_message()
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data = get_new_message()
describe "with strip_followers action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data =
get_old_message()
end
test "it strips followers collections from an old post" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data = get_old_message()
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data = get_new_message()
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
+ clear_config([:mrf_rejectnonpublic, :allow_followersonly], true)
assert {:ok, _message} = RejectNonPublic.filter(message)
end
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
+ clear_config([:mrf_rejectnonpublic, :allow_followersonly], false)
assert {:reject, _} = RejectNonPublic.filter(message)
end
end
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
+ clear_config([:mrf_rejectnonpublic, :allow_direct], true)
assert {:ok, _message} = RejectNonPublic.filter(message)
end
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
+ clear_config([:mrf_rejectnonpublic, :allow_direct], false)
assert {:reject, _} = RejectNonPublic.filter(message)
end
end
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
alias Pleroma.Web.CommonAPI
describe "when :media_removal" do
test "is empty" do
- Config.put([:mrf_simple, :media_removal], [])
+ clear_config([:mrf_simple, :media_removal], [])
media_message = build_media_message()
local_message = build_local_message()
end
test "has a matching host" do
- Config.put([:mrf_simple, :media_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :media_removal], ["remote.instance"])
media_message = build_media_message()
local_message = build_local_message()
end
test "match with wildcard domain" do
- Config.put([:mrf_simple, :media_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :media_removal], ["*.remote.instance"])
media_message = build_media_message()
local_message = build_local_message()
describe "when :media_nsfw" do
test "is empty" do
- Config.put([:mrf_simple, :media_nsfw], [])
+ clear_config([:mrf_simple, :media_nsfw], [])
media_message = build_media_message()
local_message = build_local_message()
end
test "has a matching host" do
- Config.put([:mrf_simple, :media_nsfw], ["remote.instance"])
+ clear_config([:mrf_simple, :media_nsfw], ["remote.instance"])
media_message = build_media_message()
local_message = build_local_message()
end
test "match with wildcard domain" do
- Config.put([:mrf_simple, :media_nsfw], ["*.remote.instance"])
+ clear_config([:mrf_simple, :media_nsfw], ["*.remote.instance"])
media_message = build_media_message()
local_message = build_local_message()
describe "when :report_removal" do
test "is empty" do
- Config.put([:mrf_simple, :report_removal], [])
+ clear_config([:mrf_simple, :report_removal], [])
report_message = build_report_message()
local_message = build_local_message()
end
test "has a matching host" do
- Config.put([:mrf_simple, :report_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :report_removal], ["remote.instance"])
report_message = build_report_message()
local_message = build_local_message()
end
test "match with wildcard domain" do
- Config.put([:mrf_simple, :report_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :report_removal], ["*.remote.instance"])
report_message = build_report_message()
local_message = build_local_message()
describe "when :federated_timeline_removal" do
test "is empty" do
- Config.put([:mrf_simple, :federated_timeline_removal], [])
+ clear_config([:mrf_simple, :federated_timeline_removal], [])
{_, ftl_message} = build_ftl_actor_and_message()
local_message = build_local_message()
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
local_message = build_local_message()
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
local_message = build_local_message()
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
ftl_message = Map.put(ftl_message, "cc", [])
- Config.put([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
refute "https://www.w3.org/ns/activitystreams#Public" in ftl_message["to"]
describe "when :reject" do
test "is empty" do
- Config.put([:mrf_simple, :reject], [])
+ clear_config([:mrf_simple, :reject], [])
remote_message = build_remote_message()
end
test "activity has a matching host" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], ["remote.instance"])
remote_message = build_remote_message()
end
test "activity matches with wildcard domain" do
- Config.put([:mrf_simple, :reject], ["*.remote.instance"])
+ clear_config([:mrf_simple, :reject], ["*.remote.instance"])
remote_message = build_remote_message()
end
test "actor has a matching host" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], ["remote.instance"])
remote_user = build_remote_user()
describe "when :followers_only" do
test "is empty" do
- Config.put([:mrf_simple, :followers_only], [])
+ clear_config([:mrf_simple, :followers_only], [])
{_, ftl_message} = build_ftl_actor_and_message()
local_message = build_local_message()
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([:mrf_simple, :followers_only], [actor_domain])
+ clear_config([:mrf_simple, :followers_only], [actor_domain])
assert {:ok, new_activity} = SimplePolicy.filter(activity)
assert actor.follower_address in new_activity["cc"]
describe "when :accept" do
test "is empty" do
- Config.put([:mrf_simple, :accept], [])
+ clear_config([:mrf_simple, :accept], [])
local_message = build_local_message()
remote_message = build_remote_message()
end
test "is not empty but activity doesn't have a matching host" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], ["non.matching.remote"])
local_message = build_local_message()
remote_message = build_remote_message()
end
test "activity has a matching host" do
- Config.put([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], ["remote.instance"])
local_message = build_local_message()
remote_message = build_remote_message()
end
test "activity matches with wildcard domain" do
- Config.put([:mrf_simple, :accept], ["*.remote.instance"])
+ clear_config([:mrf_simple, :accept], ["*.remote.instance"])
local_message = build_local_message()
remote_message = build_remote_message()
end
test "actor has a matching host" do
- Config.put([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], ["remote.instance"])
remote_user = build_remote_user()
describe "when :avatar_removal" do
test "is empty" do
- Config.put([:mrf_simple, :avatar_removal], [])
+ clear_config([:mrf_simple, :avatar_removal], [])
remote_user = build_remote_user()
end
test "is not empty but it doesn't have a matching host" do
- Config.put([:mrf_simple, :avatar_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :avatar_removal], ["non.matching.remote"])
remote_user = build_remote_user()
end
test "has a matching host" do
- Config.put([:mrf_simple, :avatar_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :avatar_removal], ["remote.instance"])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
end
test "match with wildcard domain" do
- Config.put([:mrf_simple, :avatar_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :avatar_removal], ["*.remote.instance"])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
describe "when :banner_removal" do
test "is empty" do
- Config.put([:mrf_simple, :banner_removal], [])
+ clear_config([:mrf_simple, :banner_removal], [])
remote_user = build_remote_user()
end
test "is not empty but it doesn't have a matching host" do
- Config.put([:mrf_simple, :banner_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :banner_removal], ["non.matching.remote"])
remote_user = build_remote_user()
end
test "has a matching host" do
- Config.put([:mrf_simple, :banner_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :banner_removal], ["remote.instance"])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
end
test "match with wildcard domain" do
- Config.put([:mrf_simple, :banner_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :banner_removal], ["*.remote.instance"])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
end
describe "when :reject_deletes is empty" do
- setup do: Config.put([:mrf_simple, :reject_deletes], [])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [])
test "it accepts deletions even from rejected servers" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], ["remote.instance"])
deletion_message = build_remote_deletion_message()
end
test "it accepts deletions even from non-whitelisted servers" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], ["non.matching.remote"])
deletion_message = build_remote_deletion_message()
end
describe "when :reject_deletes is not empty but it doesn't have a matching host" do
- setup do: Config.put([:mrf_simple, :reject_deletes], ["non.matching.remote"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], ["non.matching.remote"])
test "it accepts deletions even from rejected servers" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], ["remote.instance"])
deletion_message = build_remote_deletion_message()
end
test "it accepts deletions even from non-whitelisted servers" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], ["non.matching.remote"])
deletion_message = build_remote_deletion_message()
end
describe "when :reject_deletes has a matching host" do
- setup do: Config.put([:mrf_simple, :reject_deletes], ["remote.instance"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], ["remote.instance"])
test "it rejects the deletion" do
deletion_message = build_remote_deletion_message()
end
describe "when :reject_deletes match with wildcard domain" do
- setup do: Config.put([:mrf_simple, :reject_deletes], ["*.remote.instance"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], ["*.remote.instance"])
test "it rejects the deletion" do
deletion_message = build_remote_deletion_message()
setup do: clear_config([:mrf_subchain, :match_actor])
test "it matches and processes subchains when the actor matches a configured target" do
- Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ clear_config([:mrf_subchain, :match_actor], %{
~r/^https:\/\/banned.com/s => [DropPolicy]
})
end
test "it doesn't match and process subchains when the actor doesn't match a configured target" do
- Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ clear_config([:mrf_subchain, :match_actor], %{
~r/^https:\/\/borked.com/s => [DropPolicy]
})
test "pass filter if allow list isn't empty and user in allow list" do
actor = insert(:user)
- Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
+ clear_config([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
message = %{"actor" => actor.ap_id}
assert UserAllowListPolicy.filter(message) == {:ok, message}
end
test "rejected if allow list isn't empty and user not in allow list" do
actor = insert(:user)
- Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
+ clear_config([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
message = %{"actor" => actor.ap_id}
assert {:reject, _} = UserAllowListPolicy.filter(message)
end
setup do: clear_config([:mrf_vocabulary, :accept])
test "it accepts based on parent activity type" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
+ clear_config([:mrf_vocabulary, :accept], ["Like"])
message = %{
"type" => "Like",
end
test "it accepts based on child object type" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
"type" => "Create",
end
test "it does not accept disallowed child objects" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
"type" => "Create",
end
test "it does not accept disallowed parent types" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
message = %{
"type" => "Create",
setup do: clear_config([:mrf_vocabulary, :reject])
test "it rejects based on parent activity type" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+ clear_config([:mrf_vocabulary, :reject], ["Like"])
message = %{
"type" => "Like",
end
test "it rejects based on child object type" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
+ clear_config([:mrf_vocabulary, :reject], ["Note"])
message = %{
"type" => "Create",
end
test "it passes through objects that aren't disallowed" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+ clear_config([:mrf_vocabulary, :reject], ["Like"])
message = %{
"type" => "Announce",
test "does not validate if the message is longer than the remote_limit", %{
valid_chat_message: valid_chat_message
} do
- Pleroma.Config.put([:instance, :remote_limit], 2)
+ clear_config([:instance, :remote_limit], 2)
refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
end
end
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
data: data,
items: items
} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 10)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
%{data: data} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
federation_output: federation_output,
replies_uris: replies_uris
} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 1)
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
%{federation_output: federation_output} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
end
test "returns object with inReplyTo when denied incoming reply", %{data: data} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
object_with_reply =
Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
"https://mstdn.io/users/mayuutann/statuses/99568293732299394"
)
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 5)
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
assert modified_object["inReplyTo"] ==
import ExUnit.CaptureLog
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.ConfigDB
setup do
setup do: clear_config(:configurable_from_database, true)
test "when configuration from database is off", %{conn: conn} do
- Config.put(:configurable_from_database, false)
+ clear_config(:configurable_from_database, false)
conn = get(conn, "/api/pleroma/admin/config")
assert json_response_and_validate_schema(conn, 400) ==
end
test "saving config which need pleroma reboot", %{conn: conn} do
- chat = Config.get(:chat)
- on_exit(fn -> Config.put(:chat, chat) end)
+ clear_config([:chat, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
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)
+ clear_config([:chat, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Repo
alias Pleroma.UserInviteToken
setup do: clear_config([:instance, :invites_enabled])
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
- Config.put([:instance, :registrations_open], false)
- Config.put([:instance, :invites_enabled], false)
+ clear_config([:instance, :registrations_open], false)
+ clear_config([:instance, :invites_enabled], false)
conn =
conn
end
test "it returns 500 if `registrations_open` is enabled", %{conn: conn} do
- Config.put([:instance, :registrations_open], true)
- Config.put([:instance, :invites_enabled], true)
+ clear_config([:instance, :registrations_open], true)
+ clear_config([:instance, :invites_enabled], true)
conn =
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)
+ clear_config([:media_proxy, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
{:ok, %{admin: admin, token: token, conn: conn}}
end
end
test "it ignores messages above a certain length", %{socket: socket} do
- Pleroma.Config.put([:instance, :chat_limit], 2)
+ clear_config([:instance, :chat_limit], 2)
push(socket, "new_msg", %{"text" => "123"})
refute_broadcast("new_msg", %{text: "123"})
end
end
test "it reject messages over the local limit" do
- Pleroma.Config.put([:instance, :chat_limit], 2)
+ clear_config([:instance, :chat_limit], 2)
author = insert(:user)
recipient = insert(:user)
jafnhar = insert(:user)
tridi = insert(:user)
- Pleroma.Config.put([:instance, :safe_dm_mentions], true)
+ clear_config([:instance, :safe_dm_mentions], true)
{:ok, activity} =
CommonAPI.post(har, %{
end
test "it validates character limits are correctly enforced" do
- Pleroma.Config.put([:instance, :limit], 5)
+ clear_config([:instance, :limit], 5)
user = insert(:user)
describe "pinned statuses" do
setup do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ clear_config([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
activity: activity,
relay_mock: relay_mock
} do
- Pleroma.Config.put([:instance, :allow_relay], false)
+ clear_config([:instance, :allow_relay], false)
with_mocks([relay_mock]) do
Federator.publish(activity)
end
test "it does not crash if MRF rejects the post" do
- Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
+ clear_config([:mrf_keyword, :reject], ["lain"])
- Pleroma.Config.put(
+ clear_config(
[:mrf, :policies],
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
)
import Pleroma.Factory
import SweetXml
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Feed.FeedView
setup do: clear_config([:feed])
test "gets a feed (ATOM)", %{conn: conn} do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 25, omission: "..."}
)
end
test "gets a feed (RSS)", %{conn: conn} do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 25, omission: "..."}
)
import Pleroma.Factory
import SweetXml
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
setup do: clear_config([:feed])
setup do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 15, omission: "..."}
)
setup do: clear_config([:instance, :public])
test "returns 404 for user feed", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
user = insert(:user)
{:ok, _} = CommonAPI.post(user, %{status: "test"})
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
json_response_and_validate_schema(conn, 400)
- Pleroma.Config.put([User, :email_blacklist], [])
+ clear_config([User, :email_blacklist], [])
conn =
build_conn()
end
test "updates a scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
%{user: user, conn: conn} = oauth_access(["write:statuses"])
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
end
test "deletes a scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
%{user: user, conn: conn} = oauth_access(["write:statuses"])
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Conversation.Participation
alias Pleroma.Object
alias Pleroma.Repo
setup do: oauth_access(["write:statuses"])
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
Config.get([:instance, :allow_relay], true)
response =
end
test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do
- Config.put([:mrf_keyword, :reject], ["GNO"])
- Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
+ clear_config([:mrf_keyword, :reject], ["GNO"])
+ clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
conn
describe "cards" do
setup do
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
oauth_access(["read:statuses"])
end
defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Config
alias Pleroma.User
import Pleroma.Factory
conn: conn,
path: path
} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn = get(conn, path)
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI
)
with media_preview_enabled <- [false, true] do
- Config.put([:media_preview_proxy, :enabled], media_preview_enabled)
+ clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|> Enum.all?(fn
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Web.MediaProxy.Invalidation
import ExUnit.CaptureLog
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)
+ clear_config([:media_proxy, :enabled], false)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
- Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
+ clear_config([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)
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")
+ clear_config([:media_proxy, :enabled], false)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], Invalidation.Script)
+ clear_config([Invalidation.Script], script_path: "purge-nginx")
image_url = "http://example.com/media/example.jpg"
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
end
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
- Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
+ clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
%{path: path} = URI.parse(url)
assert %Conn{
end
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
- Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
+ clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
%{path: path} = URI.parse(url)
assert %Conn{
end
test "it does not render attachments if post is nsfw" do
- Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
+ clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
note =
end
test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
- Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
+ clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
import Pleroma.Factory
- alias Pleroma.Config
-
setup do: clear_config([:mrf_simple])
setup do: clear_config(:instance)
assert "safe_dm_mentions" in response["metadata"]["features"]
- Config.put([:instance, :safe_dm_mentions], false)
+ clear_config([:instance, :safe_dm_mentions], false)
response =
conn
setup do: clear_config([:instance, :federating])
test "it shows if federation is enabled/disabled", %{conn: conn} do
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
response =
conn
assert response["metadata"]["federation"]["enabled"] == true
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
response =
conn
end
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
password = "testpassword"
{:ok, user} =
end
test "rejects token exchange for user with confirmation_pending set to true" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
password = "testpassword"
user =
setup do: clear_config([:oauth2, :issue_new_refresh_token])
test "issues a new access token with keep fresh token" do
- Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
+ clear_config([:oauth2, :issue_new_refresh_token], true)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
end
test "issues a new access token with new fresh token" do
- Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
+ clear_config([:oauth2, :issue_new_refresh_token], false)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
end
test "GET /api/pleroma/emoji/packs when :public: false", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
end
end
test "with `admin_token` query parameter", %{conn: conn} do
- Pleroma.Config.put(:admin_token, "password123")
+ clear_config(:admin_token, "password123")
conn =
%{conn | params: %{"admin_token" => "wrong_password"}}
end
test "with `x-admin-token` HTTP header", %{conn: conn} do
- Pleroma.Config.put(:admin_token, "☕️")
+ clear_config(:admin_token, "☕️")
conn =
conn
defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
setup do: clear_config([:instance, :public])
test "it halts if not public and no user is assigned", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn =
conn
end
test "it continues if public", %{conn: conn} do
- Config.put([:instance, :public], true)
+ clear_config([:instance, :public], true)
ret_conn =
conn
end
test "it continues if a user is assigned, even if not public", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn =
conn
setup do: clear_config([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
- Pleroma.Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
conn =
build_conn()
end
test "does nothing when federating is enabled" do
- Pleroma.Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
conn =
build_conn()
describe "requires a signature when `authorized_fetch_mode` is enabled" do
setup do
- Pleroma.Config.put([:activitypub, :authorized_fetch_mode], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:activitypub, :authorized_fetch_mode], false)
- end)
+ clear_config([:activitypub, :authorized_fetch_mode], true)
params = %{"actor" => "http://mastodon.example.org/users/admin"}
conn = build_conn(:get, "/doesntmattter", params) |> put_format("activity+json")
"and [optionally] keeps only prefixed scopes, " <>
"depending on `[:auth, :enforce_oauth_admin_scope_usage]` setting",
%{f: f} do
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
assert f.(["read"], %{admin: true}) == ["admin:read", "read"]
"write"
]
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
assert f.(["read:accounts"], %{admin: true}) == ["admin:read:accounts"]
use Pleroma.Web.ConnCase
alias Phoenix.ConnTest
- alias Pleroma.Config
alias Pleroma.Web.Plugs.RateLimiter
alias Plug.Conn
setup do: clear_config([Pleroma.Web.Plugs.RemoteIp, :enabled])
test "config is required for plug to work" do
- Config.put([:rate_limit, @limiter_name], {1, 1})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, @limiter_name], {1, 1})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
assert %{limits: {1, 1}, name: :test_init, opts: [name: :test_init]} ==
[name: @limiter_name]
scale = 80
limit = 5
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
- Config.put([:rate_limit, limiter_name], {scale, limit})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {scale, limit})
plug_opts = RateLimiter.init(name: limiter_name)
conn = build_conn(:get, "/")
test "`bucket_name` option overrides default bucket name" do
limiter_name = :test_bucket_name
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
plug_opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name)
test "`params` option allows different queries to be tracked independently" do
limiter_name = :test_params
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name, params: ["id"])
test "it supports combination of options modifying bucket name" do
limiter_name = :test_options_combo
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
describe "unauthenticated users" do
test "are restricted based on remote IP" do
limiter_name = :test_unauthenticated
- Config.put([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
scale = 50
limit = 5
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
- Config.put([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
plug_opts = RateLimiter.init(name: limiter_name)
test "different users are counted independently" do
limiter_name = :test_authenticated2
- Config.put([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
test "doesn't crash due to a race condition when multiple requests are made at the same time and the bucket is not yet initialized" do
limiter_name = :test_race_condition
- Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5})
- Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
opts = RateLimiter.init(name: limiter_name)
)
test "disabled" do
- Pleroma.Config.put(RemoteIp, enabled: false)
+ clear_config(RemoteIp, enabled: false)
%{remote_ip: remote_ip} = conn(:get, "/")
end
test "custom headers" do
- Pleroma.Config.put(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
+ clear_config(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
conn =
conn(:get, "/")
refute conn.remote_ip == {1, 1, 1, 1}
- Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.0/20"])
+ clear_config([RemoteIp, :proxies], ["173.245.48.0/20"])
conn =
conn(:get, "/")
end
test "proxies set without CIDR format" do
- Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.1"])
+ clear_config([RemoteIp, :proxies], ["173.245.48.1"])
conn =
conn(:get, "/")
end
test "proxies set `nonsensical` CIDR" do
- Pleroma.Config.put([RemoteIp, :reserved], ["127.0.0.0/8"])
- Pleroma.Config.put([RemoteIp, :proxies], ["10.0.0.3/24"])
+ clear_config([RemoteIp, :reserved], ["127.0.0.0/8"])
+ clear_config([RemoteIp, :proxies], ["10.0.0.3/24"])
conn =
conn(:get, "/")
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
%{conn: conn} do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: false)
defmodule Pleroma.Web.RichMedia.HelpersTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.RichMedia.Helpers
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
end
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
end
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{page_url: "https://example.com/ogp", rich_media: _} =
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} = Helpers.fetch_data_for_activity(activity)
assert %{} = Helpers.fetch_data_for_activity(activity2)
describe "thread_containment/2" do
test "it filters to user if recipients invalid and thread containment is enabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ clear_config([:instance, :skip_thread_containment], false)
author = insert(:user)
%{user: user, token: oauth_token} = oauth_access(["read"])
User.follow(user, author, :follow_accept)
end
test "it sends message if recipients invalid and thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ clear_config([:instance, :skip_thread_containment], true)
author = insert(:user)
%{user: user, token: oauth_token} = oauth_access(["read"])
User.follow(user, author, :follow_accept)
end
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ clear_config([:instance, :skip_thread_containment], false)
author = insert(:user)
user = insert(:user, skip_thread_containment: true)
%{token: oauth_token} = oauth_access(["read"], user: user)
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
{:ok, _user_block} = Pleroma.User.block(user2, user)
end
test "it sends confirmation email if :account_activation_required is specified in instance config" 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
+ clear_config([:instance, :account_activation_required], true)
data = %{
:username => "lain",
use Pleroma.Web.ConnCase
use Oban.Testing, repo: Pleroma.Repo
- alias Pleroma.Config
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
}
]
- Config.put(:frontend_configurations, config)
+ clear_config(:frontend_configurations, config)
response =
conn
setup do: clear_config([:instance, :healthcheck])
test "returns 503 when healthcheck disabled", %{conn: conn} do
- Config.put([:instance, :healthcheck], false)
+ clear_config([:instance, :healthcheck], false)
response =
conn
end
test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
- Config.put([:instance, :healthcheck], true)
+ clear_config([:instance, :healthcheck], true)
with_mock Pleroma.Healthcheck,
system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
end
test "returns 503 when healthcheck enabled and health is false", %{conn: conn} do
- Config.put([:instance, :healthcheck], true)
+ clear_config([:instance, :healthcheck], true)
with_mock Pleroma.Healthcheck,
system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
setup do: clear_config([:email_notifications, :digest])
setup do
- Pleroma.Config.put([:email_notifications, :digest], %{
+ clear_config([:email_notifications, :digest], %{
active: true,
inactivity_threshold: 7,
interval: 7
setup do: clear_config([ScheduledActivity, :enabled])
test "creates a status from the scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
user = insert(:user)
naive_datetime =
end
test "adds log message if ScheduledActivity isn't find" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
assert capture_log([level: :error], fn ->
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})