codes_test.go 798 B

1234567891011121314151617181920212223242526272829303132333435
  1. package notifications
  2. import (
  3. "testing"
  4. m "github.com/grafana/grafana/pkg/models"
  5. "github.com/grafana/grafana/pkg/setting"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestEmailCodes(t *testing.T) {
  9. Convey("When generating code", t, func() {
  10. setting.EmailCodeValidMinutes = 120
  11. user := &m.User{Id: 10, Email: "t@a.com", Login: "asd", Password: "1", Rands: "2"}
  12. code := createUserEmailCode(user, nil)
  13. Convey("getLoginForCode should return login", func() {
  14. login := getLoginForEmailCode(code)
  15. So(login, ShouldEqual, "asd")
  16. })
  17. Convey("Can verify valid code", func() {
  18. So(validateUserEmailCode(user, code), ShouldBeTrue)
  19. })
  20. Convey("Cannot verify in-valid code", func() {
  21. code = "ASD"
  22. So(validateUserEmailCode(user, code), ShouldBeFalse)
  23. })
  24. })
  25. }