Skip to content

Commit

Permalink
fix(group): make getGroupsPublicEncryptionKeys returns unique Keys
Browse files Browse the repository at this point in the history
requesting keys for the same group multiple times in one call
now returns only unique keys instead of X times the same key
  • Loading branch information
JMounier authored and quentinvernot committed Jul 29, 2022
1 parent b9a9dbf commit 1aadf5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/Groups/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export default class GroupManager {
}

async getGroupsPublicEncryptionKeys(groupIds: Array<b64string>): Promise<Array<Uint8Array>> {
const result = await this._publicEncryptionKeyLookupCoalescer.run(this._getGroupsPublicEncryptionKeys, groupIds);
const uniqueGroupIds = [...new Set(groupIds)];
const result = await this._publicEncryptionKeyLookupCoalescer.run(this._getGroupsPublicEncryptionKeys, uniqueGroupIds);

return result.map(record => record.key);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/functional-tests/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export const generateEncryptionTests = (args: TestArgs) => {
await expectDecrypt([aliceLaptop, bobLaptop], clearText, encrypted);
});

it('dedupes identities when encrypting/sharing with the same permanent identity twice', async () => {
const encrypted = await bobLaptop.encrypt(clearText, { shareWithUsers: [alicePublicIdentity, alicePublicIdentity] });
await expectDecrypt([aliceLaptop], clearText, encrypted);
});

it('encrypts and shares with a permanent identity and not self', async () => {
const encrypted = await bobLaptop.encrypt(clearText, { shareWithUsers: [alicePublicIdentity], shareWithSelf: false });
await expect(bobLaptop.decrypt(encrypted)).to.be.rejectedWith(errors.InvalidArgument);
Expand Down
9 changes: 9 additions & 0 deletions packages/functional-tests/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@ export const generateGroupsTests = (args: TestArgs) => {
});

describe('encrypt/share', () => {
it('dedupes groupIds when encrypting/sharing with the same group twice', async () => {
const alice = await UserSession.create(appHelper);
const bob = await UserSession.create(appHelper);
const groupId = await alice.session.createGroup([bob.spublicIdentity]);
const encrypted = await encrypt(alice.session, { shareWithGroups: [groupId, groupId] });

await checkDecrypt([bob], [encrypted]);
});

it('encrypt for two groups', async () => {
const alice = await UserSession.create(appHelper);
const bob = await UserSession.create(appHelper);
Expand Down

0 comments on commit 1aadf5d

Please sign in to comment.