Files
base/mails/record_test.go
zeekay a6878e5563 core,mails: rip hooks and senders for retired local-auth flows
App.OnRecordAuthWithPasswordRequest, OnRecord{Request,Confirm}-
PasswordResetRequest, OnRecord{Request,Authenticate}OTPRequest,
OnMailerRecordPasswordResetSend, OnMailerRecordOTPSend and
OnMailerRecordAuthAlertSend were vestigial after the 16-handler purge
in 71c2d80e — every callable that wired them up is gone. Drop the
interface methods, the event types, the BaseApp fields, the init/getter
plumbing, and the matching mails.SendRecordPasswordReset /
SendRecordOTP / SendRecordAuthAlert senders. The superuser
PasswordReset filter goes with them; IAM owns superuser password flow.

The superuser collection save handler no longer forces PasswordAuth
on or pairs OTP with MFA — _superusers is now a pure email-only
mirror; IAM PKCE is the only way in.
2026-05-15 03:00:46 -07:00

73 lines
2.0 KiB
Go

package mails_test
import (
"html"
"strings"
"testing"
"github.com/hanzoai/base/mails"
"github.com/hanzoai/base/tests"
)
func TestSendRecordVerification(t *testing.T) {
t.Parallel()
testApp, _ := tests.NewTestApp()
defer testApp.Cleanup()
user, _ := testApp.FindFirstRecordByData("users", "email", "[email protected]")
// to test that it is escaped
user.Set("name", "<p>"+user.GetString("name")+"</p>")
err := mails.SendRecordVerification(testApp, user)
if err != nil {
t.Fatal(err)
}
if testApp.TestMailer.TotalSend() != 1 {
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
}
expectedParts := []string{
html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // the record name as {RECORD:name}
"http://localhost:8090/_/#/auth/confirm-verification/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
}
for _, part := range expectedParts {
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
}
}
}
func TestSendRecordChangeEmail(t *testing.T) {
t.Parallel()
testApp, _ := tests.NewTestApp()
defer testApp.Cleanup()
user, _ := testApp.FindFirstRecordByData("users", "email", "[email protected]")
// to test that it is escaped
user.Set("name", "<p>"+user.GetString("name")+"</p>")
err := mails.SendRecordChangeEmail(testApp, user, "[email protected]")
if err != nil {
t.Fatal(err)
}
if testApp.TestMailer.TotalSend() != 1 {
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
}
expectedParts := []string{
html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // the record name as {RECORD:name}
"http://localhost:8090/_/#/auth/confirm-email-change/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
}
for _, part := range expectedParts {
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
}
}
}