mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
App.OnRecordAuthWithPasswordRequest, OnRecord{Request,Confirm}-
PasswordResetRequest, OnRecord{Request,Authenticate}OTPRequest,
OnMailerRecordPasswordResetSend, OnMailerRecordOTPSend and
OnMailerRecordAuthAlertSend were vestigial after the 16-handler purge
in dc94c7ca — 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.
73 lines
2.0 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|