grafana/pkg/services/notifications/codes_test.go
Arve Knudsen 41d432b5ae
Chore: Enable whitespace linter (#25903)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2020-07-06 20:17:28 +02:00

38 lines
928 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() {
setting.EmailCodeValidMinutes = 120
user := &models.User{Id: 10, Email: "t@a.com", Login: "asd", Password: "1", Rands: "2"}
code, err := createUserEmailCode(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(user, code)
So(err, ShouldBeNil)
So(isValid, ShouldBeTrue)
})
Convey("Cannot verify in-valid code", func() {
code = "ASD"
isValid, err := validateUserEmailCode(user, code)
So(err, ShouldBeNil)
So(isValid, ShouldBeFalse)
})
})
}