2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
package gcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2022-11-09 05:48:56 -05:00
|
|
|
"cloud.google.com/go/kms/apiv1/kmspb"
|
2023-01-11 04:08:57 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/keyservice/internal/storage"
|
|
|
|
kmsInterface "github.com/edgelesssys/constellation/v2/keyservice/kms"
|
|
|
|
"github.com/edgelesssys/constellation/v2/keyservice/kms/util"
|
2022-03-25 06:02:02 -04:00
|
|
|
"github.com/googleapis/gax-go/v2"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
"google.golang.org/api/option"
|
2022-03-25 06:02:02 -04:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m,
|
|
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
var testKeyRSA = `-----BEGIN PUBLIC KEY-----
|
2022-03-22 11:03:15 -04:00
|
|
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAu+OepfHCTiTi27nkTGke
|
|
|
|
dn+AIkiM1AIWWDwqfqG85aNulcj60mGQGXIYV8LoEVkyKOhYBIUmJUaVczB4ltqq
|
|
|
|
ZhR7l46RQw2vnv+XiUmfK555d4ZDInyjTusO69hE6tkuYKdXLlG1HzcrhJ254LE2
|
|
|
|
wXtE1Yf9DygOsWet+S32gmpfH2whUY1mRTdwW4zoY4c3qtmmWImhVVNr6qR8Z95X
|
|
|
|
Y49EteCoNIomQNEZH7EnMlBsh34L7doOsckh1aTvQcrJorQSrBkWKbdV6kvuBKZp
|
|
|
|
fLK0DZiOh9BwZCZANtOqgH3V+AuNk338iON8eKCFRjoiQ40YGM6xKH3E6PHVnuKt
|
|
|
|
uIO0MPvE0qdV8Lvs+nCCrvwP5sJKZuciM40ioEO1pV1y3491xIxYhx3OfN4gg2h8
|
|
|
|
cgdKob/R8qwxqTrfceO36FBFb1vXCUApsm5oy6WxmUtIUgoYhK+6JYpVWDyOJYwP
|
|
|
|
iMJhdJA65n2ZliN8NxEhsaFoMgw76BOiD0wkt/CKPmNbOm5MGS3/fiZCt6A6u3cn
|
|
|
|
Ubhn4tvjy/q5XzVqZtBeoseW2TyyrsAN53LBkSqag5tG/264CQDigQ6Y/OADOE2x
|
|
|
|
n08MyrFHIL/wFMscOvJo7c2Eo4EW1yXkEkAy5tF5PZgnfRObakj4gdqPeq18FNzc
|
|
|
|
Y+t5OxL3kL15VzY1Ob0d5cMCAwEAAQ==
|
|
|
|
-----END PUBLIC KEY-----`
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
type stubGCPClient struct {
|
|
|
|
createErr error
|
|
|
|
createCryptoKeyCalled bool
|
|
|
|
createCryptoKeyErr error
|
|
|
|
createImportJobErr error
|
|
|
|
decryptResponse []byte
|
|
|
|
decryptErr error
|
|
|
|
encryptErr error
|
|
|
|
getKeyRingErr error
|
|
|
|
importCryptoKeyVersionErr error
|
|
|
|
updateCryptoKeyPrimaryVersionCalled bool
|
|
|
|
updateCryptoKeyPrimaryVersionErr error
|
|
|
|
getImportJobErr error
|
|
|
|
getImportJobResponse *kmspb.ImportJob
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func newStubGCPClientFactory(stub *stubGCPClient) func(ctx context.Context, opts ...option.ClientOption) (clientAPI, error) {
|
|
|
|
return func(ctx context.Context, opts ...option.ClientOption) (clientAPI, error) {
|
|
|
|
return stub, stub.createErr
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) CreateCryptoKey(ctx context.Context, req *kmspb.CreateCryptoKeyRequest, opts ...gax.CallOption) (*kmspb.CryptoKey, error) {
|
|
|
|
s.createCryptoKeyCalled = true
|
|
|
|
return &kmspb.CryptoKey{}, s.createCryptoKeyErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) CreateImportJob(ctx context.Context, req *kmspb.CreateImportJobRequest, opts ...gax.CallOption) (*kmspb.ImportJob, error) {
|
|
|
|
return &kmspb.ImportJob{}, s.createImportJobErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) Decrypt(ctx context.Context, req *kmspb.DecryptRequest, opts ...gax.CallOption) (*kmspb.DecryptResponse, error) {
|
|
|
|
return &kmspb.DecryptResponse{Plaintext: s.decryptResponse}, s.decryptErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) Encrypt(ctx context.Context, req *kmspb.EncryptRequest, opts ...gax.CallOption) (*kmspb.EncryptResponse, error) {
|
|
|
|
return &kmspb.EncryptResponse{}, s.encryptErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) GetKeyRing(ctx context.Context, req *kmspb.GetKeyRingRequest, opts ...gax.CallOption) (*kmspb.KeyRing, error) {
|
|
|
|
return &kmspb.KeyRing{}, s.getKeyRingErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) ImportCryptoKeyVersion(ctx context.Context, req *kmspb.ImportCryptoKeyVersionRequest, opts ...gax.CallOption) (*kmspb.CryptoKeyVersion, error) {
|
|
|
|
return &kmspb.CryptoKeyVersion{}, s.importCryptoKeyVersionErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) UpdateCryptoKeyPrimaryVersion(ctx context.Context, req *kmspb.UpdateCryptoKeyPrimaryVersionRequest, opts ...gax.CallOption) (*kmspb.CryptoKey, error) {
|
|
|
|
s.updateCryptoKeyPrimaryVersionCalled = true
|
|
|
|
return &kmspb.CryptoKey{}, s.updateCryptoKeyPrimaryVersionErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubGCPClient) GetImportJob(ctx context.Context, req *kmspb.GetImportJobRequest, opts ...gax.CallOption) (*kmspb.ImportJob, error) {
|
|
|
|
return s.getImportJobResponse, s.getImportJobErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
type stubStorage struct {
|
|
|
|
key []byte
|
|
|
|
getErr error
|
|
|
|
putErr error
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func (s *stubStorage) Get(context.Context, string) ([]byte, error) {
|
|
|
|
return s.key, s.getErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubStorage) Put(context.Context, string, []byte) error {
|
|
|
|
return s.putErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateKEK(t *testing.T) {
|
|
|
|
someErr := errors.New("error")
|
|
|
|
importKey := []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
client *stubGCPClient
|
|
|
|
importKey []byte
|
|
|
|
wantErr bool
|
2022-03-25 06:02:02 -04:00
|
|
|
}{
|
|
|
|
"create new kek successful": {
|
|
|
|
client: &stubGCPClient{},
|
|
|
|
},
|
|
|
|
"import kek successful": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
PublicKey: &kmspb.ImportJob_WrappingPublicKey{
|
|
|
|
Pem: testKeyRSA,
|
|
|
|
},
|
|
|
|
State: kmspb.ImportJob_ACTIVE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
importKey: importKey,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"CreateCryptoKey fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{createCryptoKeyErr: someErr},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"CreatCryptoKey fails on import": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
createCryptoKeyErr: someErr,
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
PublicKey: &kmspb.ImportJob_WrappingPublicKey{
|
|
|
|
Pem: testKeyRSA,
|
|
|
|
},
|
|
|
|
State: kmspb.ImportJob_ACTIVE,
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"CreateImportJob fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{createImportJobErr: someErr},
|
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"ImportCryptoKeyVersion fails": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
PublicKey: &kmspb.ImportJob_WrappingPublicKey{
|
|
|
|
Pem: testKeyRSA,
|
|
|
|
},
|
|
|
|
State: kmspb.ImportJob_ACTIVE,
|
|
|
|
},
|
|
|
|
importCryptoKeyVersionErr: someErr,
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"UpdateCryptoKeyPrimaryVersion fails": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
PublicKey: &kmspb.ImportJob_WrappingPublicKey{
|
|
|
|
Pem: testKeyRSA,
|
|
|
|
},
|
|
|
|
State: kmspb.ImportJob_ACTIVE,
|
|
|
|
},
|
|
|
|
updateCryptoKeyPrimaryVersionErr: someErr,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"GetImportJob fails during waitBackoff": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{getImportJobErr: someErr},
|
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"GetImportJob returns no key": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
State: kmspb.ImportJob_ACTIVE,
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"waitBackoff times out": {
|
|
|
|
client: &stubGCPClient{
|
|
|
|
getImportJobResponse: &kmspb.ImportJob{
|
|
|
|
PublicKey: &kmspb.ImportJob_WrappingPublicKey{
|
|
|
|
Pem: testKeyRSA,
|
|
|
|
},
|
|
|
|
State: kmspb.ImportJob_PENDING_GENERATION,
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
importKey: importKey,
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"creating client fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{createErr: someErr},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := &KMSClient{
|
|
|
|
projectID: "test-project",
|
|
|
|
locationID: "global",
|
|
|
|
keyRingID: "test-ring",
|
|
|
|
newClient: newStubGCPClientFactory(tc.client),
|
|
|
|
protectionLevel: kmspb.ProtectionLevel_SOFTWARE,
|
|
|
|
waitBackoffLimit: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := client.CreateKEK(context.Background(), "test-key", tc.importKey)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-25 06:02:02 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
if len(tc.importKey) != 0 {
|
|
|
|
assert.True(tc.client.updateCryptoKeyPrimaryVersionCalled)
|
|
|
|
} else {
|
|
|
|
assert.True(tc.client.createCryptoKeyCalled)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func TestGetDEK(t *testing.T) {
|
|
|
|
someErr := errors.New("error")
|
|
|
|
testKey := []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
client *stubGCPClient
|
|
|
|
storage kmsInterface.Storage
|
|
|
|
wantErr bool
|
2022-03-25 06:02:02 -04:00
|
|
|
}{
|
|
|
|
"GetDEK successful for new key": {
|
|
|
|
client: &stubGCPClient{},
|
|
|
|
storage: &stubStorage{getErr: storage.ErrDEKUnset},
|
|
|
|
},
|
|
|
|
"GetDEK successful for existing key": {
|
|
|
|
client: &stubGCPClient{decryptResponse: testKey},
|
|
|
|
storage: &stubStorage{key: testKey},
|
|
|
|
},
|
|
|
|
"Get from storage fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{},
|
|
|
|
storage: &stubStorage{getErr: someErr},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-03-25 06:02:02 -04:00
|
|
|
"Encrypt fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{encryptErr: someErr},
|
|
|
|
storage: &stubStorage{getErr: storage.ErrDEKUnset},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"Encrypt fails with notfound error": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{encryptErr: status.Error(codes.NotFound, "error")},
|
|
|
|
storage: &stubStorage{getErr: storage.ErrDEKUnset},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"Put to storage fails": {
|
|
|
|
client: &stubGCPClient{},
|
|
|
|
storage: &stubStorage{
|
|
|
|
getErr: storage.ErrDEKUnset,
|
|
|
|
putErr: someErr,
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"Decrypt fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{decryptErr: someErr},
|
|
|
|
storage: &stubStorage{key: testKey},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"Decrypt fails with notfound error": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{decryptErr: status.Error(codes.NotFound, "error")},
|
|
|
|
storage: &stubStorage{key: testKey},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"creating client fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{createErr: someErr},
|
|
|
|
storage: &stubStorage{getErr: storage.ErrDEKUnset},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := &KMSClient{
|
|
|
|
projectID: "test-project",
|
|
|
|
locationID: "global",
|
|
|
|
keyRingID: "test-ring",
|
|
|
|
newClient: newStubGCPClientFactory(tc.client),
|
|
|
|
protectionLevel: kmspb.ProtectionLevel_SOFTWARE,
|
|
|
|
waitBackoffLimit: 1,
|
|
|
|
storage: tc.storage,
|
|
|
|
}
|
|
|
|
|
|
|
|
dek, err := client.GetDEK(context.Background(), "test-key", "volume-01", 32)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-25 06:02:02 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Len(dek, 32)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func TestConnection(t *testing.T) {
|
|
|
|
someErr := errors.New("error")
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
client *stubGCPClient
|
|
|
|
wantErr bool
|
2022-03-25 06:02:02 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
client: &stubGCPClient{},
|
|
|
|
},
|
|
|
|
"newClient fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{createErr: someErr},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
"GetKeyRing fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
client: &stubGCPClient{getKeyRingErr: someErr},
|
|
|
|
wantErr: true,
|
2022-03-25 06:02:02 -04:00
|
|
|
},
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := &KMSClient{
|
|
|
|
projectID: "test-project",
|
|
|
|
locationID: "global",
|
|
|
|
keyRingID: "test-ring",
|
|
|
|
newClient: newStubGCPClientFactory(tc.client),
|
|
|
|
protectionLevel: kmspb.ProtectionLevel_SOFTWARE,
|
|
|
|
waitBackoffLimit: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := client.testConnection(context.Background())
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-25 06:02:02 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
func TestWrapCryptoKey(t *testing.T) {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
rsaPub, err := util.ParsePEMtoPublicKeyRSA([]byte(testKeyRSA))
|
|
|
|
assert.NoError(err)
|
|
|
|
|
2022-03-25 06:02:02 -04:00
|
|
|
res, err := wrapCryptoKey([]byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), rsaPub)
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(552, len(res))
|
2022-03-25 06:02:02 -04:00
|
|
|
|
|
|
|
_, err = wrapCryptoKey([]byte{0x1}, rsaPub)
|
|
|
|
assert.Error(err)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|