ed89295012
Unifies the two previously independent email subsystems — MailService (net/smtp transport) and NotificationService (HTTP-based providers) — so email can participate in the notification dispatch pipeline. Key changes: - SendEmail signature updated to accept context.Context and []string recipients to enable timeout propagation and multi-recipient dispatch - NotificationService.dispatchEmail() wires MailService as a first-class provider type with IsConfigured() guard and 30s context timeout - 'email' added to isSupportedNotificationProviderType() and supportsJSONTemplates() returns false for email (plain/HTML only) - settings_handler.go test-email endpoint updated to new SendEmail API - Frontend: 'email' added to provider type union in notifications.ts, Notifications.tsx shows recipient field and hides URL/token fields for email providers - All existing tests updated to match new SendEmail signature - New tests added covering dispatchEmail paths, IsConfigured guards, recipient validation, and context timeout behaviour Also fixes confirmed false-positive CodeQL go/email-injection alerts: - smtp.SendMail, sendSSL w.Write, and sendSTARTTLS w.Write sites now carry inline codeql[go/email-injection] annotations as required by the CodeQL same-line suppression spec; preceding-line annotations silently no-op in current CodeQL versions - auth_handler.go c.SetCookie annotated for intentional Secure=false on local non-HTTPS loopback (go/cookie-secure-not-set warning only) Closes part of #800
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package services
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Wikid82/charon/backend/internal/models"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func TestUptimeService_sendRecoveryNotification(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
db, err := gorm.Open(sqlite.Open("file:"+uuid.NewString()+"?mode=memory&cache=shared"), &gorm.Config{})
|
|
require.NoError(t, err)
|
|
require.NoError(t, db.AutoMigrate(&models.Notification{}, &models.NotificationProvider{}))
|
|
|
|
ns := NewNotificationService(db, nil)
|
|
svc := NewUptimeService(db, ns)
|
|
|
|
monitor := models.UptimeMonitor{Name: "API Server", URL: "https://api.example.com"}
|
|
|
|
svc.sendRecoveryNotification(monitor, "5m")
|
|
|
|
var notifications []models.Notification
|
|
require.NoError(t, db.Find(¬ifications).Error)
|
|
|
|
require.Len(t, notifications, 1)
|
|
assert.Contains(t, notifications[0].Title, "API Server")
|
|
assert.Contains(t, notifications[0].Message, "Downtime: 5m")
|
|
assert.Equal(t, models.NotificationTypeSuccess, notifications[0].Type)
|
|
}
|