fix: make sure smtp can be set either via env or ui
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a244b1b07e
commit
605a897045
9 changed files with 201 additions and 42 deletions
|
|
@ -23,7 +23,8 @@ defmodule Mv.ConfigSmtpTest do
|
|||
end
|
||||
|
||||
describe "smtp_port/0" do
|
||||
test "returns parsed integer when SMTP_PORT ENV is set" do
|
||||
test "returns parsed integer when SMTP_PORT ENV is set in ENV-only mode" do
|
||||
set_smtp_env("SMTP_HOST", "smtp.example.com")
|
||||
set_smtp_env("SMTP_PORT", "587")
|
||||
assert Mv.Config.smtp_port() == 587
|
||||
after
|
||||
|
|
@ -52,13 +53,21 @@ defmodule Mv.ConfigSmtpTest do
|
|||
end
|
||||
|
||||
describe "smtp_env_configured?/0" do
|
||||
test "returns true when any SMTP ENV variable is set" do
|
||||
test "returns true when SMTP_HOST is set" do
|
||||
set_smtp_env("SMTP_HOST", "smtp.example.com")
|
||||
assert Mv.Config.smtp_env_configured?() == true
|
||||
after
|
||||
clear_smtp_env()
|
||||
end
|
||||
|
||||
test "returns false when SMTP_HOST is not set even if other SMTP ENV variables are set" do
|
||||
set_smtp_env("SMTP_USERNAME", "user@example.com")
|
||||
set_smtp_env("SMTP_PASSWORD", "secret")
|
||||
refute Mv.Config.smtp_env_configured?()
|
||||
after
|
||||
clear_smtp_env()
|
||||
end
|
||||
|
||||
test "returns false when no SMTP ENV variables are set" do
|
||||
clear_smtp_env()
|
||||
refute Mv.Config.smtp_env_configured?()
|
||||
|
|
@ -66,15 +75,17 @@ defmodule Mv.ConfigSmtpTest do
|
|||
end
|
||||
|
||||
describe "smtp_password/0 and SMTP_PASSWORD_FILE" do
|
||||
test "returns value from SMTP_PASSWORD when set" do
|
||||
test "returns value from SMTP_PASSWORD when set in ENV-only mode" do
|
||||
set_smtp_env("SMTP_HOST", "smtp.example.com")
|
||||
set_smtp_env("SMTP_PASSWORD", "env-secret")
|
||||
assert Mv.Config.smtp_password() == "env-secret"
|
||||
after
|
||||
clear_smtp_env()
|
||||
end
|
||||
|
||||
test "returns content of file when SMTP_PASSWORD_FILE is set and SMTP_PASSWORD is not" do
|
||||
test "returns content of file when SMTP_PASSWORD_FILE is set in ENV-only mode and SMTP_PASSWORD is not" do
|
||||
clear_smtp_env()
|
||||
set_smtp_env("SMTP_HOST", "smtp.example.com")
|
||||
path = Path.join(System.tmp_dir!(), "mv_smtp_test_#{System.unique_integer([:positive])}")
|
||||
File.write!(path, "file-secret\n")
|
||||
Process.put(:smtp_password_file_path, path)
|
||||
|
|
@ -85,7 +96,8 @@ defmodule Mv.ConfigSmtpTest do
|
|||
if path = Process.get(:smtp_password_file_path), do: File.rm(path)
|
||||
end
|
||||
|
||||
test "SMTP_PASSWORD overrides SMTP_PASSWORD_FILE when both are set" do
|
||||
test "SMTP_PASSWORD overrides SMTP_PASSWORD_FILE in ENV-only mode when both are set" do
|
||||
set_smtp_env("SMTP_HOST", "smtp.example.com")
|
||||
path = Path.join(System.tmp_dir!(), "mv_smtp_test_#{System.unique_integer([:positive])}")
|
||||
File.write!(path, "file-secret")
|
||||
Process.put(:smtp_password_file_path, path)
|
||||
|
|
|
|||
|
|
@ -172,6 +172,34 @@ defmodule MvWeb.GlobalSettingsLiveTest do
|
|||
{:ok, _view, html} = live(conn, ~p"/settings")
|
||||
assert html =~ "SMTP is fully managed via environment variables"
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
test "shows warning block for missing required SMTP ENV values in ENV-only mode", %{
|
||||
conn: conn
|
||||
} do
|
||||
clear_smtp_env()
|
||||
System.put_env("SMTP_HOST", "smtp.env-only.example")
|
||||
on_exit(fn -> clear_smtp_env() end)
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/settings")
|
||||
assert html =~ "SMTP environment configuration appears incomplete"
|
||||
assert html =~ "SMTP_USERNAME"
|
||||
assert html =~ "SMTP_PASSWORD/SMTP_PASSWORD_FILE"
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
test "does not enter ENV-only mode when SMTP_HOST is not set", %{conn: conn} do
|
||||
clear_smtp_env()
|
||||
System.put_env("SMTP_USERNAME", "leftover@example.com")
|
||||
on_exit(fn -> clear_smtp_env() end)
|
||||
|
||||
{:ok, view, html} = live(conn, ~p"/settings")
|
||||
|
||||
refute html =~ "SMTP is fully managed via environment variables"
|
||||
refute html =~ "SMTP environment configuration appears incomplete"
|
||||
refute has_element?(view, "#setting_smtp_host[disabled]")
|
||||
refute has_element?(view, "#setting_smtp_username[disabled]")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Authentication section when OIDC-only is enabled" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue