apikeygen_test.go 564 B

1234567891011121314151617181920212223242526
  1. package apikeygen
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/util"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestApiKeyGen(t *testing.T) {
  8. Convey("When generating new api key", t, func() {
  9. result := New(12, "Cool key")
  10. So(result.ClientSecret, ShouldNotBeEmpty)
  11. So(result.HashedKey, ShouldNotBeEmpty)
  12. Convey("can decode key", func() {
  13. keyInfo, err := Decode(result.ClientSecret)
  14. So(err, ShouldBeNil)
  15. keyHashed := util.EncodePassword(keyInfo.Key, keyInfo.Name)
  16. So(keyHashed, ShouldEqual, result.HashedKey)
  17. })
  18. })
  19. }