@wireapp/core 42.9.4 → 42.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,6 +124,21 @@ export declare class ConversationService extends TypedEventEmitter<Events> {
124
124
  user: QualifiedId;
125
125
  client: string;
126
126
  }, otherUserId: QualifiedId, shouldRetry?: boolean) => Promise<MLSConversation>;
127
+ /**
128
+ * Will try to register mls group by sending an empty commit to establish it.
129
+ * After group was successfully established, it will try to add other users to the group.
130
+ *
131
+ * @param groupId - id of the MLS group
132
+ * @param conversationId - id of the conversation
133
+ * @param selfUserId - id of the self user
134
+ * @param qualifiedUsers - list of qualified users to add to the group (should not include the self user)
135
+ */
136
+ tryEstablishingMLSGroup({ groupId, conversationId, selfUserId, qualifiedUsers, }: {
137
+ groupId: string;
138
+ conversationId: QualifiedId;
139
+ selfUserId: QualifiedId;
140
+ qualifiedUsers: QualifiedId[];
141
+ }): Promise<void>;
127
142
  private handleMLSMessageAddEvent;
128
143
  private recoverMLSConversationFromEpochMismatch;
129
144
  private handleMLSWelcomeMessageEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,YAAY,EAIZ,4BAA4B,EAE7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAEL,cAAc,EAC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P,cAAc,GACf,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBvD,8BAA8B,CAAC,EAC1C,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBhD,oBAAoB,CAAC,cAAc,EAAE,WAAW;IAI7D;;;;;OAKG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAmBpE;;;OAGG;IACU,qBAAqB,CAAC,OAAO,EAAE,MAAM;IAIlD;;;;OAIG;IACU,4BAA4B,CAAC,OAAO,EAAE,MAAM;IAI5C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,YAAY;IAYb,gCAAgC;IAa7C;;;;;OAKG;YACW,+BAA+B;IA6B7C;;;;;;;OAOG;IACH,SAAgB,4BAA4B,YACjC,MAAM,YACL;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,eAChC,WAAW,4BAEvB,QAAQ,eAAe,CAAC,CAoDzB;YAEY,wBAAwB;YAoBxB,uCAAuC;YAYvC,4BAA4B;YAI5B,wBAAwB;IAIzB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;CAYnF"}
1
+ {"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,YAAY,EAIZ,4BAA4B,EAE7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD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AW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;CAYnF"}
@@ -394,6 +394,39 @@ class ConversationService extends commons_1.TypedEventEmitter {
394
394
  this.logger.error(`There was an error while handling epoch mismatch in MLS conversation (id: ${qualifiedId.id}):`, error);
395
395
  }
396
396
  }
397
+ /**
398
+ * Will try to register mls group by sending an empty commit to establish it.
399
+ * After group was successfully established, it will try to add other users to the group.
400
+ *
401
+ * @param groupId - id of the MLS group
402
+ * @param conversationId - id of the conversation
403
+ * @param selfUserId - id of the self user
404
+ * @param qualifiedUsers - list of qualified users to add to the group (should not include the self user)
405
+ */
406
+ async tryEstablishingMLSGroup({ groupId, conversationId, selfUserId, qualifiedUsers, }) {
407
+ const wasGroupEstablishedBySelfClient = await this.mlsService.tryEstablishingMLSGroup(groupId);
408
+ if (!wasGroupEstablishedBySelfClient) {
409
+ this.logger.info('Group was not established by self client, skipping adding users to the group.');
410
+ return;
411
+ }
412
+ this.logger.info('Group was established by self client, adding other users to the group...');
413
+ const usersToAdd = [
414
+ ...qualifiedUsers,
415
+ Object.assign(Object.assign({}, selfUserId), { skipOwnClientId: this.apiClient.validatedClientId }),
416
+ ];
417
+ const { conversation } = await this.addUsersToMLSConversation({
418
+ conversationId,
419
+ groupId,
420
+ qualifiedUsers: usersToAdd,
421
+ });
422
+ const addedUsers = conversation.members.others;
423
+ if (addedUsers.length > 0) {
424
+ this.logger.info(`Successfully added ${addedUsers} users to the group.`);
425
+ }
426
+ else {
427
+ this.logger.info('No other users were added to the group.');
428
+ }
429
+ }
397
430
  async handleMLSMessageAddEvent(event) {
398
431
  try {
399
432
  return await this.mlsService.handleMLSMessageAddEvent(event);
@@ -105,6 +105,10 @@ describe('ConversationService', () => {
105
105
  handleMLSMessageAddEvent: jest.fn(),
106
106
  conversationExists: jest.fn(),
107
107
  isConversationEstablished: jest.fn(),
108
+ tryEstablishingMLSGroup: jest.fn(),
109
+ getKeyPackagesPayload: jest.fn(),
110
+ addUsersToExistingConversation: jest.fn(),
111
+ resetKeyMaterialRenewal: jest.fn(),
108
112
  };
109
113
  const conversationService = new __1.ConversationService(client, mockedProteusService, mockedMLSService);
110
114
  jest.spyOn(conversationService, 'joinByExternalCommit');
@@ -402,6 +406,80 @@ describe('ConversationService', () => {
402
406
  expect(fetchedMembers).toEqual(members);
403
407
  });
404
408
  });
409
+ describe('addUsersToMLSConversation', () => {
410
+ it('should claim key packages for all the users and add them to the group', async () => {
411
+ const [conversationService, { apiClient, mlsService }] = buildConversationService();
412
+ const mockGroupId = 'groupId';
413
+ const mockConversationId = { id: PayloadHelper.getUUID(), domain: 'local.wire.com' };
414
+ const otherUsersToAdd = Array(3)
415
+ .fill(0)
416
+ .map(() => ({ id: PayloadHelper.getUUID(), domain: 'local.wire.com' }));
417
+ const selfUserToAdd = { id: 'self-user-id', domain: 'local.wire.com', skipOwnClientId: apiClient.clientId };
418
+ const qualifiedUsers = [...otherUsersToAdd, selfUserToAdd];
419
+ jest
420
+ .spyOn(mlsService, 'getKeyPackagesPayload')
421
+ .mockResolvedValueOnce({ coreCryptoKeyPackagesPayload: [], failedToFetchKeyPackages: [] });
422
+ jest.spyOn(apiClient.api.conversation, 'getConversation').mockResolvedValueOnce({
423
+ qualified_id: mockConversationId,
424
+ protocol: conversation_1.ConversationProtocol.MLS,
425
+ epoch: 1,
426
+ group_id: mockGroupId,
427
+ });
428
+ const mlsMessage = { events: [], time: '' };
429
+ jest.spyOn(mlsService, 'addUsersToExistingConversation').mockResolvedValueOnce(mlsMessage);
430
+ await conversationService.addUsersToMLSConversation({
431
+ qualifiedUsers,
432
+ groupId: mockGroupId,
433
+ conversationId: mockConversationId,
434
+ });
435
+ expect(mlsService.getKeyPackagesPayload).toHaveBeenCalledWith(qualifiedUsers);
436
+ expect(mlsService.resetKeyMaterialRenewal).toHaveBeenCalledWith(mockGroupId);
437
+ });
438
+ });
439
+ describe('tryEstablishingMLSGroup', () => {
440
+ it('should add all the users to a MLS group after group was established by the self client', async () => {
441
+ const [conversationService, { apiClient, mlsService }] = buildConversationService();
442
+ const selfUserId = { id: 'self-user-id', domain: 'local.wire.com' };
443
+ const mockConversationId = { id: PayloadHelper.getUUID(), domain: 'local.wire.com' };
444
+ const mockGroupId = 'groupId';
445
+ const otherUsersToAdd = Array(3)
446
+ .fill(0)
447
+ .map(() => ({ id: PayloadHelper.getUUID(), domain: 'local.wire.com' }));
448
+ jest.spyOn(mlsService, 'tryEstablishingMLSGroup').mockResolvedValueOnce(true);
449
+ jest
450
+ .spyOn(conversationService, 'addUsersToMLSConversation')
451
+ .mockResolvedValueOnce({ conversation: { members: { others: [] } } });
452
+ await conversationService.tryEstablishingMLSGroup({
453
+ conversationId: mockConversationId,
454
+ groupId: mockGroupId,
455
+ qualifiedUsers: otherUsersToAdd,
456
+ selfUserId,
457
+ });
458
+ expect(conversationService.addUsersToMLSConversation).toHaveBeenCalledWith({
459
+ conversationId: mockConversationId,
460
+ groupId: mockGroupId,
461
+ qualifiedUsers: [...otherUsersToAdd, Object.assign(Object.assign({}, selfUserId), { skipOwnClientId: apiClient.clientId })],
462
+ });
463
+ });
464
+ it('should not add any users if MLS group was not established by the self client', async () => {
465
+ const [conversationService, { mlsService }] = buildConversationService();
466
+ const selfUserId = { id: 'self-user-id', domain: 'local.wire.com' };
467
+ const mockConversationId = { id: PayloadHelper.getUUID(), domain: 'local.wire.com' };
468
+ const mockGroupId = 'groupId';
469
+ const otherUsersToAdd = Array(3)
470
+ .fill(0)
471
+ .map(() => ({ id: PayloadHelper.getUUID(), domain: 'local.wire.com' }));
472
+ jest.spyOn(mlsService, 'tryEstablishingMLSGroup').mockResolvedValueOnce(false);
473
+ jest.spyOn(conversationService, 'addUsersToMLSConversation');
474
+ await conversationService.tryEstablishingMLSGroup({
475
+ conversationId: mockConversationId,
476
+ groupId: mockGroupId,
477
+ qualifiedUsers: otherUsersToAdd,
478
+ selfUserId,
479
+ });
480
+ expect(conversationService.addUsersToMLSConversation).not.toHaveBeenCalled();
481
+ });
482
+ });
405
483
  });
406
484
  function generateImage() {
407
485
  const image = {
@@ -5,7 +5,9 @@ export declare const CoreCryptoMLSError: {
5
5
  readonly EXTERNAL_COMMIT_NOT_MERGED: "You tried to join with an external commit but did not merge it yet. We will reapply this message for you when you merge your external commit";
6
6
  readonly FUTURE_EPOCH: "Incoming message is for a future epoch. We will buffer it until the commit for that epoch arrives";
7
7
  };
8
+ readonly CONVERSATION_ALREADY_EXISTS: "Conversation already exists";
8
9
  };
9
10
  export declare const isCoreCryptoMLSWrongEpochError: (error: unknown) => boolean;
11
+ export declare const isCoreCryptoMLSConversationAlreadyExistsError: (error: unknown) => boolean;
10
12
  export declare const shouldMLSDecryptionErrorBeIgnored: (error: unknown) => error is Error;
11
13
  //# sourceMappingURL=CoreCryptoMLSError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CoreCryptoMLSError.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/CoreCryptoMLSError.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,kBAAkB;;;;;;;CAQrB,CAAC;AAEX,eAAO,MAAM,8BAA8B,UAAW,OAAO,KAAG,OAE/D,CAAC;AAQF,eAAO,MAAM,iCAAiC,UAAW,OAAO,mBAE/D,CAAC"}
1
+ {"version":3,"file":"CoreCryptoMLSError.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/CoreCryptoMLSError.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,kBAAkB;;;;;;;;CASrB,CAAC;AAEX,eAAO,MAAM,8BAA8B,UAAW,OAAO,KAAG,OAE/D,CAAC;AAEF,eAAO,MAAM,6CAA6C,UAAW,OAAO,KAAG,OAE9E,CAAC;AAQF,eAAO,MAAM,iCAAiC,UAAW,OAAO,mBAE/D,CAAC"}
@@ -18,7 +18,7 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.shouldMLSDecryptionErrorBeIgnored = exports.isCoreCryptoMLSWrongEpochError = exports.CoreCryptoMLSError = void 0;
21
+ exports.shouldMLSDecryptionErrorBeIgnored = exports.isCoreCryptoMLSConversationAlreadyExistsError = exports.isCoreCryptoMLSWrongEpochError = exports.CoreCryptoMLSError = void 0;
22
22
  exports.CoreCryptoMLSError = {
23
23
  DECRYPTION: {
24
24
  WRONG_EPOCH: 'Incoming message is for the wrong epoch',
@@ -26,11 +26,16 @@ exports.CoreCryptoMLSError = {
26
26
  EXTERNAL_COMMIT_NOT_MERGED: 'You tried to join with an external commit but did not merge it yet. We will reapply this message for you when you merge your external commit',
27
27
  FUTURE_EPOCH: 'Incoming message is for a future epoch. We will buffer it until the commit for that epoch arrives',
28
28
  },
29
+ CONVERSATION_ALREADY_EXISTS: 'Conversation already exists',
29
30
  };
30
31
  const isCoreCryptoMLSWrongEpochError = (error) => {
31
32
  return error instanceof Error && error.message === exports.CoreCryptoMLSError.DECRYPTION.WRONG_EPOCH;
32
33
  };
33
34
  exports.isCoreCryptoMLSWrongEpochError = isCoreCryptoMLSWrongEpochError;
35
+ const isCoreCryptoMLSConversationAlreadyExistsError = (error) => {
36
+ return error instanceof Error && error.message === exports.CoreCryptoMLSError.CONVERSATION_ALREADY_EXISTS;
37
+ };
38
+ exports.isCoreCryptoMLSConversationAlreadyExistsError = isCoreCryptoMLSConversationAlreadyExistsError;
34
39
  const mlsDecryptionErrorsToIgnore = [
35
40
  exports.CoreCryptoMLSError.DECRYPTION.ALREADY_DECRYPTED,
36
41
  exports.CoreCryptoMLSError.DECRYPTION.EXTERNAL_COMMIT_NOT_MERGED,
@@ -110,6 +110,13 @@ export declare class MLSService extends TypedEventEmitter<Events> {
110
110
  user: QualifiedId;
111
111
  client?: string;
112
112
  }): Promise<PostMlsMessageResponse>;
113
+ /**
114
+ * Will try to register mls group and send an empty commit to establish it.
115
+ *
116
+ * @param groupId - id of the MLS group
117
+ * @returns true if the client has successfully established the group, false otherwise
118
+ */
119
+ readonly tryEstablishingMLSGroup: (groupId: string) => Promise<boolean>;
113
120
  /**
114
121
  * Will send a removal commit for given clients
115
122
  * @param groupId groupId of the conversation
@@ -1 +1 @@
1
- {"version":3,"file":"MLSService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/MLSService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAqB,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAC,sBAAsB,EAAE,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AAChG,OAAO,EAAC,eAAe,EAAC,MAAM,sDAAsD,CAAC;AACrF,OAAO,EAAC,8BAA8B,EAAE,2BAA2B,EAAC,MAAM,+BAA+B,CAAC;AAE1G,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAGzD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAW,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACL,eAAe,EAIf,cAAc,EACd,UAAU,EAEV,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAC,gBAAgB,EAAsB,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAC,sBAAsB,EAAC,MAAM,sCAAsC,CAAC;AAG5E,OAAO,EAAC,4BAA4B,EAAE,4BAA4B,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,oBAAoB,UAAW,UAAU,GAAG,EAAE,KAAG,UAE7D,CAAC;AAEF,UAAU,qBAAsB,SAAQ,gBAAgB;IACtD;;OAEG;IACH,uCAAuC,EAAE,MAAM,CAA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IAQ7D;;;;OAIG;IACI,sCAAsC,CAAC,QAAQ,EAAE,MAAM;IAQ9D;;;;OAIG;YACW,+BAA+B;YAQ/B,gCAAgC;YAYhC,2BAA2B;IAIzC;;;;;OAKG;YACW,mBAAmB;YAYnB,oBAAoB;IAOrB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7D;;;;;OAKG;IACU,4BAA4B,CACvC,uBAAuB,EAAE,WAAW,EACpC,iBAAiB,CAAC,EAAE,kBAAkB,GACrC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAQ9B;;;;;;;OAOG;IACU,sBAAsB,CAAC,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAC,EAAE,4BAA4B;IAiBjG;;;;;OAKG;IACU,sBAAsB,CAAC,EAAC,OAAO,EAAE,UAAkB,EAAC,EAAE,4BAA4B;IAa/F;;;;OAIG;IACU,6BAA6B;IAiB1C;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IAY5F,wBAAwB,CAAC,KAAK,EAAE,8BAA8B;IAI9D,4BAA4B,CAAC,KAAK,EAAE,2BAA2B,EAAE,QAAQ,EAAE,MAAM;CAa/F"}
@@ -106,6 +106,38 @@ class MLSService extends commons_1.TypedEventEmitter {
106
106
  throw error;
107
107
  }
108
108
  });
109
+ /**
110
+ * Will try to register mls group and send an empty commit to establish it.
111
+ *
112
+ * @param groupId - id of the MLS group
113
+ * @returns true if the client has successfully established the group, false otherwise
114
+ */
115
+ this.tryEstablishingMLSGroup = async (groupId) => {
116
+ this.logger.info(`Trying to establish a MLS group with id ${groupId}.`);
117
+ // Before trying to register a group, check if the group is already established locally.
118
+ // We could have received a welcome message in the meantime.
119
+ const doesMLSGroupExistLocally = await this.conversationExists(groupId);
120
+ if (doesMLSGroupExistLocally) {
121
+ this.logger.info(`MLS Group with id ${groupId} already exists, skipping the initialisation.`);
122
+ return false;
123
+ }
124
+ try {
125
+ await this.registerConversation(groupId, []);
126
+ return true;
127
+ }
128
+ catch (error) {
129
+ // If conversation already existed, locally, nothing more to do, we've received a welcome message.
130
+ if ((0, CoreCryptoMLSError_1.isCoreCryptoMLSConversationAlreadyExistsError)(error)) {
131
+ this.logger.info(`MLS Group with id ${groupId} already exists, skipping the initialisation.`);
132
+ return false;
133
+ }
134
+ this.logger.info(`MLS Group with id ${groupId} was not established succesfully, wiping the group locally...`);
135
+ // Otherwise it's a backend error. Somebody else might have created the group in the meantime.
136
+ // We should wipe the group locally, wait for the welcome message or join later via external commit.
137
+ await this.wipeConversation(groupId);
138
+ return false;
139
+ }
140
+ };
109
141
  this.config = {
110
142
  keyingMaterialUpdateThreshold,
111
143
  nbKeyPackages,
@@ -20,8 +20,10 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const client_1 = require("@wireapp/api-client/lib/client");
22
22
  const event_1 = require("@wireapp/api-client/lib/event");
23
+ const http_1 = require("@wireapp/api-client/lib/http");
23
24
  const crypto_1 = require("crypto");
24
25
  const api_client_1 = require("@wireapp/api-client");
26
+ const CoreCryptoMLSError_1 = require("./CoreCryptoMLSError");
25
27
  const MLSService_1 = require("./MLSService");
26
28
  const CoreDB_1 = require("../../../storage/CoreDB");
27
29
  const RecurringTaskScheduler_1 = require("../../../util/RecurringTaskScheduler");
@@ -304,4 +306,50 @@ describe('MLSService', () => {
304
306
  expect(apiClient.api.client.uploadMLSKeyPackages).not.toHaveBeenCalled();
305
307
  });
306
308
  });
309
+ describe('tryEstablishingMLSGroup', () => {
310
+ it('returns false if group did already exist locally', async () => {
311
+ const [mlsService] = await createMLSService();
312
+ const mockGroupId = 'mock-group-id';
313
+ jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(true);
314
+ jest.spyOn(mlsService, 'registerConversation').mockImplementation(jest.fn());
315
+ const wasConversationEstablished = await mlsService.tryEstablishingMLSGroup(mockGroupId);
316
+ expect(mlsService.registerConversation).not.toHaveBeenCalled();
317
+ expect(wasConversationEstablished).toBe(false);
318
+ });
319
+ it('returns false if corecrypto has thrown an error when trying to register group locally', async () => {
320
+ const [mlsService] = await createMLSService();
321
+ const mockGroupId = 'mock-group-id';
322
+ jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(false);
323
+ jest
324
+ .spyOn(mlsService, 'registerConversation')
325
+ .mockRejectedValueOnce(new Error(CoreCryptoMLSError_1.CoreCryptoMLSError.CONVERSATION_ALREADY_EXISTS));
326
+ const wasConversationEstablished = await mlsService.tryEstablishingMLSGroup(mockGroupId);
327
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, []);
328
+ expect(wasConversationEstablished).toBe(false);
329
+ });
330
+ it('returns false and wipes group locally if any backend error was thrown', async () => {
331
+ const [mlsService] = await createMLSService();
332
+ const mockGroupId = 'mock-group-id2';
333
+ jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(false);
334
+ jest
335
+ .spyOn(mlsService, 'registerConversation')
336
+ .mockRejectedValueOnce(new http_1.BackendError('', http_1.BackendErrorLabel.MLS_STALE_MESSAGE, http_1.StatusCode.CONFLICT));
337
+ jest.spyOn(mlsService, 'wipeConversation').mockImplementation(jest.fn());
338
+ const wasConversationEstablished = await mlsService.tryEstablishingMLSGroup(mockGroupId);
339
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, []);
340
+ expect(mlsService.wipeConversation).toHaveBeenCalledWith(mockGroupId);
341
+ expect(wasConversationEstablished).toBe(false);
342
+ });
343
+ it('returns true after MLS group was etablished successfully', async () => {
344
+ const [mlsService] = await createMLSService();
345
+ const mockGroupId = 'mock-group-id2';
346
+ jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(false);
347
+ jest.spyOn(mlsService, 'registerConversation').mockResolvedValueOnce({ events: [], time: '' });
348
+ jest.spyOn(mlsService, 'wipeConversation').mockImplementation(jest.fn());
349
+ const wasConversationEstablished = await mlsService.tryEstablishingMLSGroup(mockGroupId);
350
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, []);
351
+ expect(mlsService.wipeConversation).not.toHaveBeenCalled();
352
+ expect(wasConversationEstablished).toBe(true);
353
+ });
354
+ });
307
355
  });
package/package.json CHANGED
@@ -11,11 +11,11 @@
11
11
  "./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
12
12
  },
13
13
  "dependencies": {
14
- "@wireapp/api-client": "^26.2.4",
15
- "@wireapp/commons": "^5.2.0",
14
+ "@wireapp/api-client": "^26.2.5",
15
+ "@wireapp/commons": "^5.2.1",
16
16
  "@wireapp/core-crypto": "1.0.0-rc.13",
17
17
  "@wireapp/cryptobox": "12.8.0",
18
- "@wireapp/promise-queue": "^2.2.5",
18
+ "@wireapp/promise-queue": "^2.2.6",
19
19
  "@wireapp/protocol-messaging": "1.44.0",
20
20
  "@wireapp/store-engine": "5.1.4",
21
21
  "@wireapp/store-engine-dexie": "^2.1.6",
@@ -60,6 +60,6 @@
60
60
  "test:coverage": "jest --coverage",
61
61
  "watch": "tsc --watch"
62
62
  },
63
- "version": "42.9.4",
64
- "gitHead": "54ac9ad6b06a45f1ba416f5a4b17425be1e9ce02"
63
+ "version": "42.10.1",
64
+ "gitHead": "5eab658b6736ee32a976455bea1390c3e798d429"
65
65
  }