diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b13739b..e6fc241d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Upgrade Notes - As mentioned in "Changed", `Pleroma.Upload, :base_url` **MUST** be configured. Uploads will fail without it. + - Akkoma will refuse to start if this is not set. - Same with media proxy. ## 2024.02 diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index d07f3dfe8..c299a4947 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -341,9 +341,10 @@ def check_uploders_s3_public_endpoint do end def check_uploader_base_url_set() do + uses_local_uploader? = Config.get([Pleroma.Upload, :uploader]) == Pleroma.Uploaders.Local base_url = Pleroma.Config.get([Pleroma.Upload, :base_url]) - if base_url do + if base_url || !uses_local_uploader? do :ok else Logger.error(""" @@ -361,6 +362,8 @@ def check_uploader_base_url_set() do end def check_uploader_base_url_is_not_base_domain() do + uses_local_uploader? = Config.get([Pleroma.Upload, :uploader]) == Pleroma.Uploaders.Local + uploader_host = [Pleroma.Upload, :base_url] |> Pleroma.Config.get() @@ -372,7 +375,7 @@ def check_uploader_base_url_is_not_base_domain() do |> Pleroma.Config.get() |> Keyword.get(:host) - if uploader_host == akkoma_host do + if uploader_host == akkoma_host && uses_local_uploader? do Logger.error(""" !!!WARNING!!! Your Akkoma Host and your Upload base_url's host are the same! diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs index 4b90a4c24..96d6fd739 100644 --- a/test/pleroma/config/deprecation_warnings_test.exs +++ b/test/pleroma/config/deprecation_warnings_test.exs @@ -290,38 +290,63 @@ test "check_http_adapter/0" do Application.put_env(:tesla, :adapter, Tesla.Mock) end - test "check_uploader_base_url_set/0" do - clear_config([Pleroma.Upload, :base_url], nil) + describe "check_uploader_base_url_set/0" do + test "should error if the base_url is not set" do + clear_config([Pleroma.Upload, :base_url], nil) - # we need to capture the error - assert_raise ArgumentError, fn -> - assert capture_log(fn -> + # we need to capture the error + assert_raise ArgumentError, fn -> + assert capture_log(fn -> + DeprecationWarnings.check_uploader_base_url_set() + end) =~ "Your config does not specify a base_url for uploads!" + end + end + + test "should not error if the base_url is set" do + clear_config([Pleroma.Upload, :base_url], "https://example.com") + + refute capture_log(fn -> DeprecationWarnings.check_uploader_base_url_set() end) =~ "Your config does not specify a base_url for uploads!" end - clear_config([Pleroma.Upload, :base_url], "https://example.com") + test "should not error if local uploader is not used" do + clear_config([Pleroma.Upload, :base_url], nil) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) - refute capture_log(fn -> - DeprecationWarnings.check_uploader_base_url_set() - end) =~ "Your config does not specify a base_url for uploads!" - - clear_config([Pleroma.Upload, :base_url]) + refute capture_log(fn -> + DeprecationWarnings.check_uploader_base_url_set() + end) =~ "Your config does not specify a base_url for uploads!" + end end - test "check_uploader_base_url_is_not_base_domain/0" do - clear_config([Pleroma.Upload, :base_url], "http://localhost") + describe "check_uploader_base_url_is_not_base_domain/0" do + test "should error if the akkoma domain is the same as the upload domain" do + clear_config([Pleroma.Upload, :base_url], "http://localhost") - assert capture_log(fn -> - DeprecationWarnings.check_uploader_base_url_is_not_base_domain() - end) =~ "Your Akkoma Host and your Upload base_url's host are the same!" + assert capture_log(fn -> + DeprecationWarnings.check_uploader_base_url_is_not_base_domain() + end) =~ "Your Akkoma Host and your Upload base_url's host are the same!" + end - clear_config([Pleroma.Upload, :base_url], "https://media.localhost") + test "should not error if the local uploader is not used" do + clear_config([Pleroma.Upload, :base_url], "http://localhost") + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) - refute capture_log(fn -> - DeprecationWarnings.check_uploader_base_url_is_not_base_domain() - end) =~ "Your Akkoma Host and your Upload base_url's host are the same!" + refute capture_log(fn -> + DeprecationWarnings.check_uploader_base_url_is_not_base_domain() + end) =~ "Your Akkoma Host and your Upload base_url's host are the same!" + end - clear_config([Pleroma.Upload, :base_url]) + test "should not error if the akkoma domain is different from the upload domain" do + clear_config([Pleroma.Upload, :base_url], "https://media.localhost") + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + + refute capture_log(fn -> + DeprecationWarnings.check_uploader_base_url_is_not_base_domain() + end) =~ "Your Akkoma Host and your Upload base_url's host are the same!" + + clear_config([Pleroma.Upload, :base_url]) + end end end