alias Pleroma.Config.TransferTask
alias Pleroma.ConfigDB
- clear_config(:configurable_from_database) do
- Pleroma.Config.put(:configurable_from_database, true)
- end
+ clear_config(:configurable_from_database, true)
test "transfer config values from db to env" do
refute Application.get_env(:pleroma, :test_key)
import Pleroma.Factory
- clear_config_all([:instance, :federating]) do
- Pleroma.Config.put([:instance, :federating], true)
- end
+ clear_config_all([:instance, :federating], true)
test "it goes through old direct conversations" do
user = insert(:user)
on_exit(fn -> File.rm_rf(@dir) end)
end
- clear_config([:instance, :static_dir]) do
- Pleroma.Config.put([:instance, :static_dir], @dir)
- end
+ clear_config([:instance, :static_dir], @dir)
test "overrides index" do
bundled_index = get(build_conn(), "/")
import Pleroma.Factory
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
- clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
- end
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
test "accepts a user that is an admin" do
user = insert(:user, is_admin: true)
end
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
- clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
- end
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
setup do
admin_user = insert(:user, is_admin: true)
end
end
+ defmacro clear_config(config_path, temp_setting) do
+ quote do
+ clear_config(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
+ @doc """
+ From _within a test case_, sets config to provided value and restores initial value on exit.
+ For multi-case setup use `clear_config/2` instead.
+ """
+ def set_config(config_path, temp_setting) do
+ initial_setting = Config.get(config_path)
+ Config.put(config_path, temp_setting)
+
+ ExUnit.Callbacks.on_exit(fn -> Config.put(config_path, initial_setting) end)
+ end
+
@doc "Stores initial config value and restores it after *all* test examples are executed."
defmacro clear_config_all(config_path) do
quote do
end
end
+ defmacro clear_config_all(config_path, temp_setting) do
+ quote do
+ clear_config_all(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
defmacro __using__(_opts) do
quote do
import Pleroma.Tests.Helpers,
clear_config: 1,
clear_config: 2,
clear_config_all: 1,
- clear_config_all: 2
+ clear_config_all: 2,
+ set_config: 2
]
def to_datetime(naive_datetime) do
:ok
end
- clear_config_all(:configurable_from_database) do
- Pleroma.Config.put(:configurable_from_database, true)
- end
+ clear_config_all(:configurable_from_database, true)
test "error if file with custom settings doesn't exist" do
Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs")
end
describe "Setting a custom base_url for uploaded media" do
- clear_config([Pleroma.Upload, :base_url]) do
- Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
- end
+ clear_config([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
test "returns a media url with configured base_url" do
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
import Mock
import ExUnit.CaptureLog
- clear_config([Pleroma.Uploaders.S3]) do
- Config.put([Pleroma.Uploaders.S3],
- bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com"
- )
- end
+ clear_config(Pleroma.Uploaders.S3,
+ bucket: "test_bucket",
+ public_endpoint: "https://s3.amazonaws.com"
+ )
describe "get_file/1" do
test "it returns path to local folder for files" do
email: "email@example.com"
}
- clear_config([:instance, :account_activation_required]) do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- end
+ clear_config([:instance, :account_activation_required], true)
test "it creates unconfirmed user" do
changeset = User.register_changeset(%User{}, @full_user_data)
:ok
end
- clear_config([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config([:instance, :federating], true)
describe "/relay" do
clear_config([:instance, :allow_relay])
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
alias Pleroma.Web.ActivityPub.Visibility
- clear_config([:mrf_object_age]) do
- Config.put(:mrf_object_age,
- threshold: 172_800,
- actions: [:delist, :strip_followers]
- )
- end
+ clear_config(:mrf_object_age,
+ threshold: 172_800,
+ actions: [:delist, :strip_followers]
+ )
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
- clear_config([:mrf_simple]) do
- Config.put(:mrf_simple,
- media_removal: [],
- media_nsfw: [],
- federated_timeline_removal: [],
- report_removal: [],
- reject: [],
- accept: [],
- avatar_removal: [],
- banner_removal: []
- )
- end
+ clear_config(:mrf_simple,
+ media_removal: [],
+ media_nsfw: [],
+ federated_timeline_removal: [],
+ report_removal: [],
+ reject: [],
+ accept: [],
+ avatar_removal: [],
+ banner_removal: []
+ )
describe "when :media_removal" do
test "is empty" do
:ok
end
- clear_config_all([:instance, :federating]) do
- Pleroma.Config.put([:instance, :federating], true)
- end
+ clear_config_all([:instance, :federating], true)
describe "gather_webfinger_links/1" do
test "it returns links" do
end
describe "`handle_incoming/2`, Mastodon format `replies` handling" do
- clear_config([:activitypub, :note_replies_output_limit]) do
- Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
- end
+ clear_config([:activitypub, :note_replies_output_limit], 5)
clear_config([:instance, :federation_incoming_replies_max_depth])
end
describe "`handle_incoming/2`, Pleroma format `replies` handling" do
- clear_config([:activitypub, :note_replies_output_limit]) do
- Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
- end
+ clear_config([:activitypub, :note_replies_output_limit], 5)
clear_config([:instance, :federation_incoming_replies_max_depth])
end
describe "set_replies/1" do
- clear_config([:activitypub, :note_replies_output_limit]) do
- Pleroma.Config.put([:activitypub, :note_replies_output_limit], 2)
- end
+ clear_config([:activitypub, :note_replies_output_limit], 2)
test "returns unmodified object if activity doesn't have self-replies" do
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
end
describe "note activity's `replies` collection rendering" do
- clear_config([:activitypub, :note_replies_output_limit]) do
- Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
- end
+ clear_config([:activitypub, :note_replies_output_limit], 5)
test "renders `replies` collection for a note activity" do
user = insert(:user)
end
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
- clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
- Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
- end
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
%{admin: admin} do
end
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
- clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
- Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
- end
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
test "GET /api/pleroma/admin/users/:nickname requires " <>
"read:accounts or admin:read:accounts or broader scope",
end
describe "POST /api/pleroma/admin/email_invite, with valid config" do
- clear_config([:instance, :registrations_open]) do
- Config.put([:instance, :registrations_open], false)
- end
-
- clear_config([:instance, :invites_enabled]) do
- Config.put([:instance, :invites_enabled], true)
- end
+ clear_config([:instance, :registrations_open], false)
+ clear_config([:instance, :invites_enabled], true)
test "sends invitation and returns 204", %{admin: admin, conn: conn} do
recipient_email = "foo@bar.com"
end
describe "GET /api/pleroma/admin/config" do
- clear_config(:configurable_from_database) do
- Config.put(:configurable_from_database, true)
- end
+ clear_config(:configurable_from_database, true)
test "when configuration from database is off", %{conn: conn} do
Config.put(:configurable_from_database, false)
end)
end
- clear_config(:configurable_from_database) do
- Config.put(:configurable_from_database, true)
- end
+ clear_config(:configurable_from_database, true)
@tag capture_log: true
test "create new config setting in db", %{conn: conn} do
end
describe "GET /api/pleroma/admin/restart" do
- clear_config(:configurable_from_database) do
- Config.put(:configurable_from_database, true)
- end
+ clear_config(:configurable_from_database, true)
test "pleroma restarts", %{conn: conn} do
capture_log(fn ->
:ok
end
- clear_config_all([:instance, :federating]) do
- Pleroma.Config.put([:instance, :federating], true)
- end
+ clear_config_all([:instance, :federating], true)
clear_config([:instance, :allow_relay])
clear_config([:instance, :rewrite_policy])
alias Pleroma.Object
alias Pleroma.User
- clear_config([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config([:instance, :federating], true)
describe "feed" do
clear_config([:feed])
import Pleroma.Factory
- clear_config_all([:instance, :federation_reachability_timeout_days]) do
- Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
- end
+ clear_config_all([:instance, :federation_reachability_timeout_days], 1)
describe "set_reachable/1" do
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
use Pleroma.DataCase
- clear_config_all([:instance, :federation_reachability_timeout_days]) do
- Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
- end
+ clear_config_all([:instance, :federation_reachability_timeout_days], 1)
describe "reachable?/1" do
test "returns `true` for host / url with unknown reachability status" do
end
describe "create account by app / rate limit" do
- clear_config([:rate_limit, :app_account_creation]) do
- Pleroma.Config.put([:rate_limit, :app_account_creation], {10_000, 2})
- end
+ clear_config([:rate_limit, :app_account_creation], {10_000, 2})
test "respects rate limit setting", %{conn: conn} do
app_token = insert(:oauth_token, user: nil)
%{activity: activity}
end
- clear_config([:instance, :max_pinned_statuses]) do
- Config.put([:instance, :max_pinned_statuses], 1)
- end
+ clear_config([:instance, :max_pinned_statuses], 1)
test "pin status", %{conn: conn, user: user, activity: activity} do
id_str = to_string(activity.id)
@skip if !Code.ensure_loaded?(:eldap), do: :skip
- clear_config_all([:ldap, :enabled]) do
- Pleroma.Config.put([:ldap, :enabled], true)
- end
+ clear_config_all([:ldap, :enabled], true)
- clear_config_all(Pleroma.Web.Auth.Authenticator) do
- Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
- end
+ clear_config_all(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
@tag @skip
test "authorizes the existing user using LDAP credentials" do
]
end
- clear_config([:auth, :oauth_consumer_strategies]) do
- Pleroma.Config.put(
- [:auth, :oauth_consumer_strategies],
- ~w(twitter facebook)
- )
- end
+ clear_config([:auth, :oauth_consumer_strategies], ~w(twitter facebook))
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
app: app,
:ok
end
- clear_config([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config([:instance, :federating], true)
# Note: see ActivityPubControllerTest for JSON format tests
describe "GET /objects/:uuid (text/html)" do
[user: user]
end
- clear_config([:instance, :account_activation_required]) do
- Config.put([:instance, :account_activation_required], true)
- end
+ clear_config([:instance, :account_activation_required], true)
test "resend account confirmation email", %{conn: conn, user: user} do
conn
"emoji"
)
- clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
- end
+ clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
test "shared & non-shared pack information in list_packs is ok" do
conn = build_conn()
import Pleroma.Factory
- clear_config_all([:static_fe, :enabled]) do
- Config.put([:static_fe, :enabled], true)
- end
+ clear_config_all([:static_fe, :enabled], true)
- clear_config([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config([:instance, :federating], true)
setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
:ok
end
- clear_config_all([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config_all([:instance, :federating], true)
clear_config([:instance])
clear_config([:frontend_configurations, :pleroma_fe])
end
describe "register with one time token" do
- clear_config([:instance, :registrations_open]) do
- Pleroma.Config.put([:instance, :registrations_open], false)
- end
+ clear_config([:instance, :registrations_open], false)
test "returns user on success" do
{:ok, invite} = UserInviteToken.create_invite()
end
describe "registers with date limited token" do
- clear_config([:instance, :registrations_open]) do
- Pleroma.Config.put([:instance, :registrations_open], false)
- end
+ clear_config([:instance, :registrations_open], false)
setup do
data = %{
end
describe "registers with reusable token" do
- clear_config([:instance, :registrations_open]) do
- Pleroma.Config.put([:instance, :registrations_open], false)
- end
+ clear_config([:instance, :registrations_open], false)
test "returns user on success, after him registration fails" do
{:ok, invite} = UserInviteToken.create_invite(%{max_use: 100})
end
describe "registers with reusable date limited token" do
- clear_config([:instance, :registrations_open]) do
- Pleroma.Config.put([:instance, :registrations_open], false)
- end
+ clear_config([:instance, :registrations_open], false)
test "returns user on success" do
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
end
describe "POST /main/ostatus - remote_subscribe/2" do
- clear_config([:instance, :federating]) do
- Config.put([:instance, :federating], true)
- end
+ clear_config([:instance, :federating], true)
test "renders subscribe form", %{conn: conn} do
user = insert(:user)
:ok
end
- clear_config_all([:instance, :federating]) do
- Pleroma.Config.put([:instance, :federating], true)
- end
+ clear_config_all([:instance, :federating], true)
test "GET host-meta" do
response =