2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-28 12:33:27 -04:00
|
|
|
package initserver
|
|
|
|
|
|
|
|
import (
|
2023-05-30 07:47:36 -04:00
|
|
|
"bytes"
|
2022-06-28 12:33:27 -04:00
|
|
|
"context"
|
|
|
|
"errors"
|
2023-05-30 07:47:36 -04:00
|
|
|
"io"
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
2022-06-28 12:33:27 -04:00
|
|
|
"net"
|
2022-08-01 03:11:13 -04:00
|
|
|
"strings"
|
2022-07-08 04:59:59 -04:00
|
|
|
"sync"
|
2022-06-28 12:33:27 -04:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/bootstrapper/initproto"
|
2023-01-18 10:49:55 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/atls"
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/crypto/testvector"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
2023-01-16 05:19:03 -05:00
|
|
|
kmssetup "github.com/edgelesssys/constellation/v2/internal/kms/setup"
|
2023-03-02 09:08:31 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
2023-01-06 06:04:36 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/versions/components"
|
2022-06-28 12:33:27 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/goleak"
|
2022-11-26 13:44:34 -05:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
2023-05-30 07:47:36 -04:00
|
|
|
"google.golang.org/grpc"
|
2022-06-28 12:33:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-01-16 05:19:03 -05:00
|
|
|
goleak.VerifyTestMain(m,
|
|
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
2024-01-16 11:45:35 -05:00
|
|
|
goleak.IgnoreAnyFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"),
|
2023-01-16 05:19:03 -05:00
|
|
|
)
|
2022-06-28 12:33:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNew(t *testing.T) {
|
2022-07-05 08:14:11 -04:00
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
2022-11-26 13:44:34 -05:00
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
metadata stubMetadata
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
metadata: stubMetadata{initSecretHashVal: []byte("hash")},
|
|
|
|
},
|
|
|
|
"empty init secret hash": {
|
|
|
|
metadata: stubMetadata{initSecretHashVal: nil},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"metadata error": {
|
|
|
|
metadata: stubMetadata{initSecretHashErr: errors.New("error")},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2024-03-12 06:43:38 -04:00
|
|
|
server, err := New(
|
|
|
|
context.TODO(), newFakeLock(), &stubClusterInitializer{}, atls.NewFakeIssuer(variant.Dummy{}),
|
|
|
|
&stubDisk{}, fh, &tc.metadata, logger.NewTest(t),
|
|
|
|
)
|
2022-11-26 13:44:34 -05:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NotNil(server)
|
|
|
|
assert.NotEmpty(server.initSecretHash)
|
|
|
|
assert.NotNil(server.log)
|
|
|
|
assert.NotNil(server.nodeLock)
|
|
|
|
assert.NotNil(server.initializer)
|
|
|
|
assert.NotNil(server.grpcServer)
|
|
|
|
assert.NotNil(server.fileHandler)
|
|
|
|
assert.NotNil(server.disk)
|
|
|
|
})
|
|
|
|
}
|
2022-06-28 12:33:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
someErr := errors.New("failed")
|
2022-07-08 04:59:59 -04:00
|
|
|
lockedLock := newFakeLock()
|
2022-07-26 04:58:39 -04:00
|
|
|
aqcuiredLock, lockErr := lockedLock.TryLockOnce(nil)
|
2022-07-08 04:59:59 -04:00
|
|
|
require.True(t, aqcuiredLock)
|
|
|
|
require.Nil(t, lockErr)
|
2022-06-28 12:33:27 -04:00
|
|
|
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecret := []byte("password")
|
|
|
|
initSecretHash, err := bcrypt.GenerateFromPassword(initSecret, bcrypt.DefaultCost)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
masterSecret := uri.MasterSecret{Key: []byte("secret"), Salt: []byte("salt")}
|
2023-01-16 05:19:03 -05:00
|
|
|
|
2022-06-28 12:33:27 -04:00
|
|
|
testCases := map[string]struct {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock *fakeLock
|
|
|
|
initializer ClusterInitializer
|
|
|
|
disk encryptedDisk
|
|
|
|
fileHandler file.Handler
|
|
|
|
req *initproto.InitRequest
|
2023-05-30 07:47:36 -04:00
|
|
|
stream stubStream
|
|
|
|
logCollector stubJournaldCollector
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash []byte
|
|
|
|
wantErr bool
|
|
|
|
wantShutdown bool
|
2022-06-28 12:33:27 -04:00
|
|
|
}{
|
|
|
|
"successful init": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
|
|
|
initSecretHash: initSecretHash,
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"node locked": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: lockedLock,
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"disk open error": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{openErr: someErr},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"disk uuid error": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{uuidErr: someErr},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"disk update passphrase error": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{updatePassphraseErr: someErr},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"write state file error": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{},
|
|
|
|
fileHandler: file.NewHandler(afero.NewReadOnlyFs(afero.NewMemMapFs())),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
"initialize cluster error": {
|
2022-11-26 13:44:34 -05:00
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{initClusterErr: someErr},
|
|
|
|
disk: &stubDisk{},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
2023-03-02 09:08:31 -05:00
|
|
|
req: &initproto.InitRequest{InitSecret: initSecret, KmsUri: masterSecret.EncodeToURI(), StorageUri: uri.NoStoreURI},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
wantErr: true,
|
2023-03-03 10:50:01 -05:00
|
|
|
wantShutdown: true,
|
2022-11-26 13:44:34 -05:00
|
|
|
},
|
|
|
|
"wrong initSecret": {
|
|
|
|
nodeLock: newFakeLock(),
|
|
|
|
initializer: &stubClusterInitializer{},
|
|
|
|
disk: &stubDisk{},
|
|
|
|
fileHandler: file.NewHandler(afero.NewMemMapFs()),
|
|
|
|
initSecretHash: initSecretHash,
|
|
|
|
req: &initproto.InitRequest{InitSecret: []byte("wrongpassword")},
|
2023-05-30 07:47:36 -04:00
|
|
|
stream: stubStream{},
|
|
|
|
logCollector: stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte{})}},
|
2022-11-26 13:44:34 -05:00
|
|
|
wantErr: true,
|
2022-06-28 12:33:27 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
serveStopper := newStubServeStopper()
|
|
|
|
server := &Server{
|
2023-05-30 07:47:36 -04:00
|
|
|
nodeLock: tc.nodeLock,
|
|
|
|
initializer: tc.initializer,
|
|
|
|
disk: tc.disk,
|
|
|
|
fileHandler: tc.fileHandler,
|
|
|
|
log: logger.NewTest(t),
|
|
|
|
grpcServer: serveStopper,
|
|
|
|
cleaner: &fakeCleaner{serveStopper: serveStopper},
|
|
|
|
initSecretHash: tc.initSecretHash,
|
|
|
|
journaldCollector: &tc.logCollector,
|
2022-06-28 12:33:27 -04:00
|
|
|
}
|
|
|
|
|
2023-05-30 07:47:36 -04:00
|
|
|
err := server.Init(tc.req, &tc.stream)
|
2022-06-28 12:33:27 -04:00
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
|
|
|
|
if tc.wantShutdown {
|
|
|
|
select {
|
|
|
|
case <-serveStopper.shutdownCalled:
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
t.Fatal("grpc server did not shut down")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-30 07:47:36 -04:00
|
|
|
for _, res := range tc.stream.res {
|
|
|
|
assert.NotNil(res.GetInitSuccess())
|
|
|
|
}
|
2022-06-28 12:33:27 -04:00
|
|
|
assert.NoError(err)
|
2022-07-26 04:58:39 -04:00
|
|
|
assert.False(server.nodeLock.TryLockOnce(nil)) // lock should be locked
|
2022-06-28 12:33:27 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-30 07:47:36 -04:00
|
|
|
func TestSendLogsWithMessage(t *testing.T) {
|
|
|
|
someError := errors.New("failed")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
logCollector journaldCollection
|
|
|
|
stream stubStream
|
|
|
|
failureMessage string
|
|
|
|
expectedResult string
|
|
|
|
expectedFailureMessage string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
logCollector: &stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte("asdf"))}},
|
|
|
|
stream: stubStream{},
|
|
|
|
failureMessage: "fdsa",
|
|
|
|
expectedResult: "asdf",
|
|
|
|
expectedFailureMessage: "fdsa",
|
|
|
|
},
|
|
|
|
"fail collection": {
|
|
|
|
logCollector: &stubJournaldCollector{collectErr: someError},
|
|
|
|
failureMessage: "fdsa",
|
|
|
|
wantErr: true,
|
|
|
|
expectedFailureMessage: "fdsa",
|
|
|
|
},
|
|
|
|
"fail to send": {
|
|
|
|
logCollector: &stubJournaldCollector{logPipe: &stubReadCloser{reader: bytes.NewReader([]byte("asdf"))}},
|
|
|
|
stream: stubStream{sendError: someError},
|
|
|
|
failureMessage: "fdsa",
|
|
|
|
wantErr: true,
|
|
|
|
expectedFailureMessage: "fdsa",
|
|
|
|
},
|
|
|
|
"fail to read": {
|
|
|
|
logCollector: &stubJournaldCollector{logPipe: &stubReadCloser{readErr: someError}},
|
|
|
|
failureMessage: "fdsa",
|
|
|
|
wantErr: true,
|
|
|
|
expectedFailureMessage: "fdsa",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
serverStopper := newStubServeStopper()
|
|
|
|
server := &Server{
|
|
|
|
grpcServer: serverStopper,
|
|
|
|
journaldCollector: tc.logCollector,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := server.sendLogsWithMessage(&tc.stream, errors.New(tc.failureMessage))
|
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(tc.stream.res[0].GetInitFailure().GetError(), tc.expectedFailureMessage)
|
|
|
|
|
|
|
|
assert.NoError(err)
|
|
|
|
for _, res := range tc.stream.res[1:] {
|
|
|
|
assert.Equal(tc.expectedResult, string(res.GetLog().Log))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-01 03:11:13 -04:00
|
|
|
func TestSetupDisk(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2023-01-16 05:19:03 -05:00
|
|
|
uuid string
|
|
|
|
masterKey []byte
|
|
|
|
salt []byte
|
|
|
|
wantKey []byte
|
2022-08-01 03:11:13 -04:00
|
|
|
}{
|
|
|
|
"lower case uuid": {
|
2023-01-16 05:19:03 -05:00
|
|
|
uuid: strings.ToLower(testvector.HKDF0xFF.Info),
|
|
|
|
masterKey: testvector.HKDF0xFF.Secret,
|
|
|
|
salt: testvector.HKDF0xFF.Salt,
|
|
|
|
wantKey: testvector.HKDF0xFF.Output,
|
2022-08-01 03:11:13 -04:00
|
|
|
},
|
|
|
|
"upper case uuid": {
|
2023-01-16 05:19:03 -05:00
|
|
|
uuid: strings.ToUpper(testvector.HKDF0xFF.Info),
|
|
|
|
masterKey: testvector.HKDF0xFF.Secret,
|
|
|
|
salt: testvector.HKDF0xFF.Salt,
|
|
|
|
wantKey: testvector.HKDF0xFF.Output,
|
2022-08-01 03:11:13 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2023-01-16 05:19:03 -05:00
|
|
|
require := require.New(t)
|
2022-08-01 03:11:13 -04:00
|
|
|
|
|
|
|
disk := &fakeDisk{
|
|
|
|
uuid: tc.uuid,
|
|
|
|
wantKey: tc.wantKey,
|
|
|
|
}
|
|
|
|
server := &Server{
|
|
|
|
disk: disk,
|
|
|
|
}
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
masterSecret := uri.MasterSecret{Key: tc.masterKey, Salt: tc.salt}
|
2023-01-16 05:19:03 -05:00
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
cloudKms, err := kmssetup.KMS(context.Background(), uri.NoStoreURI, masterSecret.EncodeToURI())
|
2023-01-16 05:19:03 -05:00
|
|
|
require.NoError(err)
|
|
|
|
assert.NoError(server.setupDisk(context.Background(), cloudKms))
|
2022-08-01 03:11:13 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeDisk struct {
|
|
|
|
uuid string
|
|
|
|
wantKey []byte
|
|
|
|
}
|
|
|
|
|
2023-07-17 07:55:31 -04:00
|
|
|
func (d *fakeDisk) Open() (func(), error) {
|
|
|
|
return func() {}, nil
|
2022-08-01 03:11:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *fakeDisk) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *fakeDisk) UUID() (string, error) {
|
|
|
|
return d.uuid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *fakeDisk) UpdatePassphrase(passphrase string) error {
|
|
|
|
if passphrase != string(d.wantKey) {
|
|
|
|
return errors.New("wrong passphrase")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-12 06:43:38 -04:00
|
|
|
func (d *fakeDisk) MarkDiskForReset() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 12:33:27 -04:00
|
|
|
type stubDisk struct {
|
|
|
|
openErr error
|
|
|
|
uuid string
|
|
|
|
uuidErr error
|
|
|
|
updatePassphraseErr error
|
|
|
|
updatePassphraseCalled bool
|
|
|
|
}
|
|
|
|
|
2023-07-17 07:55:31 -04:00
|
|
|
func (d *stubDisk) Open() (func(), error) {
|
|
|
|
return func() {}, d.openErr
|
2022-06-28 12:33:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *stubDisk) UUID() (string, error) {
|
|
|
|
return d.uuid, d.uuidErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *stubDisk) UpdatePassphrase(string) error {
|
|
|
|
d.updatePassphraseCalled = true
|
|
|
|
return d.updatePassphraseErr
|
|
|
|
}
|
|
|
|
|
2024-03-12 06:43:38 -04:00
|
|
|
func (d *stubDisk) MarkDiskForReset() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 12:33:27 -04:00
|
|
|
type stubClusterInitializer struct {
|
|
|
|
initClusterKubeconfig []byte
|
|
|
|
initClusterErr error
|
|
|
|
}
|
|
|
|
|
2022-08-12 09:59:45 -04:00
|
|
|
func (i *stubClusterInitializer) InitCluster(
|
2023-07-31 04:53:05 -04:00
|
|
|
context.Context, string, string,
|
2024-02-08 09:20:01 -05:00
|
|
|
bool, components.Components, []string, string, *slog.Logger,
|
2022-06-28 12:33:27 -04:00
|
|
|
) ([]byte, error) {
|
|
|
|
return i.initClusterKubeconfig, i.initClusterErr
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubServeStopper struct {
|
|
|
|
shutdownCalled chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newStubServeStopper() *stubServeStopper {
|
|
|
|
return &stubServeStopper{shutdownCalled: make(chan struct{}, 1)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubServeStopper) Serve(net.Listener) error {
|
|
|
|
panic("should not be called in a test")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubServeStopper) GracefulStop() {
|
|
|
|
s.shutdownCalled <- struct{}{}
|
|
|
|
}
|
2022-07-08 04:59:59 -04:00
|
|
|
|
|
|
|
type fakeLock struct {
|
|
|
|
state *sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFakeLock() *fakeLock {
|
|
|
|
return &fakeLock{
|
|
|
|
state: &sync.Mutex{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 04:58:39 -04:00
|
|
|
func (l *fakeLock) TryLockOnce(_ []byte) (bool, error) {
|
2022-07-08 04:59:59 -04:00
|
|
|
return l.state.TryLock(), nil
|
|
|
|
}
|
2022-07-14 09:45:04 -04:00
|
|
|
|
|
|
|
type fakeCleaner struct {
|
|
|
|
serveStopper
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeCleaner) Clean() {
|
|
|
|
go f.serveStopper.GracefulStop() // this is not the correct way to do this, but it's fine for testing
|
|
|
|
}
|
2022-11-26 13:44:34 -05:00
|
|
|
|
|
|
|
type stubMetadata struct {
|
|
|
|
initSecretHashVal []byte
|
|
|
|
initSecretHashErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *stubMetadata) InitSecretHash(context.Context) ([]byte, error) {
|
|
|
|
return m.initSecretHashVal, m.initSecretHashErr
|
|
|
|
}
|
2023-05-30 07:47:36 -04:00
|
|
|
|
|
|
|
type stubStream struct {
|
|
|
|
res []*initproto.InitResponse
|
|
|
|
sendError error
|
|
|
|
grpc.ServerStream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubStream) Send(m *initproto.InitResponse) error {
|
|
|
|
if s.sendError == nil {
|
|
|
|
// we append here since we don't receive anything
|
|
|
|
// if that if doesn't trigger
|
|
|
|
s.res = append(s.res, m)
|
|
|
|
}
|
|
|
|
return s.sendError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubStream) Context() context.Context {
|
|
|
|
return context.Background()
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubJournaldCollector struct {
|
|
|
|
logPipe io.ReadCloser
|
|
|
|
collectErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubJournaldCollector) Start() (io.ReadCloser, error) {
|
|
|
|
return s.logPipe, s.collectErr
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubReadCloser struct {
|
|
|
|
reader io.Reader
|
|
|
|
readErr error
|
|
|
|
closeErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubReadCloser) Read(p []byte) (n int, err error) {
|
|
|
|
if s.readErr != nil {
|
|
|
|
return 0, s.readErr
|
|
|
|
}
|
|
|
|
return s.reader.Read(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubReadCloser) Close() error {
|
|
|
|
return s.closeErr
|
|
|
|
}
|