-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle mls-welcome events, creating necessary data with core-crypto #WPB-12154 #111
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
public abstract class MessageResourceBase { | ||
protected final MessageHandlerBase handler; | ||
protected static final Integer PREKEYS_DEFAULT_REPLENISH = 10; | ||
|
||
public MessageResourceBase(MessageHandlerBase handler) { | ||
this.handler = handler; | ||
|
@@ -57,6 +58,14 @@ protected void handleMessage(UUID eventId, Payload payload, WireClient client) t | |
|
||
handler.onEvent(client, fromMls, genericMessageMls); | ||
break; | ||
case "conversation.mls-welcome": | ||
Logger.info("conversation.mls-welcome: bot: %s in: %s", botId, payload.conversation); | ||
|
||
client.processWelcomeMessage(payload.data.text); | ||
|
||
SystemMessage welcomeSystemMessage = getSystemMessage(eventId, payload); | ||
handler.onNewConversation(client, welcomeSystemMessage); | ||
break; | ||
case "conversation.member-join": | ||
Logger.debug("conversation.member-join: bot: %s", botId); | ||
|
||
|
@@ -71,8 +80,9 @@ protected void handleMessage(UUID eventId, Payload payload, WireClient client) t | |
return; | ||
} | ||
|
||
// Check if we still have some prekeys available. Upload new prekeys if needed | ||
// Check if we still have some prekeys and keyPackages available. Upload them if needed | ||
handler.validatePreKeys(client, participants.size()); | ||
client.checkAndReplenishKeyPackages(); | ||
|
||
SystemMessage systemMessage = getSystemMessage(eventId, payload); | ||
systemMessage.users = data.userIds; | ||
|
@@ -107,16 +117,22 @@ protected void handleMessage(UUID eventId, Payload payload, WireClient client) t | |
Logger.debug("conversation.create: bot: %s", botId); | ||
|
||
systemMessage = getSystemMessage(eventId, payload); | ||
Integer otherMembers = PREKEYS_DEFAULT_REPLENISH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the naming suggests a list of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the name of the variable. You also made me realize that I can skip proteus or MLS key replenishment in some cases, so I changed that |
||
if (systemMessage.conversation.members != null) { | ||
otherMembers = systemMessage.conversation.members.others.size(); | ||
Member self = new Member(); | ||
String selfDomain = null; | ||
if (systemMessage.conversation != null && systemMessage.conversation.id != null) { | ||
if (systemMessage.conversation.id != null) { | ||
selfDomain = systemMessage.conversation.id.domain; | ||
} | ||
self.id = new QualifiedId(botId, selfDomain); | ||
systemMessage.conversation.members.others.add(self); | ||
} | ||
|
||
// Check if we still have some prekeys and keyPackages available. Upload them if needed | ||
handler.validatePreKeys(client, otherMembers); | ||
client.checkAndReplenishKeyPackages(); | ||
|
||
handler.onNewConversation(client, systemMessage); | ||
break; | ||
case "conversation.rename": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.wire.xenon; | ||
|
||
import com.wire.xenon.backend.models.NewBot; | ||
import com.wire.xenon.crypto.mls.CryptoMlsClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class WireClientBaseTest { | ||
private WireClientBase wireClientBase; | ||
private WireAPI mockApi; | ||
private CryptoMlsClient mockCryptoMlsClient; | ||
private NewBot mockState; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mockApi = mock(WireAPI.class); | ||
mockCryptoMlsClient = mock(CryptoMlsClient.class); | ||
mockState = mock(NewBot.class); | ||
wireClientBase = new WireClientBase(mockApi, null, mockCryptoMlsClient, mockState); | ||
} | ||
|
||
@Test | ||
public void checkAndReplenishKeyPackages_replenishesWhenBelowThreshold() { | ||
when(mockCryptoMlsClient.validKeyPackageCount()).thenReturn(WireClientBase.KEY_PACKAGES_LOWER_THRESHOLD - 5L); | ||
|
||
wireClientBase.checkAndReplenishKeyPackages(); | ||
|
||
verify(mockCryptoMlsClient, times(1)).generateKeyPackages(WireClientBase.KEY_PACKAGES_REPLENISH_AMOUNT); | ||
} | ||
|
||
@Test | ||
public void checkAndReplenishKeyPackages_doesNotReplenishWhenAboveThreshold() { | ||
when(mockCryptoMlsClient.validKeyPackageCount()).thenReturn(WireClientBase.KEY_PACKAGES_LOWER_THRESHOLD + 5L); | ||
|
||
wireClientBase.checkAndReplenishKeyPackages(); | ||
|
||
verify(mockCryptoMlsClient, never()).generateKeyPackages(anyInt()); | ||
} | ||
|
||
@Test | ||
public void processWelcomeMessage_callsCheckAndReplenishKeyPackages() { | ||
String welcomeMessage = "welcomeMessage"; | ||
byte[] expectedResponse = new byte[]{1, 2, 3}; | ||
|
||
when(mockCryptoMlsClient.processWelcomeMessage(welcomeMessage)).thenReturn(expectedResponse); | ||
when(mockCryptoMlsClient.validKeyPackageCount()).thenReturn(WireClientBase.KEY_PACKAGES_LOWER_THRESHOLD + 5L); | ||
|
||
byte[] response = wireClientBase.processWelcomeMessage(welcomeMessage); | ||
|
||
verify(mockCryptoMlsClient, times(1)).processWelcomeMessage(welcomeMessage); | ||
assertArrayEquals(expectedResponse, response); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌🏻