mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
26 lines
547 B
Go
26 lines
547 B
Go
package apikeygen
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func TestApiKeyGen(t *testing.T) {
|
|
result, err := New(12, "Cool key")
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, result.ClientSecret)
|
|
assert.NotEmpty(t, result.HashedKey)
|
|
|
|
keyInfo, err := Decode(result.ClientSecret)
|
|
require.NoError(t, err)
|
|
|
|
keyHashed, err := util.EncodePassword(keyInfo.Key, keyInfo.Name)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, result.HashedKey, keyHashed)
|
|
}
|