From 67d7c6522c540e6da6ea380eddea2b8816a9503e Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Fri, 6 Sep 2024 15:31:23 +0700 Subject: [PATCH] Change SMTP defaults (#4538) * default smtp config updates * tests * improve SMTP_MIDDLEBOX_COMP_MODE decoding * changelog * format --------- Co-authored-by: Adrian Gruntkowski --- CHANGELOG.md | 2 ++ config/runtime.exs | 11 ++++++++-- test/plausible/config_test.exs | 40 +++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6be775c4ce4..0af8054c5d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,8 @@ All notable changes to this project will be documented in this file. - Replace `CLICKHOUSE_MAX_BUFFER_SIZE` with `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES` - Validate metric isn't queried multiple times - Filters in dashboard are represented by jsonurl +- `MAILER_EMAIL` now defaults to an address built off of `BASE_URL` plausible/analytics#4538 +- default `MAILER_ADAPTER` has been changed to `Bamboo.Mua` plausible/analytics#4538 ### Fixed - Creating many sites no longer leads to cookie overflow diff --git a/config/runtime.exs b/config/runtime.exs index 4850783d8114..16ac1f6310d9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -99,8 +99,8 @@ super_admin_user_ids = |> Enum.filter(& &1) env = get_var_from_path_or_env(config_dir, "ENVIRONMENT", "prod") -mailer_adapter = get_var_from_path_or_env(config_dir, "MAILER_ADAPTER", "Bamboo.SMTPAdapter") -mailer_email = get_var_from_path_or_env(config_dir, "MAILER_EMAIL", "hello@plausible.local") +mailer_adapter = get_var_from_path_or_env(config_dir, "MAILER_ADAPTER", "Bamboo.Mua") +mailer_email = get_var_from_path_or_env(config_dir, "MAILER_EMAIL", "plausible@#{base_url.host}") mailer_email = if mailer_name = get_var_from_path_or_env(config_dir, "MAILER_NAME") do @@ -536,6 +536,13 @@ case mailer_adapter do "Bamboo.Mua" -> config :plausible, Plausible.Mailer, adapter: Bamboo.Mua + # prevents common problems with Erlang's TLS v1.3 + middlebox_comp_mode = + get_var_from_path_or_env(config_dir, "SMTP_MIDDLEBOX_COMP_MODE", "false") + + middlebox_comp_mode = String.to_existing_atom(middlebox_comp_mode) + config :plausible, Plausible.Mailer, ssl: [middlebox_comp_mode: middlebox_comp_mode] + if relay = get_var_from_path_or_env(config_dir, "SMTP_HOST_ADDR") do port = get_int_from_path_or_env(config_dir, "SMTP_HOST_PORT", 25) config :plausible, Plausible.Mailer, relay: relay, port: port diff --git a/test/plausible/config_test.exs b/test/plausible/config_test.exs index 75da84bd79d5..920b0d58e17f 100644 --- a/test/plausible/config_test.exs +++ b/test/plausible/config_test.exs @@ -4,7 +4,14 @@ defmodule Plausible.ConfigTest do describe "mailer" do test "mailer email default" do env = [{"MAILER_EMAIL", nil}] - assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "hello@plausible.local" + assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "plausible@localhost" + end + + test "mailer email from base url" do + env = [{"MAILER_EMAIL", nil}, {"BASE_URL", "https://plausible.example.com:8443"}] + + assert get_in(runtime_config(env), [:plausible, :mailer_email]) == + "plausible@plausible.example.com" end test "mailer email custom" do @@ -16,7 +23,7 @@ defmodule Plausible.ConfigTest do env = [{"MAILER_EMAIL", nil}, {"MAILER_NAME", "John"}] assert get_in(runtime_config(env), [:plausible, :mailer_email]) == - {"John", "hello@plausible.local"} + {"John", "plausible@localhost"} env = [{"MAILER_EMAIL", "custom@mailer.email"}, {"MAILER_NAME", "John"}] @@ -24,21 +31,12 @@ defmodule Plausible.ConfigTest do {"John", "custom@mailer.email"} end - test "defaults to Bamboo.SMTPAdapter" do + test "defaults to Bamboo.Mua" do env = {"MAILER_ADAPTER", nil} assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [ - adapter: Bamboo.SMTPAdapter, - server: "mail", - hostname: "localhost", - port: "25", - username: nil, - password: nil, - tls: :if_available, - allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"], - ssl: false, - retries: 2, - no_mx_lookups: true + adapter: Bamboo.Mua, + ssl: [middlebox_comp_mode: false] ] end @@ -144,7 +142,17 @@ defmodule Plausible.ConfigTest do env = [{"MAILER_ADAPTER", "Bamboo.Mua"}] assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [ - {:adapter, Bamboo.Mua} + {:adapter, Bamboo.Mua}, + {:ssl, [middlebox_comp_mode: false]} + ] + end + + test "Bamboo.Mua (middlebox_comp_mode enabled)" do + env = [{"MAILER_ADAPTER", "Bamboo.Mua"}, {"SMTP_MIDDLEBOX_COMP_MODE", "true"}] + + assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [ + {:adapter, Bamboo.Mua}, + {:ssl, [middlebox_comp_mode: true]} ] end @@ -159,6 +167,7 @@ defmodule Plausible.ConfigTest do assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [ {:adapter, Bamboo.Mua}, + {:ssl, [middlebox_comp_mode: false]}, {:relay, "localhost"}, {:port, 2525}, {:auth, [username: "neo", password: "one"]} @@ -176,6 +185,7 @@ defmodule Plausible.ConfigTest do assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [ adapter: Bamboo.Mua, + ssl: [middlebox_comp_mode: false], relay: "localhost", port: 2525 ]