diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index e9d972e9d..fe0bdeb77 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -737,7 +737,7 @@ public class WhisperServerService extends Application put( + public boolean put( @Nonnull final ReceiptSerial receiptSerial, final long receiptExpiration, final long receiptLevel, @@ -87,13 +87,13 @@ public class RedeemedReceiptsManager { ":account_uuid", AttributeValues.b(accountUuid), ":redemption_time", AttributeValues.n(now.getEpochSecond()))) .build(); - return client.updateItem(updateItemRequest).thenApply(updateItemResponse -> { + final UpdateItemResponse updateItemResponse = client.updateItem(updateItemRequest); + final Map attributes = updateItemResponse.attributes(); final long ddbReceiptExpiration = Long.parseLong(attributes.get(KEY_RECEIPT_EXPIRATION).n()); final long ddbReceiptLevel = Long.parseLong(attributes.get(KEY_RECEIPT_LEVEL).n()); final UUID ddbAccountUuid = UUIDUtil.fromByteBuffer(attributes.get(KEY_ACCOUNT_UUID).b().asByteBuffer()); return ddbReceiptExpiration == receiptExpiration && ddbReceiptLevel == receiptLevel && Objects.equals(ddbAccountUuid, accountUuid); - }); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/backup/BackupAuthManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/backup/BackupAuthManagerTest.java index c056203e7..961d32f8f 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/backup/BackupAuthManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/backup/BackupAuthManagerTest.java @@ -341,7 +341,7 @@ public class BackupAuthManagerTest { clock.pin(Instant.EPOCH.plus(Duration.ofDays(1))); when(accountsManager.update(any(Account.class), any())).thenReturn(account); when(redeemedReceiptsManager.put(any(), eq(expirationTime.getEpochSecond()), eq(201L), eq(aci))) - .thenReturn(CompletableFuture.completedFuture(true)); + .thenReturn(true); authManager.redeemReceipt(account, receiptPresentation(201, expirationTime)); verify(accountsManager, times(1)).update(any(Account.class), any()); } @@ -354,7 +354,7 @@ public class BackupAuthManagerTest { clock.pin(Instant.EPOCH.plus(Duration.ofDays(1))); when(redeemedReceiptsManager.put(any(), eq(expirationTime.getEpochSecond()), eq(201L), eq(aci))) - .thenReturn(CompletableFuture.completedFuture(true)); + .thenReturn(true); assertThatExceptionOfType(BackupMissingIdCommitmentException.class) .isThrownBy(() -> authManager.redeemReceipt(account, receiptPresentation(201, expirationTime))); } @@ -375,7 +375,7 @@ public class BackupAuthManagerTest { clock.pin(Instant.EPOCH.plus(Duration.ofDays(1))); when(accountsManager.update(any(Account.class), any())).thenReturn(account); when(redeemedReceiptsManager.put(any(), eq(newExpirationTime.getEpochSecond()), eq(201L), eq(aci))) - .thenReturn(CompletableFuture.completedFuture(true)); + .thenReturn(true); authManager.redeemReceipt(account, receiptPresentation(201, newExpirationTime)); final ArgumentCaptor> updaterCaptor = ArgumentCaptor.captor(); @@ -430,7 +430,7 @@ public class BackupAuthManagerTest { clock.pin(Instant.EPOCH.plus(Duration.ofDays(1))); when(accountsManager.update(any(Account.class), any())).thenReturn(account); when(redeemedReceiptsManager.put(any(), eq(expirationTime.getEpochSecond()), eq(201L), eq(aci))) - .thenReturn(CompletableFuture.completedFuture(false)); + .thenReturn(false); assertThatExceptionOfType(BackupBadReceiptException.class) .isThrownBy(() -> authManager.redeemReceipt(account, receiptPresentation(201, expirationTime))); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DonationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DonationControllerTest.java index d6526dfa4..818e0e362 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DonationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DonationControllerTest.java @@ -23,7 +23,6 @@ import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -114,8 +113,7 @@ class DonationControllerTest { when(receiptCredentialPresentation.getReceiptLevel()).thenReturn(receiptLevel); final long receiptExpiration = nowEpochSeconds + 86400 * 30; when(receiptCredentialPresentation.getReceiptExpirationTime()).thenReturn(receiptExpiration); - when(redeemedReceiptsManager.put(same(receiptSerial), eq(receiptExpiration), eq(receiptLevel), eq(AuthHelper.VALID_UUID))).thenReturn( - CompletableFuture.completedFuture(Boolean.TRUE)); + when(redeemedReceiptsManager.put(same(receiptSerial), eq(receiptExpiration), eq(receiptLevel), eq(AuthHelper.VALID_UUID))).thenReturn(true); when(accountsManager.getByAccountIdentifier(eq(AuthHelper.VALID_UUID))) .thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); @@ -138,8 +136,7 @@ class DonationControllerTest { when(receiptCredentialPresentation.getReceiptLevel()).thenReturn(receiptLevel); final long receiptExpiration = nowEpochSeconds + 86400 * 30; when(receiptCredentialPresentation.getReceiptExpirationTime()).thenReturn(receiptExpiration); - when(redeemedReceiptsManager.put(same(receiptSerial), eq(receiptExpiration), eq(receiptLevel), eq(AuthHelper.VALID_UUID))).thenReturn( - CompletableFuture.completedFuture(Boolean.FALSE)); + when(redeemedReceiptsManager.put(same(receiptSerial), eq(receiptExpiration), eq(receiptLevel), eq(AuthHelper.VALID_UUID))).thenReturn(false); when(accountsManager.getByAccountIdentifier(eq(AuthHelper.VALID_UUID))) .thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/RedeemedReceiptsManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/RedeemedReceiptsManagerTest.java index abd7aab50..b2d5c3dc3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/RedeemedReceiptsManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/RedeemedReceiptsManagerTest.java @@ -10,7 +10,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.time.Clock; import java.time.Duration; import java.time.Instant; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +38,7 @@ class RedeemedReceiptsManagerTest { redeemedReceiptsManager = new RedeemedReceiptsManager( clock, Tables.REDEEMED_RECEIPTS.tableName(), - DYNAMO_DB_EXTENSION.getDynamoDbAsyncClient(), + DYNAMO_DB_EXTENSION.getDynamoDbClient(), Duration.ofDays(90)); } @@ -47,22 +46,22 @@ class RedeemedReceiptsManagerTest { void testPut() throws ExecutionException, InterruptedException { final long receiptExpiration = 42; final long receiptLevel = 3; - CompletableFuture put; + boolean put; // initial insert should return true put = redeemedReceiptsManager.put(receiptSerial, receiptExpiration, receiptLevel, AuthHelper.VALID_UUID); - assertThat(put.get()).isTrue(); + assertThat(put).isTrue(); // subsequent attempted inserts with modified parameters should return false put = redeemedReceiptsManager.put(receiptSerial, receiptExpiration + 1, receiptLevel, AuthHelper.VALID_UUID); - assertThat(put.get()).isFalse(); + assertThat(put).isFalse(); put = redeemedReceiptsManager.put(receiptSerial, receiptExpiration, receiptLevel + 1, AuthHelper.VALID_UUID); - assertThat(put.get()).isFalse(); + assertThat(put).isFalse(); put = redeemedReceiptsManager.put(receiptSerial, receiptExpiration, receiptLevel, AuthHelper.VALID_UUID_TWO); - assertThat(put.get()).isFalse(); + assertThat(put).isFalse(); // repeated insert attempt of the original parameters should return true put = redeemedReceiptsManager.put(receiptSerial, receiptExpiration, receiptLevel, AuthHelper.VALID_UUID); - assertThat(put.get()).isTrue(); + assertThat(put).isTrue(); } }