From 9734433f002b38ad3add6829cf74f46f90da657a Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 4 Oct 2021 11:25:38 -0400 Subject: [PATCH] Use the default `SecureRandom` algorithm for tests --- .../tests/controllers/DonationControllerTest.java | 15 ++++----------- .../storage/RedeemedReceiptsManagerTest.java | 10 +--------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java index bfa3fa07a..efe483b56 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java @@ -20,7 +20,6 @@ import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import com.google.common.collect.ImmutableSet; import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider; import io.dropwizard.testing.junit5.ResourceExtension; -import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.time.Clock; import java.time.Instant; @@ -69,14 +68,8 @@ class DonationControllerTest { static WireMockExtension wm = WireMockExtension.newInstance() .options(wireMockConfig().dynamicPort().dynamicHttpsPort()) .build(); - static SecureRandom secureRandom; - static { - try { - secureRandom = SecureRandom.getInstanceStrong(); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } - } + + private static final SecureRandom SECURE_RANDOM = new SecureRandom(); static DonationConfiguration getDonationConfiguration() { DonationConfiguration configuration = new DonationConfiguration(); @@ -119,10 +112,10 @@ class DonationControllerTest { accountsManager = mock(AccountsManager.class); AccountsHelper.setupMockUpdate(accountsManager); receiptSerialBytes = new byte[ReceiptSerial.SIZE]; - secureRandom.nextBytes(receiptSerialBytes); + SECURE_RANDOM.nextBytes(receiptSerialBytes); receiptSerial = new ReceiptSerial(receiptSerialBytes); presentation = new byte[ReceiptCredentialPresentation.SIZE]; - secureRandom.nextBytes(presentation); + SECURE_RANDOM.nextBytes(presentation); receiptCredentialPresentationFactory = mock(DonationController.ReceiptCredentialPresentationFactory.class); receiptCredentialPresentation = mock(ReceiptCredentialPresentation.class); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/RedeemedReceiptsManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/RedeemedReceiptsManagerTest.java index cb66307d7..770a02917 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/RedeemedReceiptsManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/RedeemedReceiptsManagerTest.java @@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.time.Clock; import java.time.Duration; @@ -31,14 +30,7 @@ class RedeemedReceiptsManagerTest { private static final long NOW_EPOCH_SECONDS = 1_500_000_000L; private static final String REDEEMED_RECEIPTS_TABLE_NAME = "redeemed_receipts"; - private static final SecureRandom SECURE_RANDOM; - static { - try { - SECURE_RANDOM = SecureRandom.getInstanceStrong(); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } - } + private static final SecureRandom SECURE_RANDOM = new SecureRandom(); @RegisterExtension static DynamoDbExtension dynamoDbExtension = DynamoDbExtension.builder()