mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fixes #30144 Co-authored-by: dsotirakis <sotirakis.dim@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Leon Sorokin <leeoniya@gmail.com> Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com> Co-authored-by: spinillos <selenepinillos@gmail.com> Co-authored-by: Karl Persson <kalle.persson@grafana.com> Co-authored-by: Leonard Gram <leo@xlson.com>
39 lines
965 B
Go
39 lines
965 B
Go
package notifications
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestEmailCodes(t *testing.T) {
|
|
Convey("When generating code", t, func() {
|
|
cfg := setting.NewCfg()
|
|
cfg.EmailCodeValidMinutes = 120
|
|
|
|
user := &models.User{Id: 10, Email: "t@a.com", Login: "asd", Password: "1", Rands: "2"}
|
|
code, err := createUserEmailCode(cfg, user, nil)
|
|
So(err, ShouldBeNil)
|
|
|
|
Convey("getLoginForCode should return login", func() {
|
|
login := getLoginForEmailCode(code)
|
|
So(login, ShouldEqual, "asd")
|
|
})
|
|
|
|
Convey("Can verify valid code", func() {
|
|
isValid, err := validateUserEmailCode(cfg, user, code)
|
|
So(err, ShouldBeNil)
|
|
So(isValid, ShouldBeTrue)
|
|
})
|
|
|
|
Convey("Cannot verify in-valid code", func() {
|
|
code = "ASD"
|
|
isValid, err := validateUserEmailCode(cfg, user, code)
|
|
So(err, ShouldBeNil)
|
|
So(isValid, ShouldBeFalse)
|
|
})
|
|
})
|
|
}
|