diff --git a/backup/backup.go b/backup/backup.go index b8b72f2563844980c21d8d0ebb9309b85c996221..71ea5a210b8915be03f1f78458384caa2b4d8ac6 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -303,7 +303,7 @@ func (b *Backup) assembleBackup() backup.Backup { // Get contacts bu.Contacts.Identities = b.store.E2e().GetPartners() - //add the memoized json params + // Add the memoized JSON params bu.JSONParams = b.jsonParams return bu diff --git a/backup/backup_test.go b/backup/backup_test.go index 1dc785aa311e0916f06f71618975dc9afadb1c25..d762c2428c4aa51da10e5da4eec807cf50d078b7 100644 --- a/backup/backup_test.go +++ b/backup/backup_test.go @@ -9,7 +9,13 @@ package backup import ( "bytes" + "github.com/cloudflare/circl/dh/sidh" + "gitlab.com/elixxir/client/interfaces/params" + util "gitlab.com/elixxir/client/storage/utility" + "gitlab.com/elixxir/crypto/diffieHellman" + "gitlab.com/xx_network/primitives/id" "reflect" + "sort" "strings" "testing" "time" @@ -376,6 +382,22 @@ func TestBackup_assembleBackup(t *testing.T) { b := newTestBackup("MySuperSecurePassword", nil, t) s := b.store + rng := csprng.NewSystemRNG() + for i := 0; i < 10; i++ { + recipient, _ := id.NewRandomID(rng, id.User) + dhKey := s.E2e().GetGroup().NewInt(int64(i + 10)) + pubKey := diffieHellman.GeneratePublicKey(dhKey, s.E2e().GetGroup()) + _, mySidhPriv := util.GenerateSIDHKeyPair(sidh.KeyVariantSidhA, rng) + theirSidhPub, _ := util.GenerateSIDHKeyPair(sidh.KeyVariantSidhB, rng) + p := params.GetDefaultE2ESessionParams() + + err := s.E2e().AddPartner( + recipient, pubKey, dhKey, mySidhPriv, theirSidhPub, p, p) + if err != nil { + t.Errorf("Failed to add partner %s: %+v", recipient, err) + } + } + expectedCollatedBackup := backup.Backup{ RegistrationTimestamp: s.GetUser().RegistrationTimestamp, TransmissionIdentity: backup.TransmissionIdentity{ @@ -400,6 +422,16 @@ func TestBackup_assembleBackup(t *testing.T) { collatedBackup := b.assembleBackup() + sort.Slice(expectedCollatedBackup.Contacts.Identities, func(i, j int) bool { + return bytes.Compare(expectedCollatedBackup.Contacts.Identities[i].Bytes(), + expectedCollatedBackup.Contacts.Identities[j].Bytes()) == -1 + }) + + sort.Slice(collatedBackup.Contacts.Identities, func(i, j int) bool { + return bytes.Compare(collatedBackup.Contacts.Identities[i].Bytes(), + collatedBackup.Contacts.Identities[j].Bytes()) == -1 + }) + if !reflect.DeepEqual(expectedCollatedBackup, collatedBackup) { t.Errorf("Collated backup does not match expected."+ "\nexpected: %+v\nreceived: %+v", diff --git a/storage/e2e/store.go b/storage/e2e/store.go index 1aea1efe8ddff38327d44fbfc84a07a1f32db458..931fb28449809fc398c70abfab12ef0090c3e92c 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -255,7 +255,8 @@ func (s *Store) GetPartners() []*id.ID { partnerIds := make([]*id.ID, 0, len(s.managers)) for partnerId := range s.managers { - partnerIds = append(partnerIds, &partnerId) + pid := partnerId + partnerIds = append(partnerIds, &pid) } return partnerIds