Skip to content

Commit 981be6f

Browse files
committed
fix(encrypt): fix 'shareWithUsers' argument alteration
1 parent c16bf65 commit 981be6f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/core/src/DataProtection/DataProtector.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,12 @@ export class DataProtector {
218218
}
219219

220220
async _getTransparentSession(encryptionOptions: Omit<EncryptionOptions, 'paddingStep'>): Promise<SessionResult> {
221-
const shareWithUsers = encryptionOptions.shareWithUsers || [];
222-
const shareWithGroups = encryptionOptions.shareWithGroups || [];
221+
const shareWithUsers = [
222+
...encryptionOptions.shareWithUsers || [],
223+
];
224+
const shareWithGroups = [
225+
...encryptionOptions.shareWithGroups || [],
226+
];
223227

224228
if (encryptionOptions.shareWithSelf) {
225229
const selfIdentity = _serializeIdentity(this._handleShareWithSelf([], encryptionOptions.shareWithSelf)[0]!);

packages/functional-tests/src/encryption.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ export const generateEncryptionTests = (args: TestArgs) => {
197197
});
198198

199199
describe('share at encryption time', () => {
200+
it('does not alter sharing options', async () => {
201+
const options = {
202+
shareWithUsers: [alicePublicIdentity],
203+
};
204+
await expect(bobLaptop.encrypt(clearText, options)).to.be.fulfilled;
205+
206+
expect(options.shareWithUsers.length).to.equal(1);
207+
});
208+
200209
it('encrypts and shares with a permanent identity', async () => {
201210
const encrypted = await bobLaptop.encrypt(clearText, { shareWithUsers: [alicePublicIdentity] });
202211
await expectDecrypt([aliceLaptop], clearText, encrypted);

0 commit comments

Comments
 (0)