mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
31 lines
649 B
Go
31 lines
649 B
Go
package hash
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var hasher = NewSCrypt()
|
|
|
|
func TestBasicHash(t *testing.T) {
|
|
secretKey := "hello world"
|
|
hash, err := hasher.CreateHash(secretKey)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, hash)
|
|
|
|
assert.Nil(t, hasher.VerifyHash(hash, secretKey))
|
|
assert.NotNil(t, hasher.VerifyHash(hash, "goodbye"))
|
|
}
|
|
|
|
func TestLongKey(t *testing.T) {
|
|
secretKey := strings.Repeat("A", 720)
|
|
hash, err := hasher.CreateHash(secretKey)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, hash)
|
|
|
|
assert.Nil(t, hasher.VerifyHash(hash, secretKey))
|
|
assert.NotNil(t, hasher.VerifyHash(hash, secretKey+":wrong!"))
|
|
}
|