2023-03-03 22:31:10 +01:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_newClientCert(t *testing.T) {
|
2023-03-03 22:44:57 +01:00
|
|
|
ca, err := NewRootCA(&rootTestConfig)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, ca)
|
|
|
|
|
|
|
|
require.NotNil(t, ca.Key())
|
|
|
|
require.Greater(t, len(ca.Key()), 0)
|
|
|
|
|
|
|
|
require.NotNil(t, ca.PEM())
|
|
|
|
require.Greater(t, len(ca.PEM()), 0)
|
|
|
|
|
|
|
|
x509RootCA, err := parseCertificate(ca.PEM())
|
|
|
|
require.NoError(t, err)
|
2023-03-03 22:31:10 +01:00
|
|
|
|
2023-03-03 22:44:57 +01:00
|
|
|
pem, key, err := newClientCert(&clientTestConfig, x509RootCA, ca.Key())
|
2023-03-03 22:31:10 +01:00
|
|
|
require.NoError(t, err)
|
2023-03-03 22:44:57 +01:00
|
|
|
|
|
|
|
require.NotNil(t, pem)
|
|
|
|
require.Greater(t, len(pem), 0)
|
|
|
|
|
|
|
|
require.NotNil(t, key)
|
|
|
|
require.Greater(t, len(key), 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_newClientCertErrr(t *testing.T) {
|
|
|
|
_, _, err := newClientCert(&clientTestConfig, nil, []byte{})
|
|
|
|
require.Error(t, err)
|
2023-03-03 22:31:10 +01:00
|
|
|
}
|