2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2022-09-08 08:45:27 -04:00
|
|
|
"context"
|
2022-04-11 08:25:19 -04:00
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"io/fs"
|
2022-09-08 08:45:27 -04:00
|
|
|
"net"
|
2022-04-11 08:25:19 -04:00
|
|
|
"path/filepath"
|
2022-09-08 08:45:27 -04:00
|
|
|
"sync"
|
2022-04-11 08:25:19 -04:00
|
|
|
"testing"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/vtpm"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/crypto"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/nodestate"
|
2022-04-11 08:25:19 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-04-11 08:25:19 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
2022-11-14 03:02:56 -05:00
|
|
|
goleak.VerifyTestMain(m)
|
2022-06-30 09:24:36 -04:00
|
|
|
}
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
func TestPrepareExistingDisk(t *testing.T) {
|
|
|
|
someErr := errors.New("error")
|
2022-09-08 08:45:27 -04:00
|
|
|
testRecoveryDoer := &stubRecoveryDoer{
|
|
|
|
passphrase: []byte("passphrase"),
|
|
|
|
secret: []byte("secret"),
|
|
|
|
}
|
2022-04-11 08:25:19 -04:00
|
|
|
|
|
|
|
testCases := map[string]struct {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer *stubRecoveryDoer
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper *stubMapper
|
|
|
|
mounter *stubMounter
|
|
|
|
configGenerator *stubConfigurationGenerator
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice vtpm.TPMOpenFunc
|
2022-08-15 08:50:03 -04:00
|
|
|
missingState bool
|
|
|
|
wantErr bool
|
2022-04-11 08:25:19 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"WaitForDecryptionKey fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: &stubRecoveryDoer{recoveryErr: someErr},
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
2022-09-08 08:45:27 -04:00
|
|
|
"MapDisk fails": {
|
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-04-11 08:25:19 -04:00
|
|
|
mapper: &stubMapper{
|
2022-09-08 08:45:27 -04:00
|
|
|
uuid: "test",
|
|
|
|
mapDiskErr: someErr,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
2022-08-15 08:50:03 -04:00
|
|
|
mounter: &stubMounter{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-09-08 08:45:27 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"MkdirAll fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{mkdirAllErr: someErr},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"Mount fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{mountErr: someErr},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"Unmount fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{unmountErr: someErr},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
2022-08-17 07:50:43 -04:00
|
|
|
"MarkNodeAsBootstrapped fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{unmountErr: someErr},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: failOpener,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Generating config fails": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{generateErr: someErr},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: failOpener,
|
2022-08-15 08:50:03 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"no state file": {
|
2022-09-08 08:45:27 -04:00
|
|
|
recoveryDoer: testRecoveryDoer,
|
2022-08-15 08:50:03 -04:00
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
mounter: &stubMounter{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2023-03-14 09:17:36 -04:00
|
|
|
openDevice: vtpm.OpenNOPTPM,
|
2022-08-15 08:50:03 -04:00
|
|
|
missingState: true,
|
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2022-08-15 08:50:03 -04:00
|
|
|
fs := afero.Afero{Fs: afero.NewMemMapFs()}
|
2022-07-26 04:58:39 -04:00
|
|
|
salt := []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
2022-04-11 08:25:19 -04:00
|
|
|
if !tc.missingState {
|
2022-08-15 08:50:03 -04:00
|
|
|
handler := file.NewHandler(fs)
|
2022-07-26 04:58:39 -04:00
|
|
|
require.NoError(t, handler.WriteJSON(stateInfoPath, nodestate.NodeState{MeasurementSalt: salt}, file.OptMkdirAll))
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2022-10-05 09:02:46 -04:00
|
|
|
setupManager := &Manager{
|
2023-03-14 09:17:36 -04:00
|
|
|
log: logger.NewTest(t),
|
|
|
|
csp: "test",
|
|
|
|
diskPath: "disk-path",
|
|
|
|
fs: fs,
|
|
|
|
mapper: tc.mapper,
|
|
|
|
mounter: tc.mounter,
|
|
|
|
config: tc.configGenerator,
|
|
|
|
openDevice: tc.openDevice,
|
2022-08-15 08:50:03 -04:00
|
|
|
}
|
2022-04-11 08:25:19 -04:00
|
|
|
|
2022-09-08 08:45:27 -04:00
|
|
|
err := setupManager.PrepareExistingDisk(tc.recoveryDoer)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-04-11 08:25:19 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(tc.mapper.mapDiskCalled)
|
|
|
|
assert.True(tc.mounter.mountCalled)
|
|
|
|
assert.True(tc.mounter.unmountCalled)
|
|
|
|
assert.False(tc.mapper.formatDiskCalled)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func failOpener() (io.ReadWriteCloser, error) {
|
|
|
|
return nil, errors.New("error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrepareNewDisk(t *testing.T) {
|
|
|
|
someErr := errors.New("error")
|
|
|
|
testCases := map[string]struct {
|
2022-08-15 08:50:03 -04:00
|
|
|
fs afero.Afero
|
|
|
|
mapper *stubMapper
|
|
|
|
configGenerator *stubConfigurationGenerator
|
|
|
|
wantErr bool
|
2022-04-11 08:25:19 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2022-08-15 08:50:03 -04:00
|
|
|
fs: afero.Afero{Fs: afero.NewMemMapFs()},
|
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"creating directory fails": {
|
2022-08-15 08:50:03 -04:00
|
|
|
fs: afero.Afero{Fs: afero.NewReadOnlyFs(afero.NewMemMapFs())},
|
|
|
|
mapper: &stubMapper{},
|
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"FormatDisk fails": {
|
|
|
|
fs: afero.Afero{Fs: afero.NewMemMapFs()},
|
|
|
|
mapper: &stubMapper{
|
|
|
|
uuid: "test",
|
|
|
|
formatDiskErr: someErr,
|
|
|
|
},
|
2022-08-15 08:50:03 -04:00
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
"MapDisk fails": {
|
|
|
|
fs: afero.Afero{Fs: afero.NewMemMapFs()},
|
|
|
|
mapper: &stubMapper{
|
2022-09-08 08:45:27 -04:00
|
|
|
uuid: "test",
|
|
|
|
mapDiskErr: someErr,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
2022-08-15 08:50:03 -04:00
|
|
|
configGenerator: &stubConfigurationGenerator{},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Generating config fails": {
|
|
|
|
fs: afero.Afero{Fs: afero.NewMemMapFs()},
|
|
|
|
mapper: &stubMapper{uuid: "test"},
|
|
|
|
configGenerator: &stubConfigurationGenerator{generateErr: someErr},
|
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2022-10-05 09:02:46 -04:00
|
|
|
setupManager := &Manager{
|
2022-08-15 08:50:03 -04:00
|
|
|
log: logger.NewTest(t),
|
|
|
|
csp: "test",
|
|
|
|
diskPath: "disk-path",
|
|
|
|
fs: tc.fs,
|
|
|
|
mapper: tc.mapper,
|
|
|
|
config: tc.configGenerator,
|
|
|
|
}
|
2022-04-11 08:25:19 -04:00
|
|
|
|
|
|
|
err := setupManager.PrepareNewDisk()
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-04-11 08:25:19 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(tc.mapper.formatDiskCalled)
|
|
|
|
assert.True(tc.mapper.mapDiskCalled)
|
|
|
|
|
|
|
|
data, err := tc.fs.ReadFile(filepath.Join(keyPath, keyFile))
|
|
|
|
require.NoError(t, err)
|
2022-07-26 04:58:39 -04:00
|
|
|
assert.Len(data, crypto.RNGLengthDefault)
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 04:58:39 -04:00
|
|
|
func TestReadMeasurementSalt(t *testing.T) {
|
|
|
|
salt := []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
2022-04-11 08:25:19 -04:00
|
|
|
testCases := map[string]struct {
|
2022-07-26 04:58:39 -04:00
|
|
|
salt []byte
|
2022-04-26 10:54:05 -04:00
|
|
|
writeFile bool
|
|
|
|
wantErr bool
|
2022-04-11 08:25:19 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2022-07-26 04:58:39 -04:00
|
|
|
salt: salt,
|
2022-04-11 08:25:19 -04:00
|
|
|
writeFile: true,
|
|
|
|
},
|
|
|
|
"no state file": {
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
2022-07-26 04:58:39 -04:00
|
|
|
"missing salt": {
|
2022-04-26 10:54:05 -04:00
|
|
|
writeFile: true,
|
|
|
|
wantErr: true,
|
2022-04-11 08:25:19 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
2022-08-15 08:50:03 -04:00
|
|
|
fs := afero.Afero{Fs: afero.NewMemMapFs()}
|
2022-04-11 08:25:19 -04:00
|
|
|
if tc.writeFile {
|
2022-08-15 08:50:03 -04:00
|
|
|
handler := file.NewHandler(fs)
|
2022-07-26 04:58:39 -04:00
|
|
|
state := nodestate.NodeState{MeasurementSalt: tc.salt}
|
|
|
|
require.NoError(handler.WriteJSON("test-state.json", state, file.OptMkdirAll))
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2022-09-08 08:45:27 -04:00
|
|
|
setupManager := New(logger.NewTest(t), "test", "disk-path", fs, nil, nil, nil)
|
2022-04-11 08:25:19 -04:00
|
|
|
|
2022-07-26 04:58:39 -04:00
|
|
|
measurementSalt, err := setupManager.readMeasurementSalt("test-state.json")
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-04-11 08:25:19 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
2022-07-26 04:58:39 -04:00
|
|
|
assert.Equal(tc.salt, measurementSalt)
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 08:45:27 -04:00
|
|
|
func TestRecoveryDoer(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
rejoinClientKey := []byte("rejoinClientKey")
|
|
|
|
rejoinClientSecret := []byte("rejoinClientSecret")
|
|
|
|
recoveryServerKey := []byte("recoveryServerKey")
|
|
|
|
recoveryServerSecret := []byte("recoveryServerSecret")
|
|
|
|
|
|
|
|
recoveryServerErr := errors.New("error")
|
|
|
|
recoveryServer := &stubRecoveryServer{
|
|
|
|
key: recoveryServerKey,
|
|
|
|
secret: recoveryServerSecret,
|
|
|
|
sendKeys: make(chan struct{}, 1),
|
|
|
|
err: recoveryServerErr,
|
|
|
|
}
|
|
|
|
rejoinClient := &stubRejoinClient{
|
|
|
|
key: rejoinClientKey,
|
|
|
|
secret: rejoinClientSecret,
|
|
|
|
sendKeys: make(chan struct{}, 1),
|
|
|
|
}
|
|
|
|
recoverer := NewNodeRecoverer(recoveryServer, rejoinClient)
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var key, secret []byte
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// error from recovery server
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
key, secret, err = recoverer.Do("", "")
|
|
|
|
}()
|
|
|
|
recoveryServer.sendKeys <- struct{}{}
|
|
|
|
wg.Wait()
|
|
|
|
assert.ErrorIs(err, recoveryServerErr)
|
|
|
|
|
|
|
|
recoveryServer.err = nil
|
|
|
|
recoveryServer.sendKeys = make(chan struct{}, 1)
|
|
|
|
|
|
|
|
// recovery server returns its key and secret
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
key, secret, err = recoverer.Do("", "")
|
|
|
|
}()
|
|
|
|
recoveryServer.sendKeys <- struct{}{}
|
|
|
|
wg.Wait()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(recoveryServerKey, key)
|
|
|
|
assert.Equal(recoveryServerSecret, secret)
|
|
|
|
|
|
|
|
recoveryServer.sendKeys = make(chan struct{}, 1)
|
|
|
|
|
|
|
|
// rejoin client returns its key and secret
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
key, secret, err = recoverer.Do("", "")
|
|
|
|
}()
|
|
|
|
rejoinClient.sendKeys <- struct{}{}
|
|
|
|
wg.Wait()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(rejoinClientKey, key)
|
|
|
|
assert.Equal(rejoinClientSecret, secret)
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubRecoveryServer struct {
|
|
|
|
key []byte
|
|
|
|
secret []byte
|
|
|
|
sendKeys chan struct{}
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubRecoveryServer) Serve(ctx context.Context, _ net.Listener, _ string) ([]byte, []byte, error) {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, nil, ctx.Err()
|
|
|
|
case <-s.sendKeys:
|
|
|
|
return s.key, s.secret, s.err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubRejoinClient struct {
|
|
|
|
key []byte
|
|
|
|
secret []byte
|
|
|
|
sendKeys chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubRejoinClient) Start(ctx context.Context, _ string) ([]byte, []byte) {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, nil
|
|
|
|
case <-s.sendKeys:
|
|
|
|
return s.key, s.secret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
type stubMapper struct {
|
2022-09-08 08:45:27 -04:00
|
|
|
formatDiskCalled bool
|
|
|
|
formatDiskErr error
|
|
|
|
mapDiskCalled bool
|
|
|
|
mapDiskErr error
|
|
|
|
unmapDiskCalled bool
|
|
|
|
unmapDiskErr error
|
|
|
|
uuid string
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2023-07-17 07:55:31 -04:00
|
|
|
func (s *stubMapper) DiskUUID() (string, error) {
|
|
|
|
return s.uuid, nil
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2022-08-02 06:35:23 -04:00
|
|
|
func (s *stubMapper) FormatDisk(string) error {
|
2022-04-11 08:25:19 -04:00
|
|
|
s.formatDiskCalled = true
|
|
|
|
return s.formatDiskErr
|
|
|
|
}
|
|
|
|
|
2022-08-02 06:35:23 -04:00
|
|
|
func (s *stubMapper) MapDisk(string, string) error {
|
2022-04-11 08:25:19 -04:00
|
|
|
s.mapDiskCalled = true
|
|
|
|
return s.mapDiskErr
|
|
|
|
}
|
|
|
|
|
2022-08-15 08:50:03 -04:00
|
|
|
func (s *stubMapper) UnmapDisk(string) error {
|
|
|
|
s.unmapDiskCalled = true
|
|
|
|
return s.unmapDiskErr
|
|
|
|
}
|
|
|
|
|
2023-07-18 10:20:03 -04:00
|
|
|
func (s *stubMapper) SetDiskToInitialized() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
type stubMounter struct {
|
|
|
|
mountCalled bool
|
|
|
|
mountErr error
|
|
|
|
unmountCalled bool
|
|
|
|
unmountErr error
|
|
|
|
mkdirAllErr error
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *stubMounter) Mount(_ string, _ string, _ string, _ uintptr, _ string) error {
|
2022-04-11 08:25:19 -04:00
|
|
|
s.mountCalled = true
|
|
|
|
return s.mountErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *stubMounter) Unmount(_ string, _ int) error {
|
2022-04-11 08:25:19 -04:00
|
|
|
s.unmountCalled = true
|
|
|
|
return s.unmountErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *stubMounter) MkdirAll(_ string, _ fs.FileMode) error {
|
2022-04-11 08:25:19 -04:00
|
|
|
return s.mkdirAllErr
|
|
|
|
}
|
|
|
|
|
2022-09-08 08:45:27 -04:00
|
|
|
type stubRecoveryDoer struct {
|
|
|
|
passphrase []byte
|
|
|
|
secret []byte
|
|
|
|
recoveryErr error
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *stubRecoveryDoer) Do(_, _ string) (passphrase, measurementSecret []byte, err error) {
|
2022-09-08 08:45:27 -04:00
|
|
|
return s.passphrase, s.secret, s.recoveryErr
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
2022-08-15 08:50:03 -04:00
|
|
|
|
|
|
|
type stubConfigurationGenerator struct {
|
|
|
|
generateErr error
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *stubConfigurationGenerator) Generate(_, _, _, _ string) error {
|
2022-08-15 08:50:03 -04:00
|
|
|
return s.generateErr
|
|
|
|
}
|