}
end
+ clear_config([:instance, :limit_to_local_content])
+
test "finds utf8 text in statuses", %{
japanese_activity: japanese_activity,
user: user
%{local_activity: local_activity} do
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
assert [^local_activity] = Activity.search(nil, "find me")
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
test "find all statuses for unauthenticated users when `limit_to_local_content` is `false`",
activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)
assert [^local_activity, ^remote_activity] = activities
-
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
end
describe "headers/2" do
clear_config([:http, :send_user_agent])
+ clear_config([:http, :user_agent])
test "don't send pleroma user agent" do
assert RequestBuilder.headers(%{}, []) == %{headers: []}
describe "delete attachments" do
clear_config([Pleroma.Upload])
+ 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])
+
test "with `admin_token` query parameter", %{conn: conn} do
Pleroma.Config.put(:admin_token, "password123")
clear_config([:http_securiy, :enabled])
clear_config([:http_security, :sts])
+ clear_config([:http_security, :referrer_policy])
describe "http security enabled" do
setup do
alias Pleroma.Plugs.RemoteIp
+ import Pleroma.Tests.Helpers, only: [clear_config: 1, clear_config: 2]
+
+ 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])
+
test "doesn't do anything if the user isn't set", %{conn: conn} do
ret_conn =
conn
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
%{conn: conn} do
- old = Pleroma.Config.get([:instance, :account_activation_required])
Pleroma.Config.put([:instance, :account_activation_required], true)
user = insert(:user, confirmation_pending: true)
|> UserEnabledPlug.call(%{})
assert conn.assigns.user == nil
-
- Pleroma.Config.put([:instance, :account_activation_required], old)
end
test "with a user that is deactivated, it removes that user", %{conn: conn} do
:ok
end
+ 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 ->
capture_log(&Repo.check_migrations_applied!/0)
end
test "doesn't do anything if disabled" do
- disable_migration_check =
- Pleroma.Config.get([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
-
Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
- on_exit(fn ->
- Pleroma.Config.put(
- [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
- disable_migration_check
- )
- end)
-
assert :ok == Repo.check_migrations_applied!()
end
end
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
+ @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
end
describe "User.search" do
+ clear_config([:instance, :limit_to_local_content])
+
test "excluded invisible users from results" do
user = insert(:user, %{nickname: "john t1000"})
insert(:user, %{invisible: true, nickname: "john t800"})
insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
assert [%{id: ^id}] = User.search("lain")
-
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do
|> Enum.sort()
assert [u1.id, u2.id, u3.id] == results
-
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
test "does not yield false-positive matches" do
end
describe "unfollow/2" do
- setup do
- setting = Pleroma.Config.get([:instance, :external_user_synchronization])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :external_user_synchronization], setting)
- end)
-
- :ok
- end
+ 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])
describe "get_cached_by_nickname_or_id" do
setup do
- limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
local_user = insert(:user)
remote_user = insert(:user, nickname: "nickname@example.com", local: false)
- on_exit(fn ->
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
- end)
-
[local_user: local_user, remote_user: remote_user]
end
+ 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
} do
end
describe "deletion" do
+ clear_config([:instance, :rewrite_policy])
+
test "it creates a delete activity and deletes the original object" do
note = insert(:note_activity)
object = Object.normalize(note)
end
test "it passes delete activity through MRF before deleting the object" do
- rewrite_policy = Pleroma.Config.get([:instance, :rewrite_policy])
Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.DropPolicy)
- on_exit(fn -> Pleroma.Config.put([:instance, :rewrite_policy], rewrite_policy) end)
-
note = insert(:note_activity)
object = Object.normalize(note)
end
describe "update" do
+ clear_config([:instance, :max_pinned_statuses])
+
test "it creates an update activity with the new user data" do
user = insert(:user)
{:ok, user} = User.ensure_keys_present(user)
[user: user, message: message]
end
+ clear_config(:mrf_hellthread)
+
describe "reject" do
test "rejects the message if the recipient count is above reject_threshold", %{
message: message
alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+ clear_config(:mrf_keyword)
+
setup do
Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
end
alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
+ clear_config(:mrf_mention)
+
test "pass filter if allow list is empty" do
Pleroma.Config.delete([:mrf_mention])
"object" => %{"content" => "hi"}
}
+ 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], %{
~r/^https:\/\/banned.com/s => [DropPolicy]
end
describe "handle_incoming" do
+ clear_config([:user, :deny_follow_blocked])
+
test "it works for osada follow request" do
user = insert(:user)
end
test "when configuration from database is off", %{conn: conn} do
- initial = Pleroma.Config.get(:configurable_from_database)
Pleroma.Config.put(:configurable_from_database, false)
- on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end)
conn = get(conn, "/api/pleroma/admin/config")
assert json_response(conn, 400) ==
har = insert(:user)
jafnhar = insert(:user)
tridi = insert(:user)
+
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
{:ok, activity} =
import Pleroma.Factory
describe "account fetching" do
+ clear_config([:instance, :limit_to_local_content])
+
test "works by id" do
user = insert(:user)
end
test "works by nickname for remote users" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
Pleroma.Config.put([:instance, :limit_to_local_content], false)
user = insert(:user, nickname: "user@example.com", local: false)
build_conn()
|> get("/api/v1/accounts/#{user.nickname}")
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
assert %{"id" => id} = json_response(conn, 200)
assert id == user.id
end
test "respects limit_to_local_content == :all for remote user nicknames" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
user = insert(:user, nickname: "user@example.com", local: false)
build_conn()
|> get("/api/v1/accounts/#{user.nickname}")
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
assert json_response(conn, 404)
end
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
user = insert(:user, nickname: "user@example.com", local: false)
|> assign(:token, insert(:oauth_token, user: reading_user, scopes: ["read:accounts"]))
|> get("/api/v1/accounts/#{user.nickname}")
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
assert %{"id" => id} = json_response(conn, 200)
assert id == user.id
end
assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
end
+ clear_config([Pleroma.Plugs.RemoteIp, :enabled])
+
test "rate limit", %{conn: conn} do
Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true)
app_token = insert(:oauth_token, user: nil)
clear_config([:instance, :federating])
clear_config([:instance, :allow_relay])
+ clear_config([:rich_media, :enabled])
describe "posting statuses" do
setup do: oauth_access(["write:statuses"])
import Mock
alias Pleroma.Config
- setup do
- media_proxy_config = Config.get([:media_proxy]) || []
- on_exit(fn -> Config.put([:media_proxy], media_proxy_config) end)
- :ok
- end
+ clear_config(:media_proxy)
+ clear_config([Pleroma.Web.Endpoint, :secret_key_base])
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
Config.put([:media_proxy, :enabled], false)
alias Pleroma.Web.MediaProxy.MediaProxyController
clear_config([:media_proxy, :enabled])
+ clear_config(Pleroma.Upload)
describe "when enabled" do
setup do
end
test "ensure Pleroma.Upload base_url is always whitelisted" do
- upload_config = Pleroma.Config.get([Pleroma.Upload])
media_url = "https://media.pleroma.social"
Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
encoded = url(url)
assert String.starts_with?(encoded, media_url)
-
- Pleroma.Config.put([Pleroma.Upload], upload_config)
end
end
end
import Pleroma.Factory
alias Pleroma.Web.Metadata.Providers.OpenGraph
+ 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])
+
test "it renders twitter card for user info" do
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
avatar_url = Utils.attachment_url(User.avatar_url(user))
use Pleroma.Web.ConnCase
import Pleroma.Factory
+
clear_config([:mrf_simple])
+ clear_config(:instance)
test "GET /.well-known/nodeinfo", %{conn: conn} do
links =
end
test "returns fieldsLimits field", %{conn: conn} do
- max_account_fields = Pleroma.Config.get([:instance, :max_account_fields])
- max_remote_account_fields = Pleroma.Config.get([:instance, :max_remote_account_fields])
- account_field_name_length = Pleroma.Config.get([:instance, :account_field_name_length])
- account_field_value_length = Pleroma.Config.get([:instance, :account_field_value_length])
-
Pleroma.Config.put([:instance, :max_account_fields], 10)
Pleroma.Config.put([:instance, :max_remote_account_fields], 15)
Pleroma.Config.put([:instance, :account_field_name_length], 255)
assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
-
- Pleroma.Config.put([:instance, :max_account_fields], max_account_fields)
- Pleroma.Config.put([:instance, :max_remote_account_fields], max_remote_account_fields)
- Pleroma.Config.put([:instance, :account_field_name_length], account_field_name_length)
- Pleroma.Config.put([:instance, :account_field_value_length], account_field_value_length)
end
test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
- test "it shows if federation is enabled/disabled", %{conn: conn} do
- original = Pleroma.Config.get([:instance, :federating])
+ describe "`metadata/federation/enabled`" do
+ clear_config([:instance, :federating])
- Pleroma.Config.put([:instance, :federating], true)
-
- response =
- conn
- |> get("/nodeinfo/2.1.json")
- |> json_response(:ok)
+ test "it shows if federation is enabled/disabled", %{conn: conn} do
+ Pleroma.Config.put([:instance, :federating], true)
- assert response["metadata"]["federation"]["enabled"] == true
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
- Pleroma.Config.put([:instance, :federating], false)
+ assert response["metadata"]["federation"]["enabled"] == true
- response =
- conn
- |> get("/nodeinfo/2.1.json")
- |> json_response(:ok)
+ Pleroma.Config.put([:instance, :federating], false)
- assert response["metadata"]["federation"]["enabled"] == false
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
- Pleroma.Config.put([:instance, :federating], original)
+ assert response["metadata"]["federation"]["enabled"] == false
+ end
end
test "it shows MRF transparency data if enabled", %{conn: conn} do
key: "_test",
signing_salt: "cooldude"
]
- clear_config_all([:instance, :account_activation_required])
+
+ clear_config([:instance, :account_activation_required])
describe "in OAuth consumer mode, " do
setup do
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
- clear_config_all([:instance, :federating])
+
+ clear_config([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
Pleroma.Config.put([:instance, :federating], false)
@streamer_timeout 150
@streamer_start_wait 10
- clear_config_all([:instance, :skip_thread_containment])
+ clear_config([:instance, :skip_thread_containment])
describe "user streams" do
setup do
end
describe "register with one time token" do
- setup do
- setting = Pleroma.Config.get([:instance, :registrations_open])
-
- if setting do
- Pleroma.Config.put([:instance, :registrations_open], false)
- on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end)
- end
-
- :ok
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
end
test "returns user on success" do
end
describe "registers with date limited token" do
- setup do
- setting = Pleroma.Config.get([:instance, :registrations_open])
-
- if setting do
- Pleroma.Config.put([:instance, :registrations_open], false)
- on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end)
- end
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ end
+ setup do
data = %{
"nickname" => "vinny",
"email" => "pasta@pizza.vs",
end
describe "registers with reusable token" do
- setup do
- setting = Pleroma.Config.get([:instance, :registrations_open])
-
- if setting do
- Pleroma.Config.put([:instance, :registrations_open], false)
- on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end)
- end
-
- :ok
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
end
test "returns user on success, after him registration fails" do
end
describe "registers with reusable date limited token" do
- setup do
- setting = Pleroma.Config.get([:instance, :registrations_open])
-
- if setting do
- Pleroma.Config.put([:instance, :registrations_open], false)
- on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end)
- end
-
- :ok
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
end
test "returns user on success" do
clear_config([:instance])
clear_config([:frontend_configurations, :pleroma_fe])
- clear_config([:user, :deny_follow_blocked])
describe "POST /api/pleroma/follow_import" do
setup do: oauth_access(["follow"])