diff --git a/ts/session/utils/job_runners/jobs/GroupConfigJob.ts b/ts/session/utils/job_runners/jobs/GroupConfigJob.ts index a518fabec..3302cb77e 100644 --- a/ts/session/utils/job_runners/jobs/GroupConfigJob.ts +++ b/ts/session/utils/job_runners/jobs/GroupConfigJob.ts @@ -119,9 +119,7 @@ async function buildAndSaveDumpsToDB( async function pushChangesToGroupSwarmIfNeeded(groupPk: GroupPubkeyType): Promise { // save the dumps to DB even before trying to push them, so at least we have an up to date dumps in the DB in case of crash, no network etc await LibSessionUtil.saveMetaGroupDumpToDb(groupPk); - const singleDestChanges = await LibSessionUtil.pendingChangesForGroup(groupPk); - // If there are no pending changes then the job can just complete (next time something // is updated we want to try and run immediately so don't scuedule another run in this case) if (isEmpty(singleDestChanges?.messages)) { diff --git a/ts/session/utils/libsession/libsession_utils.ts b/ts/session/utils/libsession/libsession_utils.ts index 9c4b7406f..69a79a5d4 100644 --- a/ts/session/utils/libsession/libsession_utils.ts +++ b/ts/session/utils/libsession/libsession_utils.ts @@ -202,7 +202,6 @@ async function pendingChangesForGroup( if (!needsPush) { return { messages: results, allOldHashes: new Set() }; } - const { groupInfo, groupMember, groupKeys } = await MetaGroupWrapperActions.push(groupPk); // Note: We need the keys to be pushed first to avoid a race condition diff --git a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts index 7f98ae7b9..4785bfeb4 100644 --- a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts +++ b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts @@ -75,7 +75,7 @@ describe('libsession_metagroup', () => { const toEncrypt = new Uint8Array(plaintext); const encrypted = metaGroupWrapper.encryptMessage(toEncrypt); - encrypted[1] = 67; + encrypted[1] -= 1; const func = () => metaGroupWrapper.decryptMessage(encrypted); expect(func).to.throw('unable to decrypt ciphertext with any current group keys'); }); @@ -250,4 +250,43 @@ describe('libsession_metagroup', () => { expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq(expected); }); }); + + describe('keys', () => { + it('fresh group does not need rekey', () => { + expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq( + false, + 'rekey should be false on fresh group' + ); + }); + + it('merging a key conflict marks needsRekey to true', () => { + const metaGroupWrapper2 = new MetaGroupWrapperNode({ + groupEd25519Pubkey: toFixedUint8ArrayOfLength( + HexString.fromHexString(groupCreated.pubkeyHex.slice(2)), + 32 + ), + groupEd25519Secretkey: groupCreated.secretKey, + metaDumped: null, + userEd25519Secretkey: toFixedUint8ArrayOfLength(us.ed25519KeyPair.privateKey, 64), + }); + metaGroupWrapper.memberSetPromoted(TestUtils.generateFakePubKeyStr(), false); + metaGroupWrapper2.memberSetPromoted(TestUtils.generateFakePubKeyStr(), false); + expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq( + false, + 'rekey should be false on fresh group' + ); + expect(metaGroupWrapper2.keysNeedsRekey()).to.be.eq( + false, + 'rekey should be false on fresh group2' + ); + const wrapper2Rekeyed = metaGroupWrapper2.keyRekey(); + + const loadedKey = metaGroupWrapper.loadKeyMessage('fakehash1', wrapper2Rekeyed, Date.now()); + expect(loadedKey).to.be.eq(true, 'key should have been loaded'); + expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq( + true, + 'rekey should be true for after add' + ); + }); + }); });