Fix TLS config #473

Merged
simon merged 3 commits from bugfix/fix-tls-config into main 2026-03-16 15:04:35 +01:00
2 changed files with 34 additions and 5 deletions
Showing only changes of commit f353f1cbc0 - Show all commits

View file

@ -3854,7 +3854,7 @@ msgstr "Wenn deaktiviert, können sich Nutzer*innen nicht über /register anmeld
#: lib/mv_web/controllers/page_controller.ex #: lib/mv_web/controllers/page_controller.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Home" msgid "Home"
msgstr "" msgstr "Startseite"
#: lib/mv_web/controllers/join_confirm_controller.ex #: lib/mv_web/controllers/join_confirm_controller.ex
#, elixir-autogen, elixir-format, fuzzy #, elixir-autogen, elixir-format, fuzzy

View file

@ -2,6 +2,9 @@ defmodule MvWeb.JoinLiveEmailFailureTest do
@moduledoc """ @moduledoc """
When join confirmation email delivery fails, the user sees an error message When join confirmation email delivery fails, the user sees an error message
and no success copy. Uses FailingMailAdapter; async: false to avoid config races. and no success copy. Uses FailingMailAdapter; async: false to avoid config races.
Ensures SMTP is not configured (ENV cleared, Settings smtp_host nil) so that
Mailer.smtp_config/0 returns [] and the Application-configured FailingMailAdapter is used.
""" """
use MvWeb.ConnCase, async: false use MvWeb.ConnCase, async: false
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
@ -12,18 +15,21 @@ defmodule MvWeb.JoinLiveEmailFailureTest do
test "when confirmation email fails, user sees error flash and no success message", %{ test "when confirmation email fails, user sees error flash and no success message", %{
conn: conn conn: conn
} do } do
# Clear SMTP config so Mailer.smtp_config() returns [] and FailingMailAdapter is used.
saved_env = clear_smtp_env_and_save()
enable_join_form_for_test() enable_join_form_for_test()
saved = Application.get_env(:mv, Mv.Mailer) saved_mailer = Application.get_env(:mv, Mv.Mailer)
Application.put_env( Application.put_env(
:mv, :mv,
Mv.Mailer, Mv.Mailer,
Keyword.put(saved || [], :adapter, Mv.TestSupport.FailingMailAdapter) Keyword.put(saved_mailer || [], :adapter, Mv.TestSupport.FailingMailAdapter)
) )
on_exit(fn -> on_exit(fn ->
Application.put_env(:mv, Mv.Mailer, saved) Application.put_env(:mv, Mv.Mailer, saved_mailer)
restore_smtp_env(saved_env)
end) end)
{:ok, view, _html} = live(conn, "/join") {:ok, view, _html} = live(conn, "/join")
@ -46,13 +52,36 @@ defmodule MvWeb.JoinLiveEmailFailureTest do
refute view |> element("[data-testid='join-success-message']") |> has_element?() refute view |> element("[data-testid='join-success-message']") |> has_element?()
end end
defp clear_smtp_env_and_save do
keys = [
"SMTP_HOST",
"SMTP_PORT",
"SMTP_USERNAME",
"SMTP_PASSWORD",
"SMTP_PASSWORD_FILE",
"SMTP_SSL"
]
saved = for k <- keys, into: %{}, do: {k, System.get_env(k)}
for k <- keys, do: System.delete_env(k)
saved
end
defp restore_smtp_env(saved) do
for {k, v} <- saved do
if v != nil, do: System.put_env(k, v), else: System.delete_env(k)
end
end
defp enable_join_form_for_test do defp enable_join_form_for_test do
{:ok, settings} = Membership.get_settings() {:ok, settings} = Membership.get_settings()
Membership.update_settings(settings, %{ Membership.update_settings(settings, %{
join_form_enabled: true, join_form_enabled: true,
join_form_field_ids: ["email", "first_name", "last_name"], join_form_field_ids: ["email", "first_name", "last_name"],
join_form_field_required: %{"email" => true, "first_name" => false, "last_name" => false} join_form_field_required: %{"email" => true, "first_name" => false, "last_name" => false},
# Clear SMTP host so Mv.Config.smtp_configured?() is false and Mailer.smtp_config() returns [].
smtp_host: nil
}) })
end end
end end