mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-12 01:14:28 -05:00
3a5753045e
rules_go added a SIGTERM handler that has a goroutine that survives the scope of the goleak check. Currently, the best known workaround is to ignore this goroutine. https://github.com/uber-go/goleak/issues/119 https://github.com/bazelbuild/rules_go/pull/3749 https://github.com/bazelbuild/rules_go/pull/3827#issuecomment-1894002120
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package kms
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/edgelesssys/constellation/v2/keyservice/keyserviceproto"
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uber.org/goleak"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/test/bufconn"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
goleak.VerifyTestMain(m, goleak.IgnoreAnyFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"))
|
|
}
|
|
|
|
type stubKMSClient struct {
|
|
getDataKeyErr error
|
|
dataKey []byte
|
|
}
|
|
|
|
func (c *stubKMSClient) GetDataKey(context.Context, *keyserviceproto.GetDataKeyRequest, *grpc.ClientConn) (*keyserviceproto.GetDataKeyResponse, error) {
|
|
return &keyserviceproto.GetDataKeyResponse{DataKey: c.dataKey}, c.getDataKeyErr
|
|
}
|
|
|
|
func TestConstellationKMS(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
kms *stubKMSClient
|
|
wantErr bool
|
|
}{
|
|
"GetDataKey success": {
|
|
kms: &stubKMSClient{dataKey: []byte{0x1, 0x2, 0x3}},
|
|
wantErr: false,
|
|
},
|
|
"GetDataKey error": {
|
|
kms: &stubKMSClient{getDataKeyErr: errors.New("error")},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
listener := bufconn.Listen(1)
|
|
defer listener.Close()
|
|
|
|
kms := &ConstellationKMS{
|
|
endpoint: listener.Addr().String(),
|
|
kms: tc.kms,
|
|
}
|
|
res, err := kms.GetDEK(context.Background(), "data-key", 64)
|
|
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
assert.Nil(res)
|
|
} else {
|
|
assert.NoError(err)
|
|
assert.NotNil(res)
|
|
}
|
|
})
|
|
}
|
|
}
|