mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
27 lines
564 B
Go
27 lines
564 B
Go
package apikeygen
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestApiKeyGen(t *testing.T) {
|
|
|
|
Convey("When generating new api key", t, func() {
|
|
result := New(12, "Cool key")
|
|
|
|
So(result.ClientSecret, ShouldNotBeEmpty)
|
|
So(result.HashedKey, ShouldNotBeEmpty)
|
|
|
|
Convey("can decode key", func() {
|
|
keyInfo, err := Decode(result.ClientSecret)
|
|
So(err, ShouldBeNil)
|
|
|
|
keyHashed := util.EncodePassword(keyInfo.Key, keyInfo.Name)
|
|
So(keyHashed, ShouldEqual, result.HashedKey)
|
|
})
|
|
})
|
|
}
|