diff --git a/node/changeHandlers_test.go b/node/changeHandlers_test.go index 50b48421489749cb905e2669364d3bd2845e9778..dcebeece018f583e572eb193eed75f1bc7aed824 100644 --- a/node/changeHandlers_test.go +++ b/node/changeHandlers_test.go @@ -103,14 +103,6 @@ func TestNewStateChanges(t *testing.T) { } } -/*func TestNotStarted_RoundError(t *testing.T) { - instance, _ := setup(t) - err := NotStarted(instance, true) - if err != nil { - t.Error(err) - } -}*/ - func TestError(t *testing.T) { instance, topology := setup(t) rndErr := &mixmessages.RoundError{ @@ -301,8 +293,8 @@ func TestPrecomputing_override(t *testing.T) { } rnd, _ := instance.GetRoundManager().GetRound(id.Round(1)) - phase, _ := rnd.GetPhase(phase.PrecompGeneration) - if phase.GetTimeout() != 30127 { + precompPhase, _ := rnd.GetPhase(phase.PrecompGeneration) + if precompPhase.GetTimeout() != 30127 { t.Error("Failed to override phase") } } @@ -310,13 +302,15 @@ func TestPrecomputing_override(t *testing.T) { // Smoke test: does isRegistered communicate with permissioning server? func TestIsRegistered(t *testing.T) { // Create instance - instance, err := createServerInstance(t) + instance, pAddr, nAddr, nodeId, cert, key, err := createServerInstance(t) + if err != nil { t.Errorf("Couldn't create instance: %+v", err) } // Start up permissioning server - permComms, mockPermissioning, err := startPermissioning() + permComms, mockPermissioning, err := startPermissioning(pAddr, nAddr, nodeId, cert, key, t) + if err != nil { t.Errorf("Couldn't create permissioning server: %+v", err) } diff --git a/node/mockserver_test.go b/node/mockserver_test.go index ccf57152a160b1d719a15788a229b1d8a5016514..bf97f7fb197d02263185cec993bb5e6b72e0a908 100644 --- a/node/mockserver_test.go +++ b/node/mockserver_test.go @@ -11,9 +11,6 @@ import ( crand "crypto/rand" "fmt" "github.com/pkg/errors" - jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/comms/gateway" - "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/node" "gitlab.com/elixxir/comms/registration" @@ -24,27 +21,20 @@ import ( "gitlab.com/elixxir/primitives/current" "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/ndf" - "gitlab.com/elixxir/primitives/states" "gitlab.com/elixxir/primitives/utils" "gitlab.com/elixxir/server/internal" - "gitlab.com/elixxir/server/internal/measure" "gitlab.com/elixxir/server/internal/state" "gitlab.com/elixxir/server/io" "gitlab.com/elixxir/server/services" "gitlab.com/elixxir/server/testUtil" "gitlab.com/xx_network/comms/connect" - "math/rand" + "sync" "testing" "time" ) -var nodeId *id.ID -var permComms *registration.Comms -var gwComms *gateway.Comms -var testNdf *ndf.NetworkDefinition -var pAddr string -var cnt = 0 -var nodeAddr string +var count = 0 +var countLock sync.Mutex // --------------------------------Dummy implementation of permissioning server -------------------------------- type mockPermission struct { @@ -71,8 +61,14 @@ func (i *mockPermission) Poll(*pb.PermissioningPoll, *connect.Auth, string) (*pb fullNDFMsg := &pb.NDF{Ndf: fullNdf} partialNDFMsg := &pb.NDF{Ndf: stripNdf} - signNdf(fullNDFMsg) - signNdf(partialNDFMsg) + err := signNdf(fullNDFMsg) + if err != nil { + return nil, errors.Errorf("Failed to sign full Ndf: %+v", err) + } + err = signNdf(partialNDFMsg) + if err != nil { + return nil, errors.Errorf("Failed to sign partial NDF: %+v", err) + } return &pb.PermissionPollResponse{ FullNDF: fullNDFMsg, @@ -99,188 +95,6 @@ func (i *mockPermission) GetUpdatedNDF(clientNDFHash []byte) ([]byte, error) { return nil, i.err } -// --------------------------------Dummy implementation of permissioning server -------------------------------- -type mockPermissionMultipleRounds struct{} - -func (i *mockPermissionMultipleRounds) PollNdf([]byte, *connect.Auth) ([]byte, error) { - return nil, nil -} - -func (i *mockPermissionMultipleRounds) RegisterUser(registrationCode, test string) (hash []byte, err error) { - return nil, nil -} - -func (i *mockPermissionMultipleRounds) RegisterNode([]byte, string, string, string, string, string) error { - return nil -} - -func (i *mockPermissionMultipleRounds) CheckRegistration(msg *pb.RegisteredNodeCheck) (confirmation *pb.RegisteredNodeConfirmation, e error) { - return nil, nil -} - -func (i *mockPermissionMultipleRounds) Poll(*pb.PermissioningPoll, *connect.Auth, string) (*pb.PermissionPollResponse, error) { - ourNdf := testUtil.NDF - fullNdf, _ := ourNdf.Marshal() - stripNdf, _ := ourNdf.StripNdf().Marshal() - - fullNDFMsg := &pb.NDF{Ndf: fullNdf} - partialNDFMsg := &pb.NDF{Ndf: stripNdf} - - signNdf(fullNDFMsg) - signNdf(partialNDFMsg) - - ourRoundInfoList := buildRoundInfoMessages() - - return &pb.PermissionPollResponse{ - FullNDF: fullNDFMsg, - PartialNDF: partialNDFMsg, - Updates: ourRoundInfoList, - }, nil -} - -func buildRoundInfoMessages() []*pb.RoundInfo { - numUpdates := uint64(0) - - node1 := []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} - node2 := []byte{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} - node3 := []byte{3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} - node4 := []byte{4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} - - now := time.Now() - timestamps := make([]uint64, states.NUM_STATES) - timestamps[states.PRECOMPUTING] = uint64(now.UnixNano()) - timestamps[states.REALTIME] = uint64(time.Now().Add(500 * time.Millisecond).UnixNano()) - - // Create a topology for round info - jww.FATAL.Println(node1) - ourTopology := [][]byte{node1, node2, node3} - - // Construct round info message indicating PRECOMP starting - precompRoundInfo := &pb.RoundInfo{ - ID: 0, - UpdateID: numUpdates, - State: uint32(states.PRECOMPUTING), - Topology: ourTopology, - Timestamps: timestamps, - } - - // Mocking permissioning server signing message - signRoundInfo(precompRoundInfo) - - // Increment updates id for next message - numUpdates++ - - // Construct round info message indicating STANDBY starting - standbyRoundInfo := &pb.RoundInfo{ - ID: 0, - UpdateID: numUpdates, - State: uint32(states.STANDBY), - Topology: ourTopology, - Timestamps: timestamps, - } - - // Mocking permissioning server signing message - signRoundInfo(standbyRoundInfo) - - // Increment updates id for next message - numUpdates++ - - // Construct message which adds node to team - ourTopology = append(ourTopology, node4) - - // Add new round in standby stage - newNodeRoundInfo := &pb.RoundInfo{ - ID: 0, - UpdateID: numUpdates, - State: uint32(states.STANDBY), - Topology: ourTopology, - Timestamps: timestamps, - } - - // Set the signature field of the round info - signRoundInfo(newNodeRoundInfo) - - // Increment updates id for next message - numUpdates++ - - // Construct round info message for REALTIME - realtimeRoundInfo := &pb.RoundInfo{ - ID: 0, - UpdateID: numUpdates, - State: uint32(states.REALTIME), - Topology: ourTopology, - Timestamps: timestamps, - } - - // Increment updates id for next message - numUpdates++ - - // Set the signature field of the round info - signRoundInfo(realtimeRoundInfo) - - return []*pb.RoundInfo{precompRoundInfo, standbyRoundInfo, newNodeRoundInfo, realtimeRoundInfo} -} - -func (i *mockPermissionMultipleRounds) GetCurrentClientVersion() (string, error) { - return "0.0.0", nil -} - -func (i *mockPermissionMultipleRounds) GetUpdatedNDF(clientNDFHash []byte) ([]byte, error) { - return nil, nil -} - -// --------------------------Dummy implementation of gateway server -------------------------------------- -type mockGateway struct{} - -func (*mockGateway) CheckMessages(userID *id.ID, messageID string, ipAddress string) ([]string, error) { - return nil, nil -} - -func (*mockGateway) GetMessage(userID *id.ID, msgID string, ipAddress string) (*pb.Slot, error) { - return nil, nil -} - -func (*mockGateway) PutMessage(message *pb.Slot, ipAddress string) error { - return nil -} - -func (*mockGateway) RequestNonce(message *pb.NonceRequest, ipAddress string) (*pb.Nonce, error) { - return nil, nil -} - -func (*mockGateway) ConfirmNonce(message *pb.RequestRegistrationConfirmation, ipAddress string) (*pb. - RegistrationConfirmation, error) { - return nil, nil -} - -func (*mockGateway) PollForNotifications(auth *connect.Auth) ([]*id.ID, error) { - return nil, nil -} - -func (*mockGateway) Poll(*pb.GatewayPoll) (*pb.GatewayPollResponse, error) { - return nil, nil -} - -func mockServerDef(i interface{}) *internal.Definition { - nid := internal.GenerateId(i) - - resourceMetric := measure.ResourceMetric{ - Time: time.Now(), - MemAllocBytes: 0, - NumThreads: 0, - } - resourceMonitor := measure.ResourceMonitor{} - resourceMonitor.Set(resourceMetric) - - def := internal.Definition{ - ID: nid, - ResourceMonitor: &resourceMonitor, - FullNDF: testUtil.NDF, - } - - return &def -} - // ------------------------------ Utility functions for testing purposes ---------------------------------------------- func builEmptydMockNdf() *ndf.NetworkDefinition { @@ -295,31 +109,6 @@ func builEmptydMockNdf() *ndf.NetworkDefinition { return ourMockNdf } -func buildMockNdf(nodeId *id.ID, nodeAddress, gwAddress string, cert, key []byte) { - node := ndf.Node{ - ID: nodeId.Bytes(), - TlsCertificate: string(cert), - Address: nodeAddress, - } - gw := ndf.Gateway{ - Address: gwAddress, - TlsCertificate: string(cert), - } - mockGroup := ndf.Group{ - Prime: "25", - SmallPrime: "42", - Generator: "2", - } - testNdf = &ndf.NetworkDefinition{ - Timestamp: time.Now(), - Nodes: []ndf.Node{node}, - Gateways: []ndf.Gateway{gw}, - E2E: mockGroup, - CMIX: mockGroup, - UDB: ndf.UDB{}, - } -} - // Utility function which signs an ndf message func signNdf(ourNdf *pb.NDF) error { pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) @@ -329,7 +118,10 @@ func signNdf(ourNdf *pb.NDF) error { ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - signature.Sign(ourNdf, ourPrivKey) + err = signature.Sign(ourNdf, ourPrivKey) + if err != nil { + return errors.Errorf("Could not sign ndf: %+v", err) + } return nil } @@ -343,67 +135,25 @@ func signRoundInfo(ri *pb.RoundInfo) error { ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - signature.Sign(ri, ourPrivKey) - return nil -} - -// Utility function which builds a signed full-ndf message -func setupFullNdf() (*pb.NDF, error) { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) - if err != nil { - return nil, errors.Errorf("couldn't load privKey: %+v", err) - } - - ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - - f := &mixmessages.NDF{} - tmpNdf, _, _ := ndf.DecodeNDF(testUtil.ExampleJSON) - f.Ndf, err = tmpNdf.Marshal() - if err != nil { - return nil, errors.Errorf("Failed to marshal ndf: %+v", err) - } - - if err != nil { - return nil, errors.Errorf("Could not generate serialized ndf: %s", err) - } - - err = signature.Sign(f, ourPrivKey) - - return f, nil -} - -// Utility function which builds a signed partial-ndf message -func setupPartialNdf() (*pb.NDF, error) { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) - if err != nil { - return nil, errors.Errorf("couldn't load privKey: %+v", err) - } - - ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - - f := &mixmessages.NDF{} - - stipped, err := testUtil.NDF.StripNdf().Marshal() - f.Ndf = stipped - + err = signature.Sign(ri, ourPrivKey) if err != nil { - return nil, errors.Errorf("Could not generate serialized ndf: %s", err) + return errors.Errorf("Could not sign round info: %+v", err) } - - err = signature.Sign(f, ourPrivKey) - - return f, nil + return nil } // Utility function which creates an instance -func createServerInstance(t *testing.T) (*internal.Instance, error) { - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) +func createServerInstance(t *testing.T) (instance *internal.Instance, pAddr, + nodeAddr string, nodeId *id.ID, cert, key []byte, err error) { + cert, _ = utils.ReadFile(testkeys.GetNodeCertPath()) + key, _ = utils.ReadFile(testkeys.GetNodeKeyPath()) nodeId = id.NewIdFromUInt(uint64(0), id.Node, t) - nodeAddr = fmt.Sprintf("0.0.0.0:%d", 7000+rand.Intn(1000)+cnt) - pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) - cnt++ + countLock.Lock() + nodeAddr = fmt.Sprintf("0.0.0.0:%d", 7000+count) + pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+count) + count++ + countLock.Unlock() // Build the node emptyNdf := builEmptydMockNdf() // Initialize definition @@ -419,7 +169,7 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { MetricLogPath: "", UserRegistry: nil, Permissioning: internal.Perm{ - TlsCert: []byte(testUtil.RegCert), + TlsCert: cert, Address: pAddr, }, RegistrationCode: "", @@ -438,7 +188,7 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { sm := state.NewMachine(dummyStates) ok, err := sm.Update(current.WAITING) if !ok || err != nil { - return nil, errors.Errorf("Failed to prep state machine: %+v", err) + return } // Add handler for instance @@ -447,67 +197,32 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { } // Generate instance - instance, err := internal.CreateServerInstance(def, impl, sm, + instance, err = internal.CreateServerInstance(def, impl, sm, "1.1.0") if err != nil { - return nil, errors.Errorf("Unable to create instance: %+v", err) + return } // Add permissioning as a host _, err = instance.GetNetwork().AddHost(&id.Permissioning, def.Permissioning.Address, def.Permissioning.TlsCert, false, false) if err != nil { - return nil, errors.Errorf("Failed to add permissioning host: %+v", err) + return } - - return instance, nil + err = nil + return } // Utility function which starts up a permissioning server -func startPermissioning() (*registration.Comms, *mockPermission, error) { - - cert := []byte(testUtil.RegCert) - key := []byte(testUtil.RegPrivKey) +func startPermissioning(pAddr, nAddr string, nodeId *id.ID, cert, key []byte, t *testing.T) (*registration.Comms, *mockPermission, error) { // Initialize permissioning server mp := &mockPermission{} pHandler := registration.Handler(mp) - permComms = registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) - _, err := permComms.AddHost(nodeId, pAddr, cert, false, false) + permComms := registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) + _, err := permComms.AddHost(nodeId, nAddr, cert, false, false) if err != nil { return nil, nil, errors.Errorf("Permissioning could not connect to node") } return permComms, mp, nil } - -func startGateway() (*gateway.Comms, error) { - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) - - gAddr := fmt.Sprintf("0.0.0.0:%d", 5000+rand.Intn(1000)) - gHandler := gateway.Handler(&mockGateway{}) - gwID := nodeId.DeepCopy() - gwID.SetType(id.Gateway) - gwComms = gateway.StartGateway(gwID, gAddr, gHandler, cert, key) - _, err := gwComms.AddHost(nodeId, nodeAddr, cert, false, false) - if err != nil { - return nil, err - } - - return gwComms, nil -} - -func startMultipleRoundUpdatesPermissioning() (*registration.Comms, error) { - cert := []byte(testUtil.RegCert) - key := []byte(testUtil.RegPrivKey) - // Initialize permissioning server - pHandler := registration.Handler(&mockPermissionMultipleRounds{}) - permComms = registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) - _, err := permComms.AddHost(nodeId, pAddr, cert, false, false) - if err != nil { - return nil, errors.Errorf("Permissioning could not connect to node") - } - - return permComms, nil - -} diff --git a/permissioning/mockserver_test.go b/permissioning/mockserver_test.go index a8ac09e39deb45a25a54622bef50edf708a0088c..4b876f5c10c28128bcc1acd9994078acfe69b5a0 100644 --- a/permissioning/mockserver_test.go +++ b/permissioning/mockserver_test.go @@ -12,7 +12,6 @@ import ( "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/comms/gateway" "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/node" @@ -27,27 +26,24 @@ import ( "gitlab.com/elixxir/primitives/states" "gitlab.com/elixxir/primitives/utils" "gitlab.com/elixxir/server/internal" - "gitlab.com/elixxir/server/internal/measure" "gitlab.com/elixxir/server/internal/state" "gitlab.com/elixxir/server/io" "gitlab.com/elixxir/server/services" "gitlab.com/elixxir/server/testUtil" "gitlab.com/xx_network/comms/connect" - "math/rand" + "sync" "testing" "time" ) -var nodeId *id.ID -var permComms *registration.Comms -var gwComms *gateway.Comms -var testNdf *ndf.NetworkDefinition -var pAddr string -var cnt = 0 -var nodeAddr string +var count = 0 +var countLock sync.Mutex // --------------------------------Dummy implementation of permissioning server -------------------------------- -type mockPermission struct{} +type mockPermission struct { + cert []byte + key []byte +} func (i *mockPermission) PollNdf([]byte, *connect.Auth) ([]byte, error) { return nil, nil @@ -69,8 +65,14 @@ func (i *mockPermission) Poll(*pb.PermissioningPoll, *connect.Auth, string) (*pb fullNDFMsg := &pb.NDF{Ndf: fullNdf} partialNDFMsg := &pb.NDF{Ndf: stripNdf} - signNdf(fullNDFMsg) - signNdf(partialNDFMsg) + err := signNdf(fullNDFMsg, i.key) + if err != nil { + return nil, errors.Errorf("Failed to sign full ndf: %+v", err) + } + err = signNdf(partialNDFMsg, i.key) + if err != nil { + return nil, errors.Errorf("Failed to sign partial ndf: %+v", err) + } return &pb.PermissionPollResponse{ FullNDF: fullNDFMsg, @@ -91,7 +93,10 @@ func (i *mockPermission) GetUpdatedNDF(clientNDFHash []byte) ([]byte, error) { } // --------------------------------Dummy implementation of permissioning server -------------------------------- -type mockPermissionMultipleRounds struct{} +type mockPermissionMultipleRounds struct { + cert []byte + key []byte +} func (i *mockPermissionMultipleRounds) PollNdf([]byte, *connect.Auth) ([]byte, error) { return nil, nil @@ -117,10 +122,19 @@ func (i *mockPermissionMultipleRounds) Poll(*pb.PermissioningPoll, *connect.Auth fullNDFMsg := &pb.NDF{Ndf: fullNdf} partialNDFMsg := &pb.NDF{Ndf: stripNdf} - signNdf(fullNDFMsg) - signNdf(partialNDFMsg) + err := signNdf(fullNDFMsg, i.key) + if err != nil { + return nil, errors.Errorf("Failed to sign full ndf: %+v", err) + } + err = signNdf(partialNDFMsg, i.key) + if err != nil { + return nil, errors.Errorf("Failed to sign partial ndf: %+v", err) + } - ourRoundInfoList := buildRoundInfoMessages() + ourRoundInfoList, err := buildRoundInfoMessages(i.key) + if err != nil { + return nil, errors.Errorf("Failed to build round info message: %+v", err) + } return &pb.PermissionPollResponse{ FullNDF: fullNDFMsg, @@ -129,7 +143,7 @@ func (i *mockPermissionMultipleRounds) Poll(*pb.PermissioningPoll, *connect.Auth }, nil } -func buildRoundInfoMessages() []*pb.RoundInfo { +func buildRoundInfoMessages(key []byte) ([]*pb.RoundInfo, error) { numUpdates := uint64(0) node1 := []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} @@ -156,7 +170,10 @@ func buildRoundInfoMessages() []*pb.RoundInfo { } // Mocking permissioning server signing message - signRoundInfo(precompRoundInfo) + err := signRoundInfo(precompRoundInfo, key) + if err != nil { + return nil, errors.Errorf("Failed to sign precomp round info: %+v", err) + } // Increment updates id for next message numUpdates++ @@ -171,7 +188,10 @@ func buildRoundInfoMessages() []*pb.RoundInfo { } // Mocking permissioning server signing message - signRoundInfo(standbyRoundInfo) + err = signRoundInfo(standbyRoundInfo, key) + if err != nil { + return nil, errors.Errorf("Failed to sign standby round info: %+v", err) + } // Increment updates id for next message numUpdates++ @@ -189,7 +209,10 @@ func buildRoundInfoMessages() []*pb.RoundInfo { } // Set the signature field of the round info - signRoundInfo(newNodeRoundInfo) + err = signRoundInfo(newNodeRoundInfo, key) + if err != nil { + return nil, errors.Errorf("Failed to sign new node round info: %+v", err) + } // Increment updates id for next message numUpdates++ @@ -207,9 +230,12 @@ func buildRoundInfoMessages() []*pb.RoundInfo { numUpdates++ // Set the signature field of the round info - signRoundInfo(realtimeRoundInfo) + err = signRoundInfo(realtimeRoundInfo, key) + if err != nil { + return nil, errors.Errorf("Failed to sign realtime round info: %+v", err) + } - return []*pb.RoundInfo{precompRoundInfo, standbyRoundInfo, newNodeRoundInfo, realtimeRoundInfo} + return []*pb.RoundInfo{precompRoundInfo, standbyRoundInfo, newNodeRoundInfo, realtimeRoundInfo}, nil } func (i *mockPermissionMultipleRounds) GetCurrentClientVersion() (string, error) { @@ -220,38 +246,6 @@ func (i *mockPermissionMultipleRounds) GetUpdatedNDF(clientNDFHash []byte) ([]by return nil, nil } -// --------------------------Dummy implementation of gateway server -------------------------------------- -type mockGateway struct{} - -func (*mockGateway) CheckMessages(userID *id.ID, messageID string, ipAddress string) ([]string, error) { - return nil, nil -} - -func (*mockGateway) GetMessage(userID *id.ID, msgID string, ipAddress string) (*pb.Slot, error) { - return nil, nil -} - -func (*mockGateway) PutMessage(message *pb.Slot, ipAddress string) error { - return nil -} - -func (*mockGateway) RequestNonce(message *pb.NonceRequest, ipAddress string) (*pb.Nonce, error) { - return nil, nil -} - -func (*mockGateway) ConfirmNonce(message *pb.RequestRegistrationConfirmation, ipAddress string) (*pb. - RegistrationConfirmation, error) { - return nil, nil -} - -func (*mockGateway) PollForNotifications(auth *connect.Auth) ([]*id.ID, error) { - return nil, nil -} - -func (*mockGateway) Poll(*pb.GatewayPoll) (*pb.GatewayPollResponse, error) { - return nil, nil -} - var dummyStates = [current.NUM_STATES]state.Change{ func(from current.Activity) error { return nil }, func(from current.Activity) error { return nil }, @@ -263,26 +257,6 @@ var dummyStates = [current.NUM_STATES]state.Change{ func(from current.Activity) error { return nil }, } -func mockServerDef(i interface{}) *internal.Definition { - nid := internal.GenerateId(i) - - resourceMetric := measure.ResourceMetric{ - Time: time.Now(), - MemAllocBytes: 0, - NumThreads: 0, - } - resourceMonitor := measure.ResourceMonitor{} - resourceMonitor.Set(resourceMetric) - - def := internal.Definition{ - ID: nid, - ResourceMonitor: &resourceMonitor, - FullNDF: testUtil.NDF, - } - - return &def -} - // ------------------------------ Utility functions for testing purposes ---------------------------------------------- func builEmptydMockNdf() *ndf.NetworkDefinition { @@ -297,61 +271,42 @@ func builEmptydMockNdf() *ndf.NetworkDefinition { return ourMockNdf } -func buildMockNdf(nodeId *id.ID, nodeAddress, gwAddress string, cert, key []byte) { - node := ndf.Node{ - ID: nodeId.Bytes(), - TlsCertificate: string(cert), - Address: nodeAddress, - } - gw := ndf.Gateway{ - Address: gwAddress, - TlsCertificate: string(cert), - } - mockGroup := ndf.Group{ - Prime: "25", - SmallPrime: "42", - Generator: "2", - } - testNdf = &ndf.NetworkDefinition{ - Timestamp: time.Now(), - Nodes: []ndf.Node{node}, - Gateways: []ndf.Gateway{gw}, - E2E: mockGroup, - CMIX: mockGroup, - UDB: ndf.UDB{}, - } -} - // Utility function which signs an ndf message -func signNdf(ourNdf *pb.NDF) error { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) +func signNdf(ourNdf *pb.NDF, key []byte) error { + pk, err := tls.LoadRSAPrivateKey(string(key)) if err != nil { return errors.Errorf("couldn't load privKey: %+v", err) } ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - signature.Sign(ourNdf, ourPrivKey) + err = signature.Sign(ourNdf, ourPrivKey) + if err != nil { + return errors.Errorf("Failed to sign ndf: %+v", err) + } return nil } // Utility function which signs a round info message -func signRoundInfo(ri *pb.RoundInfo) error { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) +func signRoundInfo(ri *pb.RoundInfo, key []byte) error { + pk, err := tls.LoadRSAPrivateKey(string(key)) if err != nil { return errors.Errorf("couldn't load privKey: %+v", err) } ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} - signature.Sign(ri, ourPrivKey) + err = signature.Sign(ri, ourPrivKey) + if err != nil { + return errors.Errorf("Failed to sign round info: %+v", err) + } return nil } // Utility function which builds a signed full-ndf message -func setupFullNdf() (*pb.NDF, error) { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) +func setupFullNdf(key []byte) (*pb.NDF, error) { + pk, err := tls.LoadRSAPrivateKey(string(key)) if err != nil { return nil, errors.Errorf("couldn't load privKey: %+v", err) } @@ -359,14 +314,13 @@ func setupFullNdf() (*pb.NDF, error) { ourPrivKey := &rsa.PrivateKey{PrivateKey: *pk} f := &mixmessages.NDF{} - tmpNdf, _, _ := ndf.DecodeNDF(testUtil.ExampleJSON) - f.Ndf, err = tmpNdf.Marshal() + tmpNdf, _, err := ndf.DecodeNDF(testUtil.ExampleJSON) if err != nil { - return nil, errors.Errorf("Failed to marshal ndf: %+v", err) + return nil, errors.Errorf("Failed to decode NDF: %+v", err) } - + f.Ndf, err = tmpNdf.Marshal() if err != nil { - return nil, errors.Errorf("Could not generate serialized ndf: %s", err) + return nil, errors.Errorf("Failed to marshal ndf: %+v", err) } err = signature.Sign(f, ourPrivKey) @@ -375,8 +329,8 @@ func setupFullNdf() (*pb.NDF, error) { } // Utility function which builds a signed partial-ndf message -func setupPartialNdf() (*pb.NDF, error) { - pk, err := tls.LoadRSAPrivateKey(testUtil.RegPrivKey) +func setupPartialNdf(key []byte) (*pb.NDF, error) { + pk, err := tls.LoadRSAPrivateKey(string(key)) if err != nil { return nil, errors.Errorf("couldn't load privKey: %+v", err) } @@ -398,14 +352,17 @@ func setupPartialNdf() (*pb.NDF, error) { } // Utility function which creates an instance -func createServerInstance(t *testing.T) (*internal.Instance, error) { - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) +func createServerInstance(t *testing.T) (instance *internal.Instance, pAddr, + nodeAddr string, nodeId *id.ID, cert, key []byte, err error) { + cert, _ = utils.ReadFile(testkeys.GetNodeCertPath()) + key, _ = utils.ReadFile(testkeys.GetNodeKeyPath()) nodeId = id.NewIdFromUInt(uint64(0), id.Node, t) - nodeAddr = fmt.Sprintf("0.0.0.0:%d", 7000+rand.Intn(1000)+cnt) - pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) - cnt++ + countLock.Lock() + nodeAddr = fmt.Sprintf("0.0.0.0:%d", 7200+count) + pAddr = fmt.Sprintf("0.0.0.0:%d", 2200+count) + count++ + countLock.Unlock() // Build the node emptyNdf := builEmptydMockNdf() // Initialize definition @@ -421,7 +378,7 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { MetricLogPath: "", UserRegistry: nil, Permissioning: internal.Perm{ - TlsCert: []byte(testUtil.RegCert), + TlsCert: cert, Address: pAddr, }, RegistrationCode: "", @@ -440,7 +397,7 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { sm := state.NewMachine(dummyStates) ok, err := sm.Update(current.WAITING) if !ok || err != nil { - return nil, errors.Errorf("Failed to prep state machine: %+v", err) + return } // Add handler for instance @@ -449,31 +406,32 @@ func createServerInstance(t *testing.T) (*internal.Instance, error) { } // Generate instance - instance, err := internal.CreateServerInstance(def, impl, sm, + instance, err = internal.CreateServerInstance(def, impl, sm, "1.1.0") if err != nil { - return nil, errors.Errorf("Unable to create instance: %+v", err) + return } // Add permissioning as a host _, err = instance.GetNetwork().AddHost(&id.Permissioning, def.Permissioning.Address, def.Permissioning.TlsCert, false, false) if err != nil { - return nil, errors.Errorf("Failed to add permissioning host: %+v", err) + return } - return instance, nil + err = nil + return } // Utility function which starts up a permissioning server -func startPermissioning() (*registration.Comms, error) { - - cert := []byte(testUtil.RegCert) - key := []byte(testUtil.RegPrivKey) +func startPermissioning(pAddr, nAddr string, nodeId *id.ID, cert, key []byte) (*registration.Comms, error) { // Initialize permissioning server - pHandler := registration.Handler(&mockPermission{}) - permComms = registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) - _, err := permComms.AddHost(nodeId, pAddr, cert, false, false) + pHandler := registration.Handler(&mockPermission{ + cert: cert, + key: key, + }) + permComms := registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) + _, err := permComms.AddHost(nodeId, nAddr, cert, false, false) if err != nil { return nil, errors.Errorf("Permissioning could not connect to node") } @@ -481,30 +439,14 @@ func startPermissioning() (*registration.Comms, error) { return permComms, nil } -func startGateway() (*gateway.Comms, error) { - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) - - gAddr := fmt.Sprintf("0.0.0.0:%d", 5000+rand.Intn(1000)) - gHandler := gateway.Handler(&mockGateway{}) - gwID := nodeId.DeepCopy() - gwID.SetType(id.Gateway) - gwComms = gateway.StartGateway(gwID, gAddr, gHandler, cert, key) - _, err := gwComms.AddHost(nodeId, nodeAddr, cert, false, false) - if err != nil { - return nil, err - } - - return gwComms, nil -} - -func startMultipleRoundUpdatesPermissioning() (*registration.Comms, error) { - cert := []byte(testUtil.RegCert) - key := []byte(testUtil.RegPrivKey) +func startMultipleRoundUpdatesPermissioning(pAddr, nAddr string, nodeId *id.ID, cert, key []byte) (*registration.Comms, error) { // Initialize permissioning server - pHandler := registration.Handler(&mockPermissionMultipleRounds{}) - permComms = registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) - _, err := permComms.AddHost(nodeId, pAddr, cert, false, false) + pHandler := registration.Handler(&mockPermissionMultipleRounds{ + cert: cert, + key: key, + }) + permComms := registration.StartRegistrationServer(&id.Permissioning, pAddr, pHandler, cert, key) + _, err := permComms.AddHost(nodeId, nAddr, cert, false, false) if err != nil { return nil, errors.Errorf("Permissioning could not connect to node") } diff --git a/permissioning/permissioning_test.go b/permissioning/permissioning_test.go index 9d1a5470505a345b80c20de335d8cd61d7fc318d..b3cd7fb664a8ca07b446329d0b5523f74fc64aec 100644 --- a/permissioning/permissioning_test.go +++ b/permissioning/permissioning_test.go @@ -35,17 +35,25 @@ import ( //// Full-stack happy path test for the node registration logic func TestRegisterNode(t *testing.T) { - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) + cert, err := utils.ReadFile(testkeys.GetNodeCertPath()) + if err != nil { + t.Errorf("Failed to read cert file: %+v", err) + } + key, err := utils.ReadFile(testkeys.GetNodeKeyPath()) + if err != nil { + t.Errorf("Failed to read key file: %+v", err) + } // Set up id's and address - nodeId = id.NewIdFromUInt(0, id.Node, t) - nodeAddr := fmt.Sprintf("0.0.0.0:%d", 17000+rand.Intn(1000)+cnt) - pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) + nodeId := id.NewIdFromUInt(0, id.Node, t) - cnt++ + countLock.Lock() + nodeAddr := fmt.Sprintf("0.0.0.0:%d", 7100+count) + pAddr := fmt.Sprintf("0.0.0.0:%d", 2100+count) + gAddr := fmt.Sprintf("0.0.0.0:%d", 4100+count) + count++ + countLock.Unlock() - gAddr := fmt.Sprintf("0.0.0.0:%d", 4000+rand.Intn(1000)+cnt) gwID := nodeId.DeepCopy() gwID.SetType(id.Gateway) @@ -70,7 +78,7 @@ func TestRegisterNode(t *testing.T) { UserRegistry: nil, Permissioning: internal.Perm{ - TlsCert: []byte(testUtil.RegCert), + TlsCert: cert, Address: pAddr, }, RegistrationCode: "", @@ -103,6 +111,13 @@ func TestRegisterNode(t *testing.T) { // Upsert test data for gateway instance.UpsertGatewayData("0.0.0.0:5289", "1.4") + // Start up permissioning server + permComms, err := startPermissioning(pAddr, nodeAddr, nodeId, cert, key) + if err != nil { + t.Errorf("Couldn't create permissioning server: %+v", err) + } + defer permComms.Shutdown() + // Add permissioning as a host _, err = instance.GetNetwork().AddHost(&id.Permissioning, def.Permissioning.Address, def.Permissioning.TlsCert, false, false) @@ -110,13 +125,6 @@ func TestRegisterNode(t *testing.T) { t.Errorf("Failed to add permissioning host: %+v", err) } - // Start up permissioning server - permComms, err := startPermissioning() - if err != nil { - t.Errorf("Couldn't create permissioning server: %+v", err) - } - defer permComms.Shutdown() - // Fetch permissioning host permHost, ok := instance.GetNetwork().GetHost(&id.Permissioning) if !ok { @@ -134,13 +142,13 @@ func TestRegisterNode(t *testing.T) { // Happy path: Test polling func TestPoll(t *testing.T) { // Create instance - instance, err := createServerInstance(t) + instance, pAddr, nAddr, nodeId, cert, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } // Start up permissioning server - permComms, err := startPermissioning() + permComms, err := startPermissioning(pAddr, nAddr, nodeId, cert, key) if err != nil { t.Errorf("Couldn't create permissioning server: %+v", err) } @@ -191,7 +199,7 @@ func TestPoll(t *testing.T) { func TestPoll_ErrState(t *testing.T) { // Create instance - instance, err := createServerInstance(t) + instance, pAddr, nAddr, nodeId, cert, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } @@ -206,7 +214,7 @@ func TestPoll_ErrState(t *testing.T) { } // Start up permissioning server - permComms, err := startPermissioning() + permComms, err := startPermissioning(pAddr, nAddr, nodeId, cert, key) if err != nil { t.Errorf("Couldn't create permissioning server: %+v", err) } @@ -236,16 +244,17 @@ func TestPoll_ErrState(t *testing.T) { // Happy path: Pings the mock registration server for a poll response func TestRetrieveState(t *testing.T) { // Create server instance - instance, err := createServerInstance(t) + instance, pAddr, nAddr, nodeId, cert, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } defer instance.GetNetwork().Shutdown() // Create permissioning server - permComms, err := startPermissioning() + permComms, err := startPermissioning(pAddr, nAddr, nodeId, cert, key) if err != nil { t.Errorf("Couldn't create permissioning server") + t.FailNow() } defer permComms.Shutdown() @@ -286,7 +295,7 @@ func TestUpdateInternalState(t *testing.T) { numUpdates := uint64(0) // Create server instance - instance, err := createServerInstance(t) + instance, _, _, _, _, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } @@ -316,11 +325,20 @@ func TestUpdateInternalState(t *testing.T) { numUpdates++ // Set the signature field of the round info - signRoundInfo(precompRoundInfo) + err = signRoundInfo(precompRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign precomp round info: %+v", err) + } // Set up the ndf's - fullNdf, _ := setupFullNdf() - stripNdf, _ := setupPartialNdf() + fullNdf, err := setupFullNdf(key) + if err != nil { + t.Errorf("Failed to setup full ndf: %+v", err) + } + stripNdf, err := setupPartialNdf(key) + if err != nil { + t.Errorf("Failed to setup partial ndf: %+v", err) + } // ------------------- TRANSFER FROM WAITING TO PRECOMP --------------------------------------- @@ -396,7 +414,10 @@ func TestUpdateInternalState(t *testing.T) { numUpdates++ // Set the signature field of the round info - signRoundInfo(realtimeRoundInfo) + err = signRoundInfo(realtimeRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign realtime round info: %+v", err) + } // Construct permissioning poll response mockPollResponse = &pb.PermissionPollResponse{ @@ -437,7 +458,7 @@ func TestUpdateInternalState_Smoke(t *testing.T) { numUpdates := uint64(0) // Create server instance - instance, err := createServerInstance(t) + instance, _, _, _, _, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } @@ -464,11 +485,14 @@ func TestUpdateInternalState_Smoke(t *testing.T) { numUpdates++ // Set the signature field of the round info - signRoundInfo(pendingRoundInfo) + err = signRoundInfo(pendingRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign pending round info: %+v", err) + } // Set up the ndf's - fullNdf, _ := setupFullNdf() - stripNdf, _ := setupPartialNdf() + fullNdf, _ := setupFullNdf(key) + stripNdf, _ := setupPartialNdf(key) // Construct permissioning poll response mockPollResponse := &pb.PermissionPollResponse{ @@ -496,7 +520,10 @@ func TestUpdateInternalState_Smoke(t *testing.T) { numUpdates++ // Set the signature field of the round info - signRoundInfo(standbyRoundInfo) + err = signRoundInfo(standbyRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign standby round info: %+v", err) + } // Construct permissioning poll response mockPollResponse = &pb.PermissionPollResponse{ @@ -524,7 +551,10 @@ func TestUpdateInternalState_Smoke(t *testing.T) { numUpdates++ // Set the signature field of the round info - signRoundInfo(completedRoundInfo) + err = signRoundInfo(completedRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign completed round info: %+v", err) + } // Construct permissioning poll response mockPollResponse = &pb.PermissionPollResponse{ @@ -544,7 +574,7 @@ func TestUpdateInternalState_Smoke(t *testing.T) { // Attempt to update round in which our node is not a team-member func TestUpdateInternalState_Error(t *testing.T) { // Create server instance - instance, err := createServerInstance(t) + instance, _, _, _, _, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } @@ -574,11 +604,20 @@ func TestUpdateInternalState_Error(t *testing.T) { } // Set the signature field of the round info - signRoundInfo(NumStateRoundInfo) + err = signRoundInfo(NumStateRoundInfo, key) + if err != nil { + t.Errorf("Failed to sign NumState round info: %+v", err) + } // Set up the ndf's - fullNdf, _ := setupFullNdf() - stripNdf, _ := setupPartialNdf() + fullNdf, err := setupFullNdf(key) + if err != nil { + t.Errorf("Failed to setup full ndf: %+v", err) + } + stripNdf, err := setupPartialNdf(key) + if err != nil { + t.Errorf("Failed to setup partial ndf: %+v", err) + } // Construct permissioning poll response mockPollResponse := &pb.PermissionPollResponse{ @@ -602,15 +641,23 @@ func TestRegistration(t *testing.T) { permDone := make(chan struct{}) // Pull certs and key - cert, _ := utils.ReadFile(testkeys.GetNodeCertPath()) - key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) + cert, err := utils.ReadFile(testkeys.GetNodeCertPath()) + if err != nil { + t.Errorf("Failed to load cert: +%v", err) + } + key, err := utils.ReadFile(testkeys.GetNodeKeyPath()) + if err != nil { + t.Errorf("Failed to load key: +%v", err) + } // Generate id's and addresses - nodeId = id.NewIdFromUInt(0, id.Node, t) - nodeAddr := fmt.Sprintf("0.0.0.0:%d", 7000+rand.Intn(1000)+cnt) - pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) - cnt++ - gAddr := fmt.Sprintf("0.0.0.0:%d", 4000+rand.Intn(1000)+cnt) + nodeId := id.NewIdFromUInt(0, id.Node, t) + countLock.Lock() + nodeAddr := fmt.Sprintf("0.0.0.0:%d", 7400+count) + pAddr := fmt.Sprintf("0.0.0.0:%d", 2400+count) + gAddr := fmt.Sprintf("0.0.0.0:%d", 4400+count) + count++ + countLock.Unlock() gwID := nodeId.DeepCopy() gwID.SetType(id.Gateway) @@ -635,7 +682,7 @@ func TestRegistration(t *testing.T) { }, UserRegistry: nil, Permissioning: internal.Perm{ - TlsCert: []byte(testUtil.RegCert), + TlsCert: cert, Address: pAddr, }, RegistrationCode: "", @@ -672,7 +719,7 @@ func TestRegistration(t *testing.T) { } // Boot up permissioning server - permComms, err := startPermissioning() + permComms, err := startPermissioning(pAddr, nodeAddr, nodeId, cert, key) if err != nil { t.Errorf("Couldn't create permissioning server: %+v", err) } @@ -752,13 +799,13 @@ func TestRegistration(t *testing.T) { func TestPoll_MultipleRoundupdates(t *testing.T) { // Create instance - instance, err := createServerInstance(t) + instance, pAddr, nAddr, nodeId, cert, key, err := createServerInstance(t) if err != nil { t.Errorf("Couldn't create instance: %+v", err) } // Start up permissioning server which will return multiple round updates - permComms, err := startMultipleRoundUpdatesPermissioning() + permComms, err := startMultipleRoundUpdatesPermissioning(pAddr, nAddr, nodeId, cert, key) if err != nil { t.Errorf("Couldn't create permissioning server: %+v", err) } @@ -780,12 +827,24 @@ func TestPoll_MultipleRoundupdates(t *testing.T) { // requested to wait until is after the current time. func TestQueueUntilRealtime(t *testing.T) { // Test that it happens after ~100ms - instance, _ := createServerInstance(t) + instance, _, _, _, _, _, _ := createServerInstance(t) now := time.Now() after := now.Add(100 * time.Millisecond) before := now.Add(-100 * time.Millisecond) - instance.GetStateMachine().Update(current.PRECOMPUTING) - instance.GetStateMachine().Update(current.STANDBY) + ok, err := instance.GetStateMachine().Update(current.PRECOMPUTING) + if err != nil { + t.Errorf("Failed to update to precomputing: %+v", err) + } + if !ok { + t.Errorf("Did not transition to precomputing") + } + ok, err = instance.GetStateMachine().Update(current.STANDBY) + if err != nil { + t.Errorf("Failed to update to standby: %+v", err) + } + if !ok { + t.Errorf("Did not transition to standby") + } go queueUntilRealtime(instance, after) if instance.GetStateMachine().Get() == current.REALTIME { t.Errorf("State transitioned too quickly!\n") @@ -796,9 +855,21 @@ func TestQueueUntilRealtime(t *testing.T) { } // Test the case where time.Now() is after the start time - instance, _ = createServerInstance(t) - instance.GetStateMachine().Update(current.PRECOMPUTING) - instance.GetStateMachine().Update(current.STANDBY) + instance, _, _, _, _, _, _ = createServerInstance(t) + ok, err = instance.GetStateMachine().Update(current.PRECOMPUTING) + if err != nil { + t.Errorf("Failed to update to precomputing: %+v", err) + } + if !ok { + t.Errorf("Did not transition to precomputing") + } + ok, err = instance.GetStateMachine().Update(current.STANDBY) + if err != nil { + t.Errorf("Failed to update to standby: %+v", err) + } + if !ok { + t.Errorf("Did not transition to standby") + } go queueUntilRealtime(instance, before) time.Sleep(50 * time.Millisecond) if instance.GetStateMachine().Get() != current.REALTIME { @@ -812,13 +883,10 @@ func TestUpdateRounds_Failed(t *testing.T) { key, _ := utils.ReadFile(testkeys.GetNodeKeyPath()) // Set up id's and address - nodeId = id.NewIdFromUInt(0, id.Node, t) - nodeAddr := fmt.Sprintf("0.0.0.0:%d", 17000+rand.Intn(1000)+cnt) - pAddr = fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) - - cnt++ - - gAddr := fmt.Sprintf("0.0.0.0:%d", 4000+rand.Intn(1000)+cnt) + nodeId := id.NewIdFromUInt(0, id.Node, t) + nodeAddr := fmt.Sprintf("0.0.0.0:%d", 17000+rand.Intn(1000)) + pAddr := fmt.Sprintf("0.0.0.0:%d", 2000+rand.Intn(1000)) + gAddr := fmt.Sprintf("0.0.0.0:%d", 4000+rand.Intn(1000)) gwID := nodeId.DeepCopy() gwID.SetType(id.Gateway)