From 6b2925b2329cd753d7ead131a1ac11dc76806e28 Mon Sep 17 00:00:00 2001 From: jbhusson <jonah@elixxir.io> Date: Wed, 9 Mar 2022 12:05:12 -0500 Subject: [PATCH] Remove unnecessary load, add bad json test --- backup/backup.go | 3 +-- backup/backup_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/backup/backup.go b/backup/backup.go index 68515d18e..b8b72f256 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -215,8 +215,7 @@ func (b *Backup) AddJson(newJson string) { b.mux.Lock() defer b.mux.Unlock() - currentJson := loadJson(b.store.GetKV()) - if newJson != currentJson { + if newJson != b.jsonParams { b.jsonParams = newJson if err := storeJson(newJson, b.store.GetKV()); err != nil { jww.FATAL.Panicf("Failed to store json: %+v", err) diff --git a/backup/backup_test.go b/backup/backup_test.go index a9dade343..4b6d964b1 100644 --- a/backup/backup_test.go +++ b/backup/backup_test.go @@ -320,6 +320,44 @@ func TestBackup_AddJson(t *testing.T) { } } +func TestBackup_AddJson_badJson(t *testing.T) { + b := newTestBackup("MySuperSecurePassword", nil, t) + s := b.store + json := "abc{'i'm a bad json: 'one': 1'''}}" + + expectedCollatedBackup := backup.Backup{ + RegistrationTimestamp: s.GetUser().RegistrationTimestamp, + TransmissionIdentity: backup.TransmissionIdentity{ + RSASigningPrivateKey: s.GetUser().TransmissionRSA, + RegistrarSignature: s.User().GetTransmissionRegistrationValidationSignature(), + Salt: s.GetUser().TransmissionSalt, + ComputedID: s.GetUser().TransmissionID, + }, + ReceptionIdentity: backup.ReceptionIdentity{ + RSASigningPrivateKey: s.GetUser().ReceptionRSA, + RegistrarSignature: s.User().GetReceptionRegistrationValidationSignature(), + Salt: s.GetUser().ReceptionSalt, + ComputedID: s.GetUser().ReceptionID, + DHPrivateKey: s.GetUser().E2eDhPrivateKey, + DHPublicKey: s.GetUser().E2eDhPublicKey, + }, + UserDiscoveryRegistration: backup.UserDiscoveryRegistration{ + FactList: s.GetUd().GetFacts(), + }, + Contacts: backup.Contacts{Identities: s.E2e().GetPartners()}, + JSONParams: json, + } + + b.AddJson(json) + + collatedBackup := b.assembleBackup() + if !reflect.DeepEqual(expectedCollatedBackup, collatedBackup) { + t.Errorf("Collated backup does not match expected."+ + "\nexpected: %+v\nreceived: %+v", + expectedCollatedBackup, collatedBackup) + } +} + // Tests that Backup.assembleBackup returns the backup.Backup with the expected // results. func TestBackup_assembleBackup(t *testing.T) { -- GitLab