alias Pleroma.ActivityExpiration
import Pleroma.Factory
- clear_config([ActivityExpiration, :enabled])
+ setup do: clear_config([ActivityExpiration, :enabled])
test "finds activities due to be deleted only" do
activity = insert(:note_activity)
}
end
- clear_config([:instance, :limit_to_local_content])
+ setup do: clear_config([:instance, :limit_to_local_content])
test "finds utf8 text in statuses", %{
japanese_activity: japanese_activity,
alias Pleroma.Captcha.Native
@ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
-
- clear_config([Pleroma.Captcha, :enabled])
+ setup do: clear_config([Pleroma.Captcha, :enabled])
describe "Kocaptcha" do
setup do
alias Pleroma.Config.TransferTask
alias Pleroma.ConfigDB
- clear_config(:configurable_from_database, true)
+ setup do: 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], true)
+ setup_all do: clear_config([:instance, :federating], true)
test "it goes through old direct conversations" do
user = insert(:user)
subject: "Pleroma test email",
to: [{"Test User", "user1@example.com"}]
}
-
- clear_config([Pleroma.Emails.Mailer, :enabled])
+ setup do: clear_config([Pleroma.Emails.Mailer, :enabled])
test "not send email when mailer is disabled" do
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
alias Pleroma.HTTP.RequestBuilder
describe "headers/2" do
- clear_config([:http, :send_user_agent])
- clear_config([:http, :user_agent])
+ setup do: clear_config([:http, :send_user_agent])
+ setup do: clear_config([:http, :user_agent])
test "don't send pleroma user agent" do
assert RequestBuilder.headers(%{}, []) == %{headers: []}
describe "max thread distance restriction" do
@ap_id "http://mastodon.example.org/@admin/99541947525187367"
-
- clear_config([:instance, :federation_incoming_replies_max_depth])
+ setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
test "it returns thread depth exceeded error if thread depth is exceeded" do
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
end
describe "signed fetches" do
- clear_config([:activitypub, :sign_object_fetches])
+ setup do: clear_config([:activitypub, :sign_object_fetches])
test_with_mock "it signs fetches when configured to do so",
Pleroma.Signature,
end
describe "delete attachments" do
- clear_config([Pleroma.Upload])
- clear_config([:instance, :cleanup_attachments])
+ setup do: clear_config([Pleroma.Upload])
+ setup do: clear_config([:instance, :cleanup_attachments])
test "Disabled via config" do
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
end
describe "when secret set it assigns an admin user" do
- clear_config([:admin_token])
+ setup do: clear_config([:admin_token])
test "with `admin_token` query parameter", %{conn: conn} do
Pleroma.Config.put(:admin_token, "password123")
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.User
- clear_config([:instance, :public])
+ 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)
alias Pleroma.Config
alias Plug.Conn
- clear_config([:http_securiy, :enabled])
- clear_config([:http_security, :sts])
- clear_config([:http_security, :referrer_policy])
+ setup do: clear_config([:http_securiy, :enabled])
+ setup do: clear_config([:http_security, :sts])
+ setup do: clear_config([:http_security, :referrer_policy])
describe "http security enabled" do
setup do
on_exit(fn -> File.rm_rf(@dir) end)
end
- clear_config([:instance, :static_dir], @dir)
+ setup do: clear_config([:instance, :static_dir], @dir)
test "overrides index" do
bundled_index = get(build_conn(), "/")
end
describe "transform_scopes/2" do
- clear_config([:auth, :enforce_oauth_admin_scope_usage])
+ setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage])
setup do
{:ok, %{f: &OAuthScopesPlug.transform_scopes/2}}
import Pleroma.Tests.Helpers, only: [clear_config: 1, clear_config: 2]
# Note: each example must work with separate buckets in order to prevent concurrency issues
-
- clear_config([Pleroma.Web.Endpoint, :http, :ip])
- clear_config(:rate_limit)
+ setup do: clear_config([Pleroma.Web.Endpoint, :http, :ip])
+ setup do: clear_config(:rate_limit)
describe "config" do
@limiter_name :test_init
-
- clear_config([Pleroma.Plugs.RemoteIp, :enabled])
+ setup do: clear_config([Pleroma.Plugs.RemoteIp, :enabled])
test "config is required for plug to work" do
Config.put([:rate_limit, @limiter_name], {1, 1})
alias Pleroma.Plugs.RemoteIp
import Pleroma.Tests.Helpers, only: [clear_config: 1, clear_config: 2]
-
- clear_config(RemoteIp)
+ setup do: clear_config(RemoteIp)
test "disabled" do
Pleroma.Config.put(RemoteIp, enabled: false)
alias Pleroma.Plugs.UserEnabledPlug
import Pleroma.Factory
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "doesn't do anything if the user isn't set", %{conn: conn} do
ret_conn =
import Pleroma.Factory
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
- clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
+ setup do: 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], true)
+ setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
setup do
admin_user = insert(:user, is_admin: true)
:ok
end
- clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
+ setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
test "raises if it detects unapplied migrations" do
assert_raise Pleroma.Repo.UnappliedMigrationsError, fn ->
alias Pleroma.ScheduledActivity
import Pleroma.Factory
- clear_config([ScheduledActivity, :enabled])
+ setup do: clear_config([ScheduledActivity, :enabled])
setup context do
DataCase.ensure_local_uploader(context)
defmacro clear_config(config_path, do: yield) do
quote do
- setup do
- initial_setting = Config.get(unquote(config_path))
- unquote(yield)
- on_exit(fn -> Config.put(unquote(config_path), initial_setting) end)
- :ok
- end
+ initial_setting = Config.get(unquote(config_path))
+ unquote(yield)
+ on_exit(fn -> Config.put(unquote(config_path), initial_setting) end)
+ :ok
end
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
- clear_config_all(unquote(config_path)) do
- end
- end
- end
-
- @doc """
- Stores initial config value and restores it after *all* test examples are executed.
- Only use if *all* test examples should work with the same stubbed value
- (*no* examples set a different value).
- """
- defmacro clear_config_all(config_path, do: yield) do
- quote do
- setup_all do
- initial_setting = Config.get(unquote(config_path))
- unquote(yield)
- on_exit(fn -> Config.put(unquote(config_path), initial_setting) end)
- :ok
- end
- 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,
only: [
clear_config: 1,
- clear_config: 2,
- clear_config_all: 1,
- clear_config_all: 2,
- set_config: 2
+ clear_config: 2
]
def to_datetime(naive_datetime) do
:ok
end
- clear_config_all(:configurable_from_database, true)
+ setup_all do: clear_config(: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")
use Pleroma.Tests.Helpers
alias Mix.Tasks.Pleroma.RobotsTxt
- clear_config([:instance, :static_dir])
+ setup do: clear_config([:instance, :static_dir])
test "creates new dir" do
path = "test/fixtures/new_dir/"
%{upload_file: upload_file}
end
- clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
+ 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")
alias Pleroma.Upload
alias Pleroma.Upload.Filter
- clear_config([Filter.Mogrify, :args])
+ setup do: clear_config([Filter.Mogrify, :args])
test "apply mogrify filter" do
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
alias Pleroma.Config
alias Pleroma.Upload.Filter
- clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
+ setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "applies filters" do
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
end
describe "Setting a custom base_url for uploaded media" do
- clear_config([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
+ setup do: 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,
- bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com"
- )
+ setup do:
+ 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
end
describe "User.search" do
- clear_config([:instance, :limit_to_local_content])
+ setup do: clear_config([:instance, :limit_to_local_content])
test "excluded invisible users from results" do
user = insert(:user, %{nickname: "john t1000"})
:ok
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
describe "service actors" do
test "returns updated invisible actor" do
end
describe "unfollow/2" do
- clear_config([:instance, :external_user_synchronization])
+ setup do: clear_config([:instance, :external_user_synchronization])
test "unfollow with syncronizes external user" do
Pleroma.Config.put([:instance, :external_user_synchronization], true)
password_confirmation: "test",
email: "email@example.com"
}
-
- clear_config([:instance, :autofollowed_nicknames])
- clear_config([:instance, :welcome_message])
- clear_config([:instance, :welcome_user_nickname])
+ setup do: clear_config([:instance, :autofollowed_nicknames])
+ setup do: clear_config([:instance, :welcome_message])
+ setup do: clear_config([:instance, :welcome_user_nickname])
test "it autofollows accounts that are set for it" do
user = insert(:user)
assert activity.actor == welcome_user.ap_id
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
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)
password_confirmation: "test",
email: "email@example.com"
}
-
- clear_config([:instance, :account_activation_required], true)
+ setup do: clear_config([:instance, :account_activation_required], true)
test "it creates unconfirmed user" do
changeset = User.register_changeset(%User{}, @full_user_data)
ap_id: "http...",
avatar: %{some: "avatar"}
}
-
- clear_config([:instance, :user_bio_length])
- clear_config([:instance, :user_name_length])
+ setup do: clear_config([:instance, :user_bio_length])
+ setup do: clear_config([:instance, :user_name_length])
test "it confirms validity" do
cs = User.remote_user_creation(@valid_remote)
[user: user]
end
- clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :federating])
test ".delete_user_activities deletes all create activities", %{user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
end
describe "account_status/1" do
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "return confirmation_pending for unconfirm user" do
Pleroma.Config.put([:instance, :account_activation_required], true)
end
describe "following/followers synchronization" do
- clear_config([:instance, :external_user_synchronization])
+ 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)
[local_user: local_user, remote_user: remote_user]
end
- clear_config([:instance, :limit_to_local_content])
+ setup do: clear_config([:instance, :limit_to_local_content])
test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
remote_user: remote_user
:ok
end
- clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance, :federating], true)
describe "/relay" do
- clear_config([:instance, :allow_relay])
+ setup do: clear_config([:instance, :allow_relay])
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
|> json_response(403)
end
- clear_config([:media_proxy])
- clear_config([Pleroma.Upload])
+ setup do: clear_config([:media_proxy])
+ setup do: clear_config([Pleroma.Upload])
test "POST /api/ap/upload_media", %{conn: conn} do
user = insert(:user)
:ok
end
- clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :federating])
describe "streaming out participations" do
test "it streams them out" do
end
describe "deletion" do
- clear_config([:instance, :rewrite_policy])
+ setup do: clear_config([:instance, :rewrite_policy])
test "it reverts deletion on error" do
note = insert(:note_activity)
end
describe "update" do
- clear_config([:instance, :max_pinned_statuses])
+ setup do: clear_config([:instance, :max_pinned_statuses])
test "it creates an update activity with the new user data" do
user = insert(:user)
[user: user, message: message]
end
- clear_config(:mrf_hellthread)
+ setup do: clear_config(:mrf_hellthread)
describe "reject" do
test "rejects the message if the recipient count is above reject_threshold", %{
alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy
- clear_config(:mrf_keyword)
+ setup do: clear_config(:mrf_keyword)
setup do
Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
- clear_config(:mrf_mention)
+ setup do: clear_config(:mrf_mention)
test "pass filter if allow list is empty" do
Pleroma.Config.delete([:mrf_mention])
end
describe "describe/0" do
- clear_config([:instance, :rewrite_policy])
+ setup do: clear_config([:instance, :rewrite_policy])
test "it works as expected with noop policy" do
expected = %{
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
alias Pleroma.Web.ActivityPub.Visibility
- clear_config(:mrf_object_age,
- threshold: 172_800,
- actions: [:delist, :strip_followers]
- )
+ setup do:
+ 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.Web.ActivityPub.MRF.RejectNonPublic
- clear_config([:mrf_rejectnonpublic])
+ setup do: clear_config([:mrf_rejectnonpublic])
describe "public message" do
test "it's allowed when address is public" do
alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
- clear_config(:mrf_simple,
- media_removal: [],
- media_nsfw: [],
- federated_timeline_removal: [],
- report_removal: [],
- reject: [],
- accept: [],
- avatar_removal: [],
- banner_removal: []
- )
+ setup do:
+ 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
"type" => "Create",
"object" => %{"content" => "hi"}
}
-
- clear_config([:mrf_subchain, :match_actor])
+ 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], %{
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
- clear_config([:mrf_user_allowlist, :localhost])
+ setup do: clear_config([:mrf_user_allowlist, :localhost])
test "pass filter if allow list is empty" do
actor = insert(:user)
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
describe "accept" do
- clear_config([:mrf_vocabulary, :accept])
+ setup do: clear_config([:mrf_vocabulary, :accept])
test "it accepts based on parent activity type" do
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
end
describe "reject" do
- clear_config([:mrf_vocabulary, :reject])
+ setup do: clear_config([:mrf_vocabulary, :reject])
test "it rejects based on parent activity type" do
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
:ok
end
- clear_config_all([:instance, :federating], true)
+ setup_all do: clear_config([:instance, :federating], true)
describe "gather_webfinger_links/1" do
test "it returns links" do
end
describe "publish/1" do
- clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :federating])
test "returns error when activity not `Create` type" do
activity = insert(:like_activity)
end
describe "handle_incoming" do
- clear_config([:user, :deny_follow_blocked])
+ setup do: clear_config([:user, :deny_follow_blocked])
test "it works for osada follow request" do
user = insert(:user)
:ok
end
- clear_config([:instance, :max_remote_account_fields])
+ setup do: clear_config([:instance, :max_remote_account_fields])
describe "handle_incoming" do
test "it ignores an incoming notice if we already have it" do
end
describe "`handle_incoming/2`, Mastodon format `replies` handling" do
- clear_config([:activitypub, :note_replies_output_limit], 5)
-
- clear_config([:instance, :federation_incoming_replies_max_depth])
+ setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
+ setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
setup do
data =
end
describe "`handle_incoming/2`, Pleroma format `replies` handling" do
- clear_config([:activitypub, :note_replies_output_limit], 5)
-
- clear_config([:instance, :federation_incoming_replies_max_depth])
+ setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
+ setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
setup do
user = insert(:user)
end
describe "fix_in_reply_to/2" do
- clear_config([:instance, :federation_incoming_replies_max_depth])
+ setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
setup do
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
end
describe "set_replies/1" do
- clear_config([:activitypub, :note_replies_output_limit], 2)
+ setup do: 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], 5)
+ setup do: 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], true)
+ setup do: 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], false)
+ setup do: 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], false)
- clear_config([:instance, :invites_enabled], true)
+ setup do: clear_config([:instance, :registrations_open], false)
+ setup do: clear_config([:instance, :invites_enabled], true)
test "sends invitation and returns 204", %{admin: admin, conn: conn} do
recipient_email = "foo@bar.com"
end
describe "POST /api/pleroma/admin/users/email_invite, with invalid config" do
- clear_config([:instance, :registrations_open])
- clear_config([:instance, :invites_enabled])
+ setup do: clear_config([:instance, :registrations_open])
+ 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)
end
describe "GET /api/pleroma/admin/config" do
- clear_config(:configurable_from_database, true)
+ setup do: 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, true)
+ setup do: 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, true)
+ setup do: clear_config(:configurable_from_database, true)
test "pleroma restarts", %{conn: conn} do
capture_log(fn ->
end
describe "message lengths" do
- clear_config([:instance, :chat_limit])
+ setup do: clear_config([:instance, :chat_limit])
test "it ignores messages of length zero", %{socket: socket} do
push(socket, "new_msg", %{"text" => ""})
require Pleroma.Constants
- clear_config([:instance, :safe_dm_mentions])
- clear_config([:instance, :limit])
- clear_config([:instance, :max_pinned_statuses])
+ setup do: clear_config([:instance, :safe_dm_mentions])
+ setup do: clear_config([:instance, :limit])
+ setup do: clear_config([:instance, :max_pinned_statuses])
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
:ok
end
- clear_config_all([:instance, :federating], true)
-
- clear_config([:instance, :allow_relay])
- clear_config([:instance, :rewrite_policy])
- clear_config([:mrf_keyword])
+ setup_all do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance, :allow_relay])
+ setup do: clear_config([:instance, :rewrite_policy])
+ setup do: clear_config([:mrf_keyword])
describe "Publish an activity" do
setup do
alias Pleroma.Web.Feed.FeedView
- clear_config([:feed])
+ setup do: clear_config([:feed])
test "gets a feed (ATOM)", %{conn: conn} do
Pleroma.Config.put(
alias Pleroma.Object
alias Pleroma.User
- clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance, :federating], true)
describe "feed" do
- clear_config([:feed])
+ setup do: clear_config([:feed])
test "gets a feed", %{conn: conn} do
Config.put(
import Pleroma.Factory
- clear_config_all([:instance, :federation_reachability_timeout_days], 1)
+ setup_all do: clear_config([: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], 1)
+ setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
describe "reachable?/1" do
test "returns `true` for host / url with unknown reachability status" do
import Pleroma.Factory
- clear_config([:instance, :public])
+ setup do: clear_config([:instance, :public])
test "put settings", %{conn: conn} do
user = insert(:user)
use Pleroma.Web.ConnCase
import Pleroma.Factory
- clear_config([:instance, :max_account_fields])
+
+ setup do: clear_config([:instance, :max_account_fields])
describe "updating credentials" do
setup do: oauth_access(["write:accounts"])
import Pleroma.Factory
describe "account fetching" do
- clear_config([:instance, :limit_to_local_content])
+ setup do: clear_config([:instance, :limit_to_local_content])
test "works by id" do
user = insert(:user)
describe "user fetching with restrict unauthenticated profiles for local and remote" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
describe "user fetching with restrict unauthenticated profiles for local" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
describe "user fetching with restrict unauthenticated profiles for remote" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
[valid_params: valid_params]
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "Account registration via Application", %{conn: conn} do
conn =
end)
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "returns bad_request if missing email params when :account_activation_required is enabled",
%{conn: conn, valid_params: valid_params} do
end
describe "create account by app / rate limit" do
- clear_config([:rate_limit, :app_account_creation], {10_000, 2})
+ setup do: 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)
[image: image]
end
- clear_config([:media_proxy])
- clear_config([Pleroma.Upload])
+ setup do: clear_config([:media_proxy])
+ setup do: clear_config([Pleroma.Upload])
test "returns uploaded image", %{conn: conn, image: image} do
desc = "Description of the image"
import Pleroma.Factory
import Ecto.Query
- clear_config([ScheduledActivity, :enabled])
+ setup do: clear_config([ScheduledActivity, :enabled])
test "shows scheduled activities" do
%{user: user, conn: conn} = oauth_access(["read:statuses"])
import Pleroma.Factory
- clear_config([:instance, :federating])
- clear_config([:instance, :allow_relay])
- clear_config([:rich_media, :enabled])
+ setup do: clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :allow_relay])
+ setup do: clear_config([:rich_media, :enabled])
describe "posting statuses" do
setup do: oauth_access(["write:statuses"])
describe "status with restrict unauthenticated activities for local and remote" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :local]) do
- Config.put([:restrict_unauthenticated, :activities, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
- clear_config([:restrict_unauthenticated, :activities, :remote]) do
- Config.put([:restrict_unauthenticated, :activities, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
describe "status with restrict unauthenticated activities for local" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :local]) do
- Config.put([:restrict_unauthenticated, :activities, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
describe "status with restrict unauthenticated activities for remote" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :remote]) do
- Config.put([:restrict_unauthenticated, :activities, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :local]) do
- Config.put([:restrict_unauthenticated, :activities, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
- clear_config([:restrict_unauthenticated, :activities, :remote]) do
- Config.put([:restrict_unauthenticated, :activities, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
describe "getting statuses by ids with restricted unauthenticated for local" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :local]) do
- Config.put([:restrict_unauthenticated, :activities, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
describe "getting statuses by ids with restricted unauthenticated for remote" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :activities, :remote]) do
- Config.put([:restrict_unauthenticated, :activities, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
%{activity: activity}
end
- clear_config([:instance, :max_pinned_statuses], 1)
+ setup do: clear_config([:instance, :max_pinned_statuses], 1)
test "pin status", %{conn: conn, user: user, activity: activity} do
id_str = to_string(activity.id)
describe "public with restrict unauthenticated timeline for local and federated timelines" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :timelines, :local]) do
- Config.put([:restrict_unauthenticated, :timelines, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
- clear_config([:restrict_unauthenticated, :timelines, :federated]) do
- Config.put([:restrict_unauthenticated, :timelines, :federated], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
test "if user is unauthenticated", %{conn: conn} do
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
describe "public with restrict unauthenticated timeline for local" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :timelines, :local]) do
- Config.put([:restrict_unauthenticated, :timelines, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
test "if user is unauthenticated", %{conn: conn} do
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
describe "public with restrict unauthenticated timeline for remote" do
setup do: local_and_remote_activities()
- clear_config([:restrict_unauthenticated, :timelines, :federated]) do
- Config.put([:restrict_unauthenticated, :timelines, :federated], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
test "if user is unauthenticated", %{conn: conn} do
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
import Mock
alias Pleroma.Config
- clear_config(:media_proxy)
- clear_config([Pleroma.Web.Endpoint, :secret_key_base])
+ setup do: clear_config(:media_proxy)
+ setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base])
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
Config.put([:media_proxy, :enabled], false)
import Pleroma.Web.MediaProxy
alias Pleroma.Web.MediaProxy.MediaProxyController
- clear_config([:media_proxy, :enabled])
- clear_config(Pleroma.Upload)
+ setup do: clear_config([:media_proxy, :enabled])
+ setup do: clear_config(Pleroma.Upload)
describe "when enabled" do
setup do
import Pleroma.Factory
alias Pleroma.Web.Metadata.Providers.OpenGraph
- clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
+ setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
test "it renders all supported types of attachments and skips unknown types" do
user = insert(:user)
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router
- clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
+ setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
test "it renders twitter card for user info" do
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
import Pleroma.Factory
- clear_config([:mrf_simple])
- clear_config(:instance)
+ setup do: clear_config([:mrf_simple])
+ setup do: clear_config(:instance)
test "GET /.well-known/nodeinfo", %{conn: conn} do
links =
end
describe "`metadata/federation/enabled`" do
- clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :federating])
test "it shows if federation is enabled/disabled", %{conn: conn} do
Pleroma.Config.put([:instance, :federating], true)
@skip if !Code.ensure_loaded?(:eldap), do: :skip
- clear_config_all([:ldap, :enabled], true)
+ setup_all do: clear_config([:ldap, :enabled], true)
- clear_config_all(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
+ setup_all do: clear_config(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
@tag @skip
test "authorizes the existing user using LDAP credentials" do
key: "_test",
signing_salt: "cooldude"
]
-
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
describe "in OAuth consumer mode, " do
setup do
]
end
- clear_config([:auth, :oauth_consumer_strategies], ~w(twitter facebook))
+ setup do: clear_config([:auth, :oauth_consumer_strategies], ~w(twitter facebook))
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
app: app,
end
describe "POST /oauth/token - refresh token" do
- clear_config([:oauth2, :issue_new_refresh_token])
+ 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)
:ok
end
- clear_config([:instance, :federating], true)
+ setup do: 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], true)
+ setup do: clear_config([:instance, :account_activation_required], true)
test "resend account confirmation email", %{conn: conn, user: user} do
conn
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
)
-
- clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
+ setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
test "shared & non-shared pack information in list_packs is ok" do
conn = build_conn()
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
- clear_config([:instance, :federating])
+ setup do: clear_config([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
Pleroma.Config.put([:instance, :federating], false)
:ok
end
- clear_config([:rich_media, :enabled])
+ setup do: clear_config([:rich_media, :enabled])
test "refuses to crawl incomplete URLs" do
user = insert(:user)
import Pleroma.Factory
- clear_config_all([:static_fe, :enabled], true)
-
- clear_config([:instance, :federating], true)
+ setup_all do: clear_config([:static_fe, :enabled], true)
+ setup do: clear_config([:instance, :federating], true)
setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
@streamer_timeout 150
@streamer_start_wait 10
-
- clear_config([:instance, :skip_thread_containment])
+ setup do: clear_config([:instance, :skip_thread_containment])
describe "user streams" do
setup do
:ok
end
- clear_config_all([:instance, :federating], true)
-
- clear_config([:instance])
- clear_config([:frontend_configurations, :pleroma_fe])
- clear_config([:user, :deny_follow_blocked])
+ setup_all do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance])
+ setup do: clear_config([:frontend_configurations, :pleroma_fe])
+ setup do: clear_config([:user, :deny_follow_blocked])
describe "GET /ostatus_subscribe - remote_follow/2" do
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
end
describe "register with one time token" do
- clear_config([:instance, :registrations_open], false)
+ setup do: 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], false)
+ setup do: clear_config([:instance, :registrations_open], false)
setup do
data = %{
end
describe "registers with reusable token" do
- clear_config([:instance, :registrations_open], false)
+ setup do: 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], false)
+ setup do: 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})
:ok
end
- clear_config([:instance])
- clear_config([:frontend_configurations, :pleroma_fe])
+ setup do: clear_config([:instance])
+ setup do: clear_config([:frontend_configurations, :pleroma_fe])
describe "POST /api/pleroma/follow_import" do
setup do: oauth_access(["follow"])
end
describe "GET /api/pleroma/healthcheck" do
- clear_config([:instance, :healthcheck])
+ setup do: clear_config([:instance, :healthcheck])
test "returns 503 when healthcheck disabled", %{conn: conn} do
Config.put([:instance, :healthcheck], false)
end
describe "POST /main/ostatus - remote_subscribe/2" do
- clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance, :federating], true)
test "renders subscribe form", %{conn: conn} do
user = insert(:user)
:ok
end
- clear_config_all([:instance, :federating], true)
+ setup_all do: clear_config([:instance, :federating], true)
test "GET host-meta" do
response =
import Pleroma.Factory
alias Pleroma.Workers.Cron.ClearOauthTokenWorker
- clear_config([:oauth2, :clean_expired_tokens])
+ setup do: clear_config([:oauth2, :clean_expired_tokens])
test "deletes expired tokens" do
insert(:oauth_token,
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- clear_config([:email_notifications, :digest])
+ setup do: clear_config([:email_notifications, :digest])
setup do
Pleroma.Config.put([:email_notifications, :digest], %{
import Pleroma.Factory
import ExUnit.CaptureLog
- clear_config([ActivityExpiration, :enabled])
+ setup do: clear_config([ActivityExpiration, :enabled])
test "deletes an expiration activity" do
Pleroma.Config.put([ActivityExpiration, :enabled], true)
import Pleroma.Factory
import ExUnit.CaptureLog
- clear_config([ScheduledActivity, :enabled])
+ setup do: clear_config([ScheduledActivity, :enabled])
test "creates a status from the scheduled activity" do
Pleroma.Config.put([ScheduledActivity, :enabled], true)