Skip to content

Commit

Permalink
runfix: verify mls state on welcome message [WPB-6794] (#16913)
Browse files Browse the repository at this point in the history
* chore: bump core with mls service emitting new epoch on welcome

* test: handling mls welcome message

* refactor: simplify mls welcome message handler

* docs: improve comments
  • Loading branch information
PatrykBuniX authored Feb 26, 2024
1 parent fa45a82 commit 369229b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@peculiar/x509": "1.9.6",
"@wireapp/avs": "9.6.12",
"@wireapp/commons": "5.2.4",
"@wireapp/core": "45.0.1",
"@wireapp/core": "45.0.2",
"@wireapp/react-ui-kit": "9.15.4",
"@wireapp/store-engine-dexie": "2.1.7",
"@wireapp/webapp-events": "0.20.1",
Expand Down
57 changes: 57 additions & 0 deletions src/script/conversation/ConversationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
ConversationCreateEvent,
ConversationMemberJoinEvent,
CONVERSATION_EVENT,
ConversationMLSWelcomeEvent,
} from '@wireapp/api-client/lib/event/';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import {amplify} from 'amplify';
Expand Down Expand Up @@ -1261,6 +1262,62 @@ describe('ConversationRepository', () => {
});
});

describe('conversation.mls-welcome', () => {
it('should initialise mls 1:1 conversation after receiving a welcome', async () => {
const conversationRepository = testFactory.conversation_repository!;
const mockedGroupId = 'AAEAAKA0LuGtiU7NjqqlZIE2dQUAZWxuYS53aXJlLmxpbms=';

const conversation = _generateConversation({
groupId: mockedGroupId,
type: CONVERSATION_TYPE.ONE_TO_ONE,
protocol: ConversationProtocol.MLS,
});

const otherUserId = {id: 'f718410c-3833-479d-bd80-a5df03f38414', domain: 'test-domain'};
const otherUser = new User(otherUserId.id, otherUserId.domain);

conversationRepository['userState'].users.push(otherUser);
conversation.participating_user_ids.push(otherUserId);

await conversationRepository['saveConversation'](conversation);

const welcomeEvent: ConversationMLSWelcomeEvent = {
conversation: conversation.id,
data: conversation.groupId!,
from: 'd5a39ffb-6ce3-4cc8-9048-0e15d031b4c5',
time: '2015-04-27T11:42:31.475Z',
type: CONVERSATION_EVENT.MLS_WELCOME_MESSAGE,
};

const coreConversationService = container.resolve(Core).service!.conversation!;

jest.spyOn(coreConversationService, 'isMLSGroupEstablishedLocally').mockResolvedValueOnce(false);

const establishedMls1to1ConversationResponse = generateAPIConversation({
id: {id: '04ab891e-ccf1-4dba-9d74-bacec64b5b1e', domain: 'test-domain'},
type: CONVERSATION_TYPE.ONE_TO_ONE,
protocol: ConversationProtocol.MLS,
overwites: {
group_id: mockedGroupId,
epoch: 1,
qualified_others: [otherUserId],
members: {
others: [{id: otherUserId.id, status: 0, qualified_id: otherUserId}],
self: {},
} as any,
},
}) as BackendMLSConversation;

jest
.spyOn(coreConversationService, 'establishMLS1to1Conversation')
.mockResolvedValueOnce(establishedMls1to1ConversationResponse);

await conversationRepository['handleConversationEvent'](welcomeEvent);

expect(coreConversationService.establishMLS1to1Conversation).toHaveBeenCalled();
});
});

describe('conversation.asset-add', () => {
beforeEach(() => {
const matchUsers = new RegExp(`${escapeRegex(Config.getConfig().BACKEND_REST)}/users\\?ids=([a-z0-9-,]+)`);
Expand Down
6 changes: 2 additions & 4 deletions src/script/conversation/ConversationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
ConversationTypingEvent,
CONVERSATION_EVENT,
ConversationProtocolUpdateEvent,
ConversationMLSWelcomeEvent,
} from '@wireapp/api-client/lib/event';
import {BackendErrorLabel} from '@wireapp/api-client/lib/http/';
import type {BackendError} from '@wireapp/api-client/lib/http/';
Expand Down Expand Up @@ -3233,7 +3232,7 @@ export class ConversationRepository {
return this.onRename(conversationEntity, eventJson, eventSource === EventRepository.SOURCE.WEB_SOCKET);

case CONVERSATION_EVENT.MLS_WELCOME_MESSAGE:
return this.onMLSWelcomeMessage(conversationEntity, eventJson);
return this.onMLSWelcomeMessage(conversationEntity);

case ClientEvent.CONVERSATION.ASSET_ADD:
return this.onAssetAdd(conversationEntity, eventJson);
Expand Down Expand Up @@ -3922,10 +3921,9 @@ export class ConversationRepository {
* User has received a welcome message in a conversation.
*
* @param conversationEntity Conversation entity user has received a welcome message in
* @param eventJson JSON data of 'conversation.mls-welcome' event
* @returns Resolves when the event was handled
*/
private async onMLSWelcomeMessage(conversationEntity: Conversation, eventJson: ConversationMLSWelcomeEvent) {
private async onMLSWelcomeMessage(conversationEntity: Conversation) {
// If we receive a welcome message in mls 1:1 conversation, we need to make sure proteus 1:1 is hidden (if it exists)

if (conversationEntity.type() !== CONVERSATION_TYPE.ONE_TO_ONE || !isMLSConversation(conversationEntity)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ class MLSConversationVerificationStateHandler {
}

/**
* This function checks if the conversation is verified and if it is, it will degrade it
* Changes mls verification state to "degraded"
* @param conversation
* @param userIds
*/
private async degradeConversation(conversation: MLSConversation) {
const state = ConversationVerificationState.DEGRADED;
Expand All @@ -85,9 +84,8 @@ class MLSConversationVerificationStateHandler {
}

/**
* This function checks if the conversation is degraded and if it is, it will verify it
* Changes mls verification state to "verified"
* @param conversation
* @param userIds
*/
private async verifyConversation(conversation: MLSConversation) {
const state = ConversationVerificationState.VERIFIED;
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4812,9 +4812,9 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/api-client@npm:^26.10.10":
version: 26.10.10
resolution: "@wireapp/api-client@npm:26.10.10"
"@wireapp/api-client@npm:^26.10.11":
version: 26.10.11
resolution: "@wireapp/api-client@npm:26.10.11"
dependencies:
"@wireapp/commons": ^5.2.5
"@wireapp/priority-queue": ^2.1.4
Expand All @@ -4830,7 +4830,7 @@ __metadata:
tough-cookie: 4.1.3
ws: 8.16.0
zod: 3.22.4
checksum: b1610c4e8e0661e48d5df6de1d055231cabb2bee74d1dc74aeda8d242d97a79df72e7f4177f7ed17aeb7a30be04dd471283a44657423bbebe99cafdcaf866e37
checksum: 929574d2ed50a52da0a9e407010802d996efe531f37a7a13c7bad94b2837e221acaee2422ccbf0d213e5515358877ace91ddf1eb86af89b41501354ff82761f9
languageName: node
linkType: hard

Expand Down Expand Up @@ -4895,11 +4895,11 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:45.0.1":
version: 45.0.1
resolution: "@wireapp/core@npm:45.0.1"
"@wireapp/core@npm:45.0.2":
version: 45.0.2
resolution: "@wireapp/core@npm:45.0.2"
dependencies:
"@wireapp/api-client": ^26.10.10
"@wireapp/api-client": ^26.10.11
"@wireapp/commons": ^5.2.5
"@wireapp/core-crypto": 1.0.0-rc.43
"@wireapp/cryptobox": 12.8.0
Expand All @@ -4916,7 +4916,7 @@ __metadata:
long: ^5.2.0
uuidjs: 4.2.13
zod: 3.22.4
checksum: 80f731cb0ea289fcb3526faa1b7c87747e980bd5a307e306c1dc23cbd4a8fe86e96eb6670e71aac4b923a7d0fdf85fe47553b4f85517e0eaef1c307c35918568
checksum: 8b5c2eb1b41ac1f33de2cfa83549f06a93b0d874e0252a974c8bb9422f9561f7fabd724491d54065c30b9bfa0baeea90e4df3e8482ee55ab5f274f44ca303d85
languageName: node
linkType: hard

Expand Down Expand Up @@ -17616,7 +17616,7 @@ __metadata:
"@wireapp/avs": 9.6.12
"@wireapp/commons": 5.2.4
"@wireapp/copy-config": 2.1.14
"@wireapp/core": 45.0.1
"@wireapp/core": 45.0.2
"@wireapp/eslint-config": 3.0.5
"@wireapp/prettier-config": 0.6.3
"@wireapp/react-ui-kit": 9.15.4
Expand Down

0 comments on commit 369229b

Please sign in to comment.