From 327315d5de43a26aed78bb50fea1e1647e0d1014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= <66256922+daniel-weisse@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:05:59 +0200 Subject: [PATCH] csi: let constructor take care of setting up cryptsetup (#2312) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- csi/cryptmapper/cryptmapper.go | 4 ++-- csi/cryptmapper/cryptmapper_test.go | 12 ++++++++++-- csi/test/BUILD.bazel | 2 -- csi/test/mount_integration_test.go | 7 +++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/csi/cryptmapper/cryptmapper.go b/csi/cryptmapper/cryptmapper.go index fc7c12494..157233162 100644 --- a/csi/cryptmapper/cryptmapper.go +++ b/csi/cryptmapper/cryptmapper.go @@ -40,9 +40,9 @@ type CryptMapper struct { // New initializes a new CryptMapper with the given kms client and key-encryption-key ID. // kms is used to fetch data encryption keys for the dm-crypt volumes. -func New(kms keyCreator, mapper deviceMapper) *CryptMapper { +func New(kms keyCreator) *CryptMapper { return &CryptMapper{ - mapper: mapper, + mapper: cryptsetup.New(), kms: kms, getDiskFormat: getDiskFormat, } diff --git a/csi/cryptmapper/cryptmapper_test.go b/csi/cryptmapper/cryptmapper_test.go index 8283f4671..cf521e202 100644 --- a/csi/cryptmapper/cryptmapper_test.go +++ b/csi/cryptmapper/cryptmapper_test.go @@ -57,7 +57,11 @@ func TestCloseCryptDevice(t *testing.T) { }) } - mapper := New(&fakeKMS{}, &stubCryptDevice{}) + mapper := &CryptMapper{ + mapper: &stubCryptDevice{}, + kms: &fakeKMS{}, + getDiskFormat: getDiskFormat, + } err := mapper.CloseCryptDevice("volume01-unit-test") assert.NoError(t, err) } @@ -214,7 +218,11 @@ func TestOpenCryptDevice(t *testing.T) { }) } - mapper := New(&fakeKMS{}, &stubCryptDevice{}) + mapper := &CryptMapper{ + mapper: &stubCryptDevice{}, + kms: &fakeKMS{}, + getDiskFormat: getDiskFormat, + } _, err := mapper.OpenCryptDevice(context.Background(), "/dev/some-device", "volume01", false) assert.NoError(t, err) } diff --git a/csi/test/BUILD.bazel b/csi/test/BUILD.bazel index 637e4698a..708827377 100644 --- a/csi/test/BUILD.bazel +++ b/csi/test/BUILD.bazel @@ -8,14 +8,12 @@ go_test( deps = select({ "@io_bazel_rules_go//go/platform:android": [ "//csi/cryptmapper", - "//internal/cryptsetup", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@org_uber_go_goleak//:goleak", ], "@io_bazel_rules_go//go/platform:linux": [ "//csi/cryptmapper", - "//internal/cryptsetup", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@org_uber_go_goleak//:goleak", diff --git a/csi/test/mount_integration_test.go b/csi/test/mount_integration_test.go index ee853f0f8..1075758c0 100644 --- a/csi/test/mount_integration_test.go +++ b/csi/test/mount_integration_test.go @@ -16,7 +16,6 @@ import ( "testing" "github.com/edgelesssys/constellation/v2/csi/cryptmapper" - "github.com/edgelesssys/constellation/v2/internal/cryptsetup" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" @@ -67,7 +66,7 @@ func TestOpenAndClose(t *testing.T) { setup() defer teardown(devicePath) - mapper := cryptmapper.New(&fakeKMS{}, cryptsetup.New()) + mapper := cryptmapper.New(&fakeKMS{}) newPath, err := mapper.OpenCryptDevice(context.Background(), devicePath, deviceName, false) require.NoError(err) @@ -107,7 +106,7 @@ func TestOpenAndCloseIntegrity(t *testing.T) { setup() defer teardown(devicePath) - mapper := cryptmapper.New(&fakeKMS{}, cryptsetup.New()) + mapper := cryptmapper.New(&fakeKMS{}) newPath, err := mapper.OpenCryptDevice(context.Background(), devicePath, deviceName, true) require.NoError(err) @@ -146,7 +145,7 @@ func TestDeviceCloning(t *testing.T) { setup() defer teardown(devicePath) - mapper := cryptmapper.New(&dynamicKMS{}, cryptsetup.New()) + mapper := cryptmapper.New(&dynamicKMS{}) _, err := mapper.OpenCryptDevice(context.Background(), devicePath, deviceName, false) assert.NoError(err)