Skip to content
Snippets Groups Projects
Commit c34b1137 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-2545/mapImplSalt' into 'XX-2502/Salt'

XX-2545 UpdateSalt() for MapImpl

See merge request elixxir/registration!212
parents 2ae6e285 84e6725d
Branches XX-2502/Salt
No related tags found
No related merge requests found
......@@ -101,7 +101,14 @@ func (m *MapImpl) InsertRoundMetric(metric *RoundMetric, topology [][]byte) erro
// Update the Salt for a given Node ID
func (m *MapImpl) UpdateSalt(id *id.ID, salt []byte) error {
// TODO
n, err := m.GetNodeById(id)
if err != nil {
return err
}
m.mut.Lock()
defer m.mut.Unlock()
n.Salt = salt
return nil
}
......
......@@ -7,6 +7,8 @@
package storage
import (
"bytes"
"crypto/rand"
"gitlab.com/elixxir/registration/storage/node"
"gitlab.com/xx_network/primitives/id"
"testing"
......@@ -232,6 +234,49 @@ func TestMapImpl_InsertApplication_Duplicate(t *testing.T) {
}
}
// Happy path
func TestMapImpl_UpdateSalt(t *testing.T) {
testID := id.NewIdFromString("test", id.Node, t)
key := "testKey"
newSalt := make([]byte, 8)
_, _ = rand.Read(newSalt)
m := &MapImpl{
nodes: map[string]*Node{key: {Id: testID.Bytes(), Salt: []byte("b")}},
}
err := m.UpdateSalt(testID, newSalt)
if err != nil {
t.Errorf("Received unexpected error when upadting salt."+
"\n\terror: %v", err)
}
// Verify that the new salt matches the passed in salt
if !bytes.Equal(newSalt, m.nodes[key].Salt) {
t.Errorf("Node in map has unexpected salt."+
"\n\texpected: %d\n\treceived: %d", newSalt, m.nodes[key].Salt)
}
}
// Tests that MapImpl.UpdateSalt returns an error if no Node is found in the map
// for the given ID.
func TestMapImpl_UpdateSalt_NodeNotInMap(t *testing.T) {
testID := id.NewIdFromString("test", id.Node, t)
key := "testKey"
newSalt := make([]byte, 8)
_, _ = rand.Read(newSalt)
m := &MapImpl{
nodes: map[string]*Node{key: {Id: id.NewIdFromString("test3", id.Node, t).Bytes(), Salt: []byte("b")}},
}
err := m.UpdateSalt(testID, newSalt)
if err == nil {
t.Errorf("Did not receive an error when the Node does not exist in " +
"the map.")
}
}
// Happy path
func TestMapImpl_RegisterNode(t *testing.T) {
m := &MapImpl{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment