From 91ec98981d528c019d0a97309ac84a077e215ab0 Mon Sep 17 00:00:00 2001 From: alexandreferris Date: Thu, 21 Nov 2024 17:33:05 +0100 Subject: [PATCH] feat(implement-mls-client-initialization) #WPB-12152 * Update userAgent to legalhold/1.1.0 * Remove default value for core crypto password token * Update wirebot/runtime to 1.4.0 to use JDK 17 * Move KeyPackage amount to const * Change CompletableFuture to use exceptionally instead of handle * Update tests and remove unused try/catch --- Dockerfile | 2 +- hold.yaml | 4 +- .../hold/service/DeviceManagementService.java | 24 +++++------ .../service/DeviceManagementServiceTest.java | 43 +++++-------------- 4 files changed, 24 insertions(+), 49 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0e8f60..a75a506 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY . ./ RUN mvn -Dmaven.test.skip=true package # runtime stage -FROM wirebot/runtime:1.3.0 +FROM wirebot/runtime:1.4.0 RUN mkdir /opt/hold RUN mkdir /opt/hold/images diff --git a/hold.yaml b/hold.yaml index efd11cf..09621f4 100644 --- a/hold.yaml +++ b/hold.yaml @@ -42,7 +42,7 @@ jerseyClient: connectionRequestTimeout: 40s keepAlive: 0ms retries: 3 - userAgent: legalhold/1.0.7 + userAgent: legalhold/1.1.0 tls: protocol: TLSv1.3 provider: SunJSSE @@ -53,7 +53,7 @@ jerseyClient: sleep: ${DELAY:-60s} token: ${SERVICE_TOKEN:-dummy} apiHost: ${WIRE_API_HOST:-https://prod-nginz-https.wire.com} -coreCryptoPassword: ${CORE_CRYPTO_PASSWORD:-dummy} +coreCryptoPassword: ${CORE_CRYPTO_PASSWORD} database: driverClass: ${DB_DRIVER:-org.postgresql.Driver} diff --git a/src/main/java/com/wire/bots/hold/service/DeviceManagementService.java b/src/main/java/com/wire/bots/hold/service/DeviceManagementService.java index 042f6d4..d701527 100644 --- a/src/main/java/com/wire/bots/hold/service/DeviceManagementService.java +++ b/src/main/java/com/wire/bots/hold/service/DeviceManagementService.java @@ -27,6 +27,8 @@ import static com.wire.bots.hold.utils.Tools.hexify; public class DeviceManagementService { + private static final int KEY_PACKAGE_AMOUNT = 100; + private final CryptoDatabaseFactory cf; private final AccessDAO accessDAO; private final Client client; @@ -101,7 +103,7 @@ public void confirmDevice(QualifiedId userId, UUID teamId, String clientId, Stri return null; }); CompletableFuture mlsKeyPackagesFuture = CompletableFuture.supplyAsync(() -> { - wireClientBase.uploadMlsKeyPackages(100); + wireClientBase.uploadMlsKeyPackages(KEY_PACKAGE_AMOUNT); return null; }); CompletableFuture> conversationsFuture = CompletableFuture.supplyAsync(() -> @@ -114,16 +116,12 @@ public void confirmDevice(QualifiedId userId, UUID teamId, String clientId, Stri mlsPublicKeyFuture, mlsKeyPackagesFuture, conversationsFuture - ).handle((success, throwable) -> { - if (throwable != null) { - if (throwable instanceof CompletionException) { - throw new RuntimeException(throwable.getCause().getMessage()); - } else { - throw new RuntimeException(throwable.getMessage()); - } + ).exceptionally(throwable -> { + if (throwable instanceof CompletionException) { + throw new RuntimeException(throwable.getCause().getMessage()); + } else { + throw new RuntimeException(throwable.getMessage()); } - - return success; }); combinedFutures.get(); @@ -132,9 +130,9 @@ public void confirmDevice(QualifiedId userId, UUID teamId, String clientId, Stri wireClientBase.joinMlsConversation(conversation.id, conversation.mlsGroupId); } } catch (ExecutionException exception) { - throw new RuntimeException(exception.getCause().getMessage()); - } catch (Exception exception) { - throw new RuntimeException(exception.getMessage()); + throw new RuntimeException("ExecutionException: " + exception.getCause().getMessage()); + } catch (InterruptedException exception) { + throw new RuntimeException("InterruptedException: " + exception.getMessage()); } } diff --git a/src/test/java/com/wire/bots/hold/service/DeviceManagementServiceTest.java b/src/test/java/com/wire/bots/hold/service/DeviceManagementServiceTest.java index c3de2d6..99d9ba9 100644 --- a/src/test/java/com/wire/bots/hold/service/DeviceManagementServiceTest.java +++ b/src/test/java/com/wire/bots/hold/service/DeviceManagementServiceTest.java @@ -101,11 +101,7 @@ public void givenDisabledMls_whenConfirmingProteusDevice_thenInsertToDatabase() .willReturn(okJson(disabledMlsFeatureConfigJsonResponse))); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert( @@ -164,11 +160,7 @@ public void givenEnabledMlsAndFailingPublicKeys_whenConfirmingDevice_thenProteus ).thenReturn(1); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert( @@ -194,7 +186,7 @@ public void givenEnabledMls_whenConfirmingDeviceAndUpdateClientPublicKeyFails_th deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); } catch (Exception exception) { // then - assert exception.getMessage().equals("{\"error\":\"error from clients/" + clientId + "\"}"); + assert exception.getMessage().equals("ExecutionException: {\"error\":\"error from clients/" + clientId + "\"}"); } // then @@ -223,7 +215,7 @@ public void givenEnabledMls_whenConfirmingDeviceAndKeyPackagesFails_thenThrowsEr deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); } catch (Exception exception) { // then - assert exception.getMessage().equals("{\"error\":\"error from mls/key-packages/self/" + clientId + "\"}"); + assert exception.getMessage().equals("ExecutionException: {\"error\":\"error from mls/key-packages/self/" + clientId + "\"}"); } // then @@ -258,11 +250,7 @@ public void givenEnabledMls_whenConfirmingDeviceAndConversationsIdsFails_thenEmp ).thenReturn(1); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert( @@ -301,11 +289,7 @@ public void givenEnabledMls_whenConfirmingDeviceAndConversationsListFails_thenEm ).thenReturn(1); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert( @@ -344,11 +328,7 @@ public void givenEnabledMls_whenConfirmingDevice_thenEmptyConversationListIsRetu ).thenReturn(1); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert( @@ -384,8 +364,8 @@ public void givenEnabledMls_whenConfirmingDeviceAndGroupInfoFails_thenExceptionI try { deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); } catch (Exception exception) { + // then assert exception.getMessage().equals("{\"error\":\"error from conversations/" + conversationId.domain + "/" + conversationId.id + "/groupinfo\"}"); - } } @@ -423,6 +403,7 @@ public void givenEnabledMls_whenConfirmingDeviceAndCommitMlsBundleFails_thenExce try { deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); } catch (Exception exception) { + // then assert exception.getMessage().equals("{\"error\":\"error from mls/commit-bundles\"}"); } } @@ -466,11 +447,7 @@ public void givenEnabledMls_whenConfirmingDevice_thenDeviceIsSavedToDatabase() t ).thenReturn(1); // when - try { - deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); - } catch (Exception exception) { - // Do nothing - } + deviceManagementService.confirmDevice(userId, teamId, clientId, refreshToken); // then verify(accessDAO, times(1)).insert(