Skip to content
Snippets Groups Projects
Commit b192d685 authored by Jonah Husson's avatar Jonah Husson
Browse files

finish tests for instance and securedndf

parent 7cac3a84
Branches
Tags
No related merge requests found
package network package network
import ( import (
"gitlab.com/elixxir/comms/connect"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
ds "gitlab.com/elixxir/comms/network/dataStructures" ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/comms/testkeys"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"testing" "testing"
) )
...@@ -63,14 +68,82 @@ func TestInstance_GetRoundUpdates(t *testing.T) { ...@@ -63,14 +68,82 @@ func TestInstance_GetRoundUpdates(t *testing.T) {
} }
} }
func setupComm(t *testing.T) (*Instance, *mixmessages.NDF) {
priv := testkeys.LoadFromPath(testkeys.GetNodeKeyPath())
privKey, err := rsa.LoadPrivateKeyFromPem(priv)
pub := testkeys.LoadFromPath(testkeys.GetNodeCertPath())
if err != nil {
t.Errorf("Could not generate rsa key: %s", err)
}
f := &mixmessages.NDF{}
baseNDF := ndf.NetworkDefinition{}
f.Ndf, err = baseNDF.Marshal()
if err != nil {
t.Errorf("Could not generate serialized ndf: %s", err)
}
err = signature.Sign(f, privKey)
pc := &connect.ProtoComms{}
i := NewInstance(pc)
_, err = i.comm.AddHost(id.PERMISSIONING, "0.0.0.0:4200", pub, false, true)
if err != nil {
t.Errorf("Failed to add permissioning host: %+v", err)
}
return i, f
}
func TestInstance_RoundUpdate(t *testing.T) { func TestInstance_RoundUpdate(t *testing.T) {
msg := &mixmessages.RoundInfo{
ID: 2,
UpdateID: 4,
State: 6,
BatchSize: 8,
}
priv := testkeys.LoadFromPath(testkeys.GetNodeKeyPath())
privKey, err := rsa.LoadPrivateKeyFromPem(priv)
err = signature.Sign(msg, privKey)
i := NewInstance(&connect.ProtoComms{})
pub := testkeys.LoadFromPath(testkeys.GetGatewayCertPath())
err = i.RoundUpdate(msg)
if err == nil {
t.Error("Should have failed to get perm host")
} }
func TestInstance_UpdateFullNdf(t *testing.T) { _, err = i.comm.AddHost(id.PERMISSIONING, "0.0.0.0:4200", pub, false, true)
if err != nil {
t.Errorf("failed to add bad host: %+v", err)
}
err = i.RoundUpdate(msg)
if err == nil {
t.Error("Should have failed to verify")
}
i, _ = setupComm(t)
err = i.RoundUpdate(msg)
if err != nil {
t.Errorf("Failed to update ndf: %+v", err)
}
} }
func TestInstance_UpdatePartialNdf(t *testing.T) { func TestInstance_UpdateFullNdf(t *testing.T) {
i, f := setupComm(t)
err := i.UpdateFullNdf(f)
if err != nil {
t.Errorf("Failed to update ndf: %+v", err)
}
}
func TestInstance_UpdatePartialNdf(t *testing.T) {
i, f := setupComm(t)
err := i.UpdatePartialNdf(f)
if err != nil {
t.Errorf("Failed to update ndf: %+v", err)
}
} }
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment