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
51 lines
1.3 KiB
Go
51 lines
1.3 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 TestNotificationService_TemplateCRUD(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.NotificationTemplate{}))
|
|
|
|
svc := NewNotificationService(db, nil)
|
|
|
|
tmpl := &models.NotificationTemplate{
|
|
Name: "Custom",
|
|
Description: "initial description",
|
|
Config: `{"message":"hello"}`,
|
|
Template: "custom",
|
|
}
|
|
|
|
require.NoError(t, svc.CreateTemplate(tmpl))
|
|
require.NotEmpty(t, tmpl.ID)
|
|
|
|
fetched, err := svc.GetTemplate(tmpl.ID)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tmpl.Name, fetched.Name)
|
|
assert.Equal(t, tmpl.Description, fetched.Description)
|
|
|
|
tmpl.Description = "updated description"
|
|
require.NoError(t, svc.UpdateTemplate(tmpl))
|
|
|
|
list, err := svc.ListTemplates()
|
|
require.NoError(t, err)
|
|
require.Len(t, list, 1)
|
|
assert.Equal(t, "updated description", list[0].Description)
|
|
|
|
require.NoError(t, svc.DeleteTemplate(tmpl.ID))
|
|
list, err = svc.ListTemplates()
|
|
require.NoError(t, err)
|
|
assert.Empty(t, list)
|
|
}
|