mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
41d432b5ae
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
38 lines
928 B
Go
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)
|
|
})
|
|
})
|
|
}
|