mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-09 10:19:19 +00:00
Add tests for extra warnings about media subdomains
This commit is contained in:
parent
4cd299bd83
commit
61621ebdbc
5 changed files with 38 additions and 6 deletions
|
@ -100,9 +100,9 @@ config :pleroma, :config_description, [
|
||||||
label: "Base URL",
|
label: "Base URL",
|
||||||
type: :string,
|
type: :string,
|
||||||
description:
|
description:
|
||||||
"Base URL for the uploads. Required if you use a CDN or host attachments under a different domain.",
|
"Base URL for the uploads. Required if you use a CDN or host attachments under a different domain - it is HIGHLY recommended that you **do not** set this to be the same as the domain akkoma is hosted on.",
|
||||||
suggestions: [
|
suggestions: [
|
||||||
"https://cdn-host.com"
|
"https://media.akkoma.dev/media/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -22,6 +22,7 @@ config :logger, :console,
|
||||||
config :pleroma, :auth, oauth_consumer_strategies: []
|
config :pleroma, :auth, oauth_consumer_strategies: []
|
||||||
|
|
||||||
config :pleroma, Pleroma.Upload,
|
config :pleroma, Pleroma.Upload,
|
||||||
|
base_url: "http://localhost:4001/media/",
|
||||||
filters: [],
|
filters: [],
|
||||||
link_name: false
|
link_name: false
|
||||||
|
|
||||||
|
|
|
@ -602,7 +602,7 @@ the source code is here: [kocaptcha](https://github.com/koto-bank/kocaptcha). Th
|
||||||
* `filters`: List of [upload filters](#upload-filters) to use.
|
* `filters`: List of [upload filters](#upload-filters) to use.
|
||||||
* `link_name`: When enabled Akkoma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers
|
* `link_name`: When enabled Akkoma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers
|
||||||
* `base_url`: The base URL to access a user-uploaded file; MUST be configured explicitly.
|
* `base_url`: The base URL to access a user-uploaded file; MUST be configured explicitly.
|
||||||
Using a (sub)domain distinct from the instance endpoint is **strongly** recommended.
|
Using a (sub)domain distinct from the instance endpoint is **strongly** recommended. A good value might be `https://media.myakkoma.instance/media/`.
|
||||||
* `proxy_remote`: If you're using a remote uploader, Akkoma will proxy media requests instead of redirecting to it.
|
* `proxy_remote`: If you're using a remote uploader, Akkoma will proxy media requests instead of redirecting to it.
|
||||||
* `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation.
|
* `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation.
|
||||||
* `filename_display_max_length`: Set max length of a filename to display. 0 = no limit. Default: 30.
|
* `filename_display_max_length`: Set max length of a filename to display. 0 = no limit. Default: 30.
|
||||||
|
|
|
@ -352,10 +352,11 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
Please make the following change:\n
|
Please make the following change:\n
|
||||||
\n* `config :pleroma, Pleroma.Upload, base_url: "https://example.com/media/`
|
\n* `config :pleroma, Pleroma.Upload, base_url: "https://example.com/media/`
|
||||||
\n
|
\n
|
||||||
\nPlease note that it is HEAVILY recommended to use a subdomain to host user-uploaded media!
|
\nPlease note that it is HEAVILY recommended to use a subdomain to host user-uploaded media!
|
||||||
""")
|
""")
|
||||||
|
|
||||||
:error
|
# This is a hard exit - the uploader will not work without a base_url
|
||||||
|
raise ArgumentError, message: "No base_url set for uploads - please set one in your config!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -369,7 +370,6 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
akkoma_host =
|
akkoma_host =
|
||||||
[Pleroma.Web.Endpoint, :url]
|
[Pleroma.Web.Endpoint, :url]
|
||||||
|> Pleroma.Config.get()
|
|> Pleroma.Config.get()
|
||||||
|> IO.inspect()
|
|
||||||
|> Keyword.get(:host)
|
|> Keyword.get(:host)
|
||||||
|
|
||||||
if uploader_host == akkoma_host do
|
if uploader_host == akkoma_host do
|
||||||
|
|
|
@ -289,4 +289,35 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||||
|
|
||||||
Application.put_env(:tesla, :adapter, Tesla.Mock)
|
Application.put_env(:tesla, :adapter, Tesla.Mock)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "check_uploader_base_url_set/0" do
|
||||||
|
clear_config([Pleroma.Upload], base_url: nil)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
test "check_uploader_base_url_is_not_base_domain/0" 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!"
|
||||||
|
|
||||||
|
clear_config([Pleroma.Upload], base_url: "https://media.localhost")
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue