Backend: Migrate to using non-global configuration (#31856)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -56,7 +56,7 @@ func (ns *NotificationService) Init() error {
|
||||
"Subject": subjectTemplateFunc,
|
||||
})
|
||||
|
||||
templatePattern := filepath.Join(setting.StaticRootPath, ns.Cfg.Smtp.TemplatesPattern)
|
||||
templatePattern := filepath.Join(ns.Cfg.StaticRootPath, ns.Cfg.Smtp.TemplatesPattern)
|
||||
_, err := mailTemplates.ParseGlob(templatePattern)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6,32 +6,31 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNotifications(t *testing.T) {
|
||||
Convey("Given the notifications service", t, func() {
|
||||
setting.StaticRootPath = "../../../public/"
|
||||
func TestNotificationService(t *testing.T) {
|
||||
ns := &NotificationService{
|
||||
Cfg: setting.NewCfg(),
|
||||
}
|
||||
ns.Cfg.StaticRootPath = "../../../public/"
|
||||
ns.Cfg.Smtp.Enabled = true
|
||||
ns.Cfg.Smtp.TemplatesPattern = "emails/*.html"
|
||||
ns.Cfg.Smtp.FromAddress = "from@address.com"
|
||||
ns.Cfg.Smtp.FromName = "Grafana Admin"
|
||||
ns.Bus = bus.New()
|
||||
|
||||
ns := &NotificationService{}
|
||||
ns.Bus = bus.New()
|
||||
ns.Cfg = setting.NewCfg()
|
||||
ns.Cfg.Smtp.Enabled = true
|
||||
ns.Cfg.Smtp.TemplatesPattern = "emails/*.html"
|
||||
ns.Cfg.Smtp.FromAddress = "from@address.com"
|
||||
ns.Cfg.Smtp.FromName = "Grafana Admin"
|
||||
err := ns.Init()
|
||||
require.NoError(t, err)
|
||||
|
||||
err := ns.Init()
|
||||
So(err, ShouldBeNil)
|
||||
t.Run("When sending reset email password", func(t *testing.T) {
|
||||
err := ns.sendResetPasswordEmail(&models.SendResetPasswordEmailCommand{User: &models.User{Email: "asd@asd.com"}})
|
||||
require.NoError(t, err)
|
||||
|
||||
Convey("When sending reset email password", func() {
|
||||
err := ns.sendResetPasswordEmail(&models.SendResetPasswordEmailCommand{User: &models.User{Email: "asd@asd.com"}})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
sentMsg := <-ns.mailQueue
|
||||
So(sentMsg.Body, ShouldContainSubstring, "body")
|
||||
So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com")
|
||||
So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
|
||||
})
|
||||
sentMsg := <-ns.mailQueue
|
||||
assert.Contains(t, sentMsg.Body, "body")
|
||||
assert.Equal(t, "Reset your Grafana password - asd@asd.com", sentMsg.Subject)
|
||||
assert.NotContains(t, sentMsg.Body, "Subject")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ func (rs *RenderingService) Init() error {
|
||||
// RendererCallbackUrl has already been passed, it won't generate an error.
|
||||
u, _ := url.Parse(rs.Cfg.RendererCallbackUrl)
|
||||
rs.domain = u.Hostname()
|
||||
case setting.HttpAddr != setting.DefaultHTTPAddr:
|
||||
rs.domain = setting.HttpAddr
|
||||
case rs.Cfg.HTTPAddr != setting.DefaultHTTPAddr:
|
||||
rs.domain = rs.Cfg.HTTPAddr
|
||||
default:
|
||||
rs.domain = "localhost"
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func (rs *RenderingService) getURL(path string) string {
|
||||
}
|
||||
|
||||
// &render=1 signals to the legacy redirect layer to
|
||||
return fmt.Sprintf("%s://%s:%s%s/%s&render=1", protocol, rs.domain, setting.HttpPort, subPath, path)
|
||||
return fmt.Sprintf("%s://%s:%s%s/%s&render=1", protocol, rs.domain, rs.Cfg.HTTPPort, subPath, path)
|
||||
}
|
||||
|
||||
func (rs *RenderingService) generateAndStoreRenderKey(orgId, userId int64, orgRole models.RoleType) (string, error) {
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestGetUrl(t *testing.T) {
|
||||
t.Run("When renderer url not configured", func(t *testing.T) {
|
||||
rs.Cfg.RendererUrl = ""
|
||||
rs.domain = "localhost"
|
||||
setting.HttpPort = "3000"
|
||||
rs.Cfg.HTTPPort = "3000"
|
||||
|
||||
t.Run("And protocol HTTP configured should return expected path", func(t *testing.T) {
|
||||
rs.Cfg.ServeFromSubPath = false
|
||||
|
||||
Reference in New Issue
Block a user