gate magic link login on verified email delivery
All checks were successful
deploy / deploy (push) Successful in 1m2s
All checks were successful
deploy / deploy (push) Successful in 1m2s
The login page now only shows the magic link form when a test email has been sent successfully, not just when an adapter is configured. Saving email settings or disconnecting clears the flag so the admin must re-verify after config changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,14 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
import Phoenix.LiveViewTest
|
||||
import Berrypod.AccountsFixtures
|
||||
|
||||
alias Berrypod.Mailer
|
||||
|
||||
describe "login page" do
|
||||
setup do
|
||||
Mailer.mark_email_verified()
|
||||
:ok
|
||||
end
|
||||
|
||||
test "renders login page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/log-in")
|
||||
|
||||
@@ -15,6 +22,11 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
end
|
||||
|
||||
describe "user login - magic link" do
|
||||
setup do
|
||||
Mailer.mark_email_verified()
|
||||
:ok
|
||||
end
|
||||
|
||||
test "sends magic link email when user exists", %{conn: conn} do
|
||||
user = user_fixture()
|
||||
|
||||
@@ -93,7 +105,7 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "email configured" do
|
||||
describe "email configured and verified" do
|
||||
setup do
|
||||
original = Application.get_env(:berrypod, Berrypod.Mailer)
|
||||
|
||||
@@ -102,6 +114,8 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
api_key: "test"
|
||||
)
|
||||
|
||||
Mailer.mark_email_verified()
|
||||
|
||||
on_exit(fn -> Application.put_env(:berrypod, Berrypod.Mailer, original) end)
|
||||
:ok
|
||||
end
|
||||
@@ -114,6 +128,32 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "email configured but not verified" do
|
||||
setup do
|
||||
# Create user before switching adapter (fixture sends a confirmation email)
|
||||
_user = user_fixture()
|
||||
|
||||
original = Application.get_env(:berrypod, Berrypod.Mailer)
|
||||
|
||||
Application.put_env(:berrypod, Berrypod.Mailer,
|
||||
adapter: Swoosh.Adapters.Postmark,
|
||||
api_key: "test"
|
||||
)
|
||||
|
||||
Mailer.clear_email_verified()
|
||||
|
||||
on_exit(fn -> Application.put_env(:berrypod, Berrypod.Mailer, original) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "hides magic link form and shows recovery link", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/log-in")
|
||||
|
||||
refute html =~ "Log in with email"
|
||||
assert html =~ "Locked out?"
|
||||
end
|
||||
end
|
||||
|
||||
describe "login navigation" do
|
||||
test "redirects to setup page when the setup link is clicked", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/log-in")
|
||||
@@ -130,6 +170,7 @@ defmodule BerrypodWeb.Auth.LoginTest do
|
||||
|
||||
describe "re-authentication (sudo mode)" do
|
||||
setup %{conn: conn} do
|
||||
Mailer.mark_email_verified()
|
||||
user = user_fixture()
|
||||
%{user: user, conn: log_in_user(conn, user)}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user