diff --git a/cli/cmd/init.go b/cli/cmd/init.go index 29abb91db..931770f0a 100644 --- a/cli/cmd/init.go +++ b/cli/cmd/init.go @@ -107,7 +107,9 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser endpoints := ipsToEndpoints(append(coordinators.PublicIPs(), nodes.PublicIPs()...), *config.CoordinatorPort) cmd.Println("Waiting for cloud provider to finish resource creation ...") - waiter.InitializeValidators(validators.V()) + if err := waiter.InitializeValidators(validators.V()); err != nil { + return err + } if err := waiter.WaitForAll(ctx, endpoints, coordinatorstate.AcceptingInit); err != nil { return fmt.Errorf("failed to wait for peer status: %w", err) } diff --git a/cli/cmd/statuswaiter.go b/cli/cmd/statuswaiter.go index d87724102..457c03c56 100644 --- a/cli/cmd/statuswaiter.go +++ b/cli/cmd/statuswaiter.go @@ -8,6 +8,6 @@ import ( ) type statusWaiter interface { - InitializeValidators([]atls.Validator) + InitializeValidators([]atls.Validator) error WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error } diff --git a/cli/cmd/statuswaiter_test.go b/cli/cmd/statuswaiter_test.go index 17361e8c0..dbcd78ef5 100644 --- a/cli/cmd/statuswaiter_test.go +++ b/cli/cmd/statuswaiter_test.go @@ -10,11 +10,13 @@ import ( type stubStatusWaiter struct { initialized bool + initializeErr error waitForAllErr error } -func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) { +func (s *stubStatusWaiter) InitializeValidators([]atls.Validator) error { s.initialized = true + return s.initializeErr } func (s *stubStatusWaiter) WaitForAll(ctx context.Context, endpoints []string, status ...state.State) error { diff --git a/cli/status/status.go b/cli/status/status.go index 99ad157d4..c0e148594 100644 --- a/cli/status/status.go +++ b/cli/status/status.go @@ -34,9 +34,13 @@ func NewWaiter() *Waiter { } // InitializeValidators initializes the validators for the attestation. -func (w *Waiter) InitializeValidators(validators []atls.Validator) { +func (w *Waiter) InitializeValidators(validators []atls.Validator) error { + if len(validators) == 0 { + return errors.New("no validators provided to initialize status waiter") + } w.newConn = newAttestedConnGenerator(validators) w.initialized = true + return nil } // WaitFor waits for a PeerStatusServer, which is reachable under the given endpoint diff --git a/cli/status/status_test.go b/cli/status/status_test.go index 08ed3b049..32f5458b0 100644 --- a/cli/status/status_test.go +++ b/cli/status/status_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/edgelesssys/constellation/coordinator/atls" + "github.com/edgelesssys/constellation/coordinator/core" "github.com/edgelesssys/constellation/coordinator/pubapi/pubproto" "github.com/edgelesssys/constellation/coordinator/state" "github.com/stretchr/testify/assert" @@ -23,7 +25,11 @@ func TestInitializeValidators(t *testing.T) { // Uninitialized waiter fails. assert.Error(waiter.WaitFor(context.Background(), "someIP", state.IsNode)) - waiter.InitializeValidators(nil) + // Initializing waiter with no validators fails + assert.Error(waiter.InitializeValidators(nil)) + + // Initialized waiter succeeds + assert.NoError(waiter.InitializeValidators([]atls.Validator{core.NewMockValidator()})) assert.NoError(waiter.WaitFor(context.Background(), "someIP", state.IsNode)) } diff --git a/util/pcr-reader/main.go b/util/pcr-reader/main.go index 0bbad9f13..20ac19f67 100644 --- a/util/pcr-reader/main.go +++ b/util/pcr-reader/main.go @@ -45,11 +45,13 @@ func main() { // wait for coordinator to come online waiter := status.NewWaiter() - waiter.InitializeValidators([]atls.Validator{ + if err := waiter.InitializeValidators([]atls.Validator{ azure.NewValidator(map[uint32][]byte{}), gcp.NewValidator(map[uint32][]byte{}), gcp.NewNonCVMValidator(map[uint32][]byte{}), - }) + }); err != nil { + log.Fatal(err) + } if err := waiter.WaitFor(ctx, addr, state.AcceptingInit, state.ActivatingNodes, state.IsNode, state.NodeWaitingForClusterJoin); err != nil { log.Fatal(err) }