test: added a (still broken) test for key conflicts

pull/2873/head
Audric Ackermann 2 years ago
parent e24ec9e1a8
commit 6b3adff972

@ -119,9 +119,7 @@ async function buildAndSaveDumpsToDB(
async function pushChangesToGroupSwarmIfNeeded(groupPk: GroupPubkeyType): Promise<RunJobResult> {
// 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)) {

@ -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

@ -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'
);
});
});
});

Loading…
Cancel
Save