Skip to content

Commit

Permalink
fix(encrypt): fix 'shareWithUsers' argument alteration
Browse files Browse the repository at this point in the history
  • Loading branch information
JMounier committed Dec 9, 2022
1 parent c16bf65 commit 981be6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/DataProtection/DataProtector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ export class DataProtector {
}

async _getTransparentSession(encryptionOptions: Omit<EncryptionOptions, 'paddingStep'>): Promise<SessionResult> {
const shareWithUsers = encryptionOptions.shareWithUsers || [];
const shareWithGroups = encryptionOptions.shareWithGroups || [];
const shareWithUsers = [
...encryptionOptions.shareWithUsers || [],
];
const shareWithGroups = [
...encryptionOptions.shareWithGroups || [],
];

if (encryptionOptions.shareWithSelf) {
const selfIdentity = _serializeIdentity(this._handleShareWithSelf([], encryptionOptions.shareWithSelf)[0]!);
Expand Down
9 changes: 9 additions & 0 deletions packages/functional-tests/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ export const generateEncryptionTests = (args: TestArgs) => {
});

describe('share at encryption time', () => {
it('does not alter sharing options', async () => {
const options = {
shareWithUsers: [alicePublicIdentity],
};
await expect(bobLaptop.encrypt(clearText, options)).to.be.fulfilled;

expect(options.shareWithUsers.length).to.equal(1);
});

it('encrypts and shares with a permanent identity', async () => {
const encrypted = await bobLaptop.encrypt(clearText, { shareWithUsers: [alicePublicIdentity] });
await expectDecrypt([aliceLaptop], clearText, encrypted);
Expand Down

0 comments on commit 981be6f

Please sign in to comment.