mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-24 13:36:24 +00:00
fix(email): report a missing sender address from the SMTP connection test
TestConnection skipped the empty-from guard that Send enforces, so with no sender and no username configured the test issued the null reverse-path and could report success against a lenient relay while every real notification send kept failing with the missing-sender error. Guard the test path the same way and surface a dedicated translated message.
This commit is contained in:
@@ -117,6 +117,9 @@ func (s *EmailService) TestConnection() SMTPTestResult {
|
||||
if from == "" {
|
||||
from = username
|
||||
}
|
||||
if from == "" {
|
||||
return SMTPTestResult{false, "send", "smtpFromNotConfigured"}
|
||||
}
|
||||
from, fromName = resolveFrom(from, fromName)
|
||||
|
||||
recipients := parseRecipients(toStr)
|
||||
|
||||
@@ -180,6 +180,31 @@ func TestSendUsesBareAddressFromNameAddrSmtpFrom(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnectionReportsMissingFrom(t *testing.T) {
|
||||
if err := database.InitDB(filepath.Join(t.TempDir(), "x-ui.db")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = database.CloseDB() })
|
||||
|
||||
settingService := service.SettingService{}
|
||||
mustSet := func(name string, err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatalf("set %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
mustSet("host", settingService.SetSmtpHost("127.0.0.1"))
|
||||
mustSet("port", settingService.SetSmtpPort(1))
|
||||
mustSet("to", settingService.SetSmtpTo("admin@example.com"))
|
||||
mustSet("encryption", settingService.SetSmtpEncryptionType("none"))
|
||||
|
||||
got := NewEmailService(settingService).TestConnection()
|
||||
want := SMTPTestResult{Success: false, Stage: "send", Message: "smtpFromNotConfigured"}
|
||||
if got != want {
|
||||
t.Errorf("TestConnection() = %+v, want %+v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMessageStripsHeaderInjection(t *testing.T) {
|
||||
raw := buildMessage(
|
||||
"panel@example.com\r\nBcc: evil@example.com",
|
||||
|
||||
Reference in New Issue
Block a user