Skip to content

Commit

Permalink
Do not set one-time pre-keys if the lists of new keys are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-signal committed Dec 8, 2023
1 parent 5b0fcbe commit 3cf1b92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public CompletableFuture<Response> setKeys(@Auth final DisabledPermittedAuthenti
return updateAccountFuture.thenCompose(updatedAccount -> {
final List<CompletableFuture<Void>> storeFutures = new ArrayList<>(3);

if (setKeysRequest.preKeys() != null) {
if (setKeysRequest.preKeys() != null && !setKeysRequest.preKeys().isEmpty()) {
storeFutures.add(keys.storeEcOneTimePreKeys(identifier, device.getId(), setKeysRequest.preKeys()));
}

if (setKeysRequest.pqPreKeys() != null) {
if (setKeysRequest.pqPreKeys() != null && !setKeysRequest.pqPreKeys().isEmpty()) {
storeFutures.add(keys.storeKemOneTimePreKeys(identifier, device.getId(), setKeysRequest.pqPreKeys()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,33 @@ void putKeysTestV2() {
verify(accounts).updateDeviceTransactionallyAsync(eq(AuthHelper.VALID_ACCOUNT), eq(SAMPLE_DEVICE_ID), any(), any());
}

@Test
void putKeysTestV2EmptySingleUseKeysList() {
final ECKeyPair identityKeyPair = Curve.generateKeyPair();
final ECSignedPreKey signedPreKey = KeysHelper.signedECPreKey(31338, identityKeyPair);
final IdentityKey identityKey = new IdentityKey(identityKeyPair.getPublicKey());

final SetKeysRequest setKeysRequest = new SetKeysRequest(List.of(), signedPreKey, List.of(), null);

when(AuthHelper.VALID_ACCOUNT.getIdentityKey(IdentityType.ACI)).thenReturn(identityKey);

try (final Response response =
resources.getJerseyTest()
.target("/v2/keys")
.request()
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.put(Entity.entity(setKeysRequest, MediaType.APPLICATION_JSON_TYPE))) {

assertThat(response.getStatus()).isEqualTo(204);

verify(KEYS, never()).storeEcOneTimePreKeys(any(), anyByte(), any());
verify(KEYS, never()).storeKemOneTimePreKeys(any(), anyByte(), any());

verify(AuthHelper.VALID_DEVICE).setSignedPreKey(eq(signedPreKey));
verify(accounts).updateDeviceTransactionallyAsync(eq(AuthHelper.VALID_ACCOUNT), eq(SAMPLE_DEVICE_ID), any(), any());
}
}

@Test
void putKeysPqTestV2() {
final ECPreKey preKey = KeysHelper.ecPreKey(31337);
Expand Down

0 comments on commit 3cf1b92

Please sign in to comment.