mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 08:29:33 -05:00
2d8fcd9bf4
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/goleak"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
goleak.VerifyTestMain(m)
|
|
}
|
|
|
|
func TestDeriveKey(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
key, err := DeriveKey([]byte("secret"), []byte("salt"), nil, 32)
|
|
assert.NoError(err)
|
|
assert.Len(key, 32)
|
|
|
|
key1, err := DeriveKey([]byte("secret"), []byte("salt"), []byte("first"), 32)
|
|
require.NoError(err)
|
|
key2, err := DeriveKey([]byte("secret"), []byte("salt"), []byte("first"), 32)
|
|
require.NoError(err)
|
|
assert.Equal(key1, key2)
|
|
|
|
key3, err := DeriveKey([]byte("secret"), []byte("salt"), []byte("second"), 32)
|
|
require.NoError(err)
|
|
assert.NotEqual(key1, key3)
|
|
}
|
|
|
|
func TestGenerateCertificateSerialNumber(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
|
|
s1, err := GenerateCertificateSerialNumber()
|
|
require.NoError(err)
|
|
s2, err := GenerateCertificateSerialNumber()
|
|
require.NoError(err)
|
|
assert.NotEqual(s1, s2)
|
|
}
|
|
|
|
func TestGenerateRandomBytes(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
|
|
n1, err := GenerateRandomBytes(32)
|
|
require.NoError(err)
|
|
assert.Len(n1, 32)
|
|
|
|
n2, err := GenerateRandomBytes(32)
|
|
require.NoError(err)
|
|
|
|
assert.Equal(len(n1), len(n2))
|
|
assert.NotEqual(n1, n2)
|
|
|
|
n3, err := GenerateRandomBytes(16)
|
|
require.NoError(err)
|
|
assert.Len(n3, 16)
|
|
}
|