Skip to content

Commit

Permalink
Hotfix: empty pk should not fail overall share. Needed to also filter…
Browse files Browse the repository at this point in the history
… on empty string. (#53)
  • Loading branch information
jsonsivar authored Feb 24, 2021
1 parent 46c3522 commit 304bf6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions integration_tests/sharing_interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,40 @@ describe('Users sharing data', () => {
expect(data.notification.relatedObject?.itemPaths[0].bucketKey).not.to.be.null;
expect(data.notification.relatedObject?.keys[0]).not.to.be.null;
}).timeout(TestsDefaultTimeout);

it('empty pk should not fail share', async () => {
const { user: user1 } = await authenticateAnonymousUser();
const user1Pk = Buffer.from(user1.identity.public.pubKey).toString('hex');
const txtContent = 'Some manual text should be in the file';

const storage1 = new UserStorage(user1, TestStorageConfig);
const uploadResponse = await storage1.addItems({
bucket: 'personal',
files: [
{
path: 'top.txt',
data: txtContent,
mimeType: 'plain/text',
},
],
});

await storage1.initMailbox();

// share with new user
const shareResult = await storage1.shareViaPublicKey({
publicKeys: [{
id: '[email protected]',
pk: '',
}],
paths: [{
bucket: 'personal',
path: '/top.txt',
}],
});

expect(shareResult.publicKeys).not.to.be.empty;
expect(shareResult.publicKeys[0].type).to.equal(ShareKeyType.Temp);
expect(shareResult.publicKeys[0].pk).not.to.be.empty;
}).timeout(TestsDefaultTimeout);
});
2 changes: 1 addition & 1 deletion packages/storage/src/userStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ export class UserStorage {
const idString = Buffer.from(this.user.identity.public.pubKey).toString('hex');
const filteredRecipients: string[] = request.publicKeys
.map((key) => key.pk)
.filter((key) => key !== null && key !== undefined) as string[];
.filter((key) => !!key) as string[];
const store = await this.getMetadataStore();

const invitations = await createFileInvitations(
Expand Down

0 comments on commit 304bf6a

Please sign in to comment.