Skip to content

Commit

Permalink
feat(implement-mls-client-initialization) #WPB-12152
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexandreferris committed Nov 21, 2024
1 parent 302ab94 commit 91ec989
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +103,7 @@ public void confirmDevice(QualifiedId userId, UUID teamId, String clientId, Stri
return null;
});
CompletableFuture<Void> mlsKeyPackagesFuture = CompletableFuture.supplyAsync(() -> {
wireClientBase.uploadMlsKeyPackages(100);
wireClientBase.uploadMlsKeyPackages(KEY_PACKAGE_AMOUNT);
return null;
});
CompletableFuture<List<Conversation>> conversationsFuture = CompletableFuture.supplyAsync(() ->
Expand All @@ -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();
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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\"}");

}
}

Expand Down Expand Up @@ -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\"}");
}
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 91ec989

Please sign in to comment.