1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.ConfigTest do
8 alias Pleroma.Web.AdminAPI.Config
11 Mix.shell(Mix.Shell.Process)
14 Mix.shell(Mix.Shell.IO)
15 Application.delete_env(:pleroma, :first_setting)
16 Application.delete_env(:pleroma, :second_setting)
22 clear_config_all([:instance, :dynamic_configuration]) do
23 Pleroma.Config.put([:instance, :dynamic_configuration], true)
26 test "settings are migrated to db" do
27 assert Repo.all(Config) == []
29 Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo])
30 Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"])
32 Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
34 config1 = Config.get_by_params(%{group: ":pleroma", key: ":first_setting"})
35 config2 = Config.get_by_params(%{group: ":pleroma", key: ":second_setting"})
36 refute Config.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
38 assert Config.from_binary(config1.value) == [key: "value", key2: [Repo]]
39 assert Config.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
42 test "settings are migrated to file and deleted from db" do
44 config_file = "config/#{env}.exported_from_db.secret.exs"
47 :ok = File.rm(config_file)
52 key: ":setting_first",
53 value: [key: "value", key2: ["Activity"]]
58 key: ":setting_second",
59 value: [key: "value2", key2: [Repo]]
62 Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", env, "-d"])
64 assert Repo.all(Config) == []
66 file = File.read!(config_file)
67 assert file =~ "config :pleroma, :setting_first,"
68 assert file =~ "config :pleroma, :setting_second,"
71 test "load a settings with large values and pass to file", %{temp_file: temp_file} do
77 email: "example@example.com",
78 notify_email: "noreply@example.com",
79 description: "A Pleroma instance, an alternative fediverse server",
82 remote_limit: 100_000,
83 upload_limit: 16_000_000,
84 avatar_upload_limit: 2_000_000,
85 background_upload_limit: 4_000_000,
86 banner_upload_limit: 4_000_000,
89 max_option_chars: 200,
91 max_expiration: 365 * 24 * 60 * 60
93 registrations_open: true,
95 federation_incoming_replies_max_depth: 100,
96 federation_reachability_timeout_days: 7,
97 federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],
99 rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
101 quarantined_instances: [],
102 managed_config: true,
103 static_dir: "instance/static/",
104 allowed_post_formats: ["text/plain", "text/html", "text/markdown", "text/bbcode"],
105 mrf_transparency: true,
106 mrf_transparency_exclusions: [],
107 autofollowed_nicknames: [],
108 max_pinned_statuses: 1,
109 no_attachment_links: true,
110 welcome_user_nickname: nil,
111 welcome_message: nil,
112 max_report_comment_size: 1000,
113 safe_dm_mentions: false,
115 remote_post_retention_days: 90,
116 skip_thread_containment: true,
117 limit_to_local_content: :unauthenticated,
118 dynamic_configuration: false,
119 user_bio_length: 5000,
120 user_name_length: 100,
121 max_account_fields: 10,
122 max_remote_account_fields: 20,
123 account_field_name_length: 512,
124 account_field_value_length: 2048,
125 external_user_synchronization: true,
126 extended_nickname_format: true,
127 multi_factor_authentication: [
141 Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
143 assert Repo.all(Config) == []
144 assert File.exists?(temp_file)
145 {:ok, file} = File.read(temp_file)
148 "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"