Updates for org.apache.commons.lang3.RandomStringUtils deprecations

This commit is contained in:
Chris Eager 2024-11-14 15:52:42 -06:00 committed by Chris Eager
parent 93f4a91ebf
commit ecbb2f1399
18 changed files with 53 additions and 53 deletions

View File

@ -64,14 +64,14 @@ public class BufferingInterceptorIntegrationTest {
@Path("/virtual/{size}")
@ManagedAsync
public String getVirtual(@PathParam("size") int size) {
return RandomStringUtils.randomAscii(size);
return RandomStringUtils.secure().nextAscii(size);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/platform/{size}")
public String getPlatform(@PathParam("size") int size) {
return RandomStringUtils.randomAscii(size);
return RandomStringUtils.secure().nextAscii(size);
}
}
}

View File

@ -123,7 +123,7 @@ public class WebsocketResourceProviderIntegrationTest {
@Path("/{size}")
@ManagedAsync
public String get(@PathParam("size") int size) {
return RandomStringUtils.randomAscii(size);
return RandomStringUtils.secure().nextAscii(size);
}
@PUT

View File

@ -51,7 +51,7 @@ class OptionalAccessTest {
}
private static List<Arguments> verify() {
final String unidentifiedAccessKey = RandomStringUtils.randomAlphanumeric(16);
final String unidentifiedAccessKey = RandomStringUtils.secure().nextAlphanumeric(16);
final Anonymous correctUakHeader =
new Anonymous(Base64.getEncoder().encodeToString(unidentifiedAccessKey.getBytes()));
@ -180,7 +180,7 @@ class OptionalAccessTest {
@Test
void testTargetIdentifierIllegalArgument() {
final String unidentifiedAccessKey = RandomStringUtils.randomAlphanumeric(16);
final String unidentifiedAccessKey = RandomStringUtils.secure().nextAlphanumeric(16);
final Anonymous correctUakHeader =
new Anonymous(Base64.getEncoder().encodeToString(unidentifiedAccessKey.getBytes()));

View File

@ -1005,8 +1005,8 @@ class DeviceControllerTest {
}
private static List<String> waitForLinkedDeviceBadTokenIdentifierLength() {
return List.of(RandomStringUtils.randomAlphanumeric(DeviceController.MIN_TOKEN_IDENTIFIER_LENGTH - 1),
RandomStringUtils.randomAlphanumeric(DeviceController.MAX_TOKEN_IDENTIFIER_LENGTH + 1));
return List.of(RandomStringUtils.secure().nextAlphanumeric(DeviceController.MIN_TOKEN_IDENTIFIER_LENGTH - 1),
RandomStringUtils.secure().nextAlphanumeric(DeviceController.MAX_TOKEN_IDENTIFIER_LENGTH + 1));
}
@Test
@ -1177,7 +1177,7 @@ class DeviceControllerTest {
@Test
void recordRestoreAccountRequest() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
final RestoreAccountRequest restoreAccountRequest =
new RestoreAccountRequest(RestoreAccountRequest.Method.LOCAL_BACKUP);
@ -1195,7 +1195,7 @@ class DeviceControllerTest {
@Test
void recordRestoreAccountRequestBadToken() {
final String token = RandomStringUtils.randomAlphanumeric(128);
final String token = RandomStringUtils.secure().nextAlphanumeric(128);
final RestoreAccountRequest restoreAccountRequest =
new RestoreAccountRequest(RestoreAccountRequest.Method.LOCAL_BACKUP);
@ -1210,7 +1210,7 @@ class DeviceControllerTest {
@Test
void recordRestoreAccountRequestInvalidRequest() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
final RestoreAccountRequest restoreAccountRequest = new RestoreAccountRequest(null);
try (final Response response = resources.getJerseyTest()
@ -1224,7 +1224,7 @@ class DeviceControllerTest {
@Test
void waitForDeviceTransferRequest() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
final RestoreAccountRequest restoreAccountRequest =
new RestoreAccountRequest(RestoreAccountRequest.Method.LOCAL_BACKUP);
@ -1243,7 +1243,7 @@ class DeviceControllerTest {
@Test
void waitForDeviceTransferRequestNoRequestIssued() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
when(accountsManager.waitForRestoreAccountRequest(eq(token), any()))
.thenReturn(CompletableFuture.completedFuture(Optional.empty()));
@ -1260,7 +1260,7 @@ class DeviceControllerTest {
@ParameterizedTest
@ValueSource(ints = {0, -1, 3601})
void waitForDeviceTransferRequestBadTimeout(final int timeoutSeconds) {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
try (final Response response = resources.getJerseyTest()
.target("/v1/devices/restore_account/" + token)

View File

@ -104,7 +104,7 @@ public class ValidatingInterceptorTest {
@ParameterizedTest
@ValueSource(ints = {0, 1, 2, 3, 4, 6, 1000})
public void testExactlySizeValidationFailure(final int size) throws Exception {
final String stringValue = RandomStringUtils.randomAlphanumeric(size);
final String stringValue = RandomStringUtils.secure().nextAlphanumeric(size);
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
builderWithValidDefaults()
.setFixedSizeString(stringValue)
@ -119,7 +119,7 @@ public class ValidatingInterceptorTest {
));
final List<String> listValue = IntStream.range(0, size)
.mapToObj(i -> RandomStringUtils.randomAlphabetic(10))
.mapToObj(i -> RandomStringUtils.secure().nextAlphabetic(10))
.toList();
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
builderWithValidDefaults()
@ -181,7 +181,7 @@ public class ValidatingInterceptorTest {
@ParameterizedTest
@MethodSource
public void testRangeSizeValidationFailure(final int size, final Status expectedStatus) throws Exception {
final String stringValue = RandomStringUtils.randomAlphanumeric(size);
final String stringValue = RandomStringUtils.secure().nextAlphanumeric(size);
assertEquals(expectedStatus.getCode(), requestStatus(() -> stub.validationsEndpoint(
builderWithValidDefaults()
.setRangeSizeString(stringValue)
@ -196,7 +196,7 @@ public class ValidatingInterceptorTest {
)).getCode());
final List<String> listValue = IntStream.range(0, size)
.mapToObj(i -> RandomStringUtils.randomAlphabetic(10))
.mapToObj(i -> RandomStringUtils.secure().nextAlphabetic(10))
.toList();
assertEquals(expectedStatus.getCode(), requestStatus(() -> stub.validationsEndpoint(
builderWithValidDefaults()

View File

@ -101,7 +101,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
private static final UUID ACCOUNT_IDENTIFIER = UUID.randomUUID();
private static final byte DEVICE_ID = Device.PRIMARY_ID;
private static final String RECOGNIZED_PROXY_SECRET = RandomStringUtils.randomAlphanumeric(16);
private static final String RECOGNIZED_PROXY_SECRET = RandomStringUtils.secure().nextAlphanumeric(16);
// Please note that this certificate/key are used only for testing and are not used anywhere outside of this test.
// They were generated with:

View File

@ -38,7 +38,7 @@ class WebsocketHandshakeCompleteHandlerTest extends AbstractLeakDetectionTest {
private UserEventRecordingHandler userEventRecordingHandler;
private MutableRemoteAddressEmbeddedChannel embeddedChannel;
private static final String RECOGNIZED_PROXY_SECRET = RandomStringUtils.randomAlphanumeric(16);
private static final String RECOGNIZED_PROXY_SECRET = RandomStringUtils.secure().nextAlphanumeric(16);
private static class UserEventRecordingHandler extends ChannelInboundHandlerAdapter {

View File

@ -37,7 +37,7 @@ import org.whispersystems.textsecuregcm.tests.util.SynchronousExecutorService;
class APNSenderTest {
private static final String DESTINATION_DEVICE_TOKEN = RandomStringUtils.randomAlphanumeric(32);
private static final String DESTINATION_DEVICE_TOKEN = RandomStringUtils.secure().nextAlphanumeric(32);
private static final String BUNDLE_ID = "org.signal.test";
private Account destinationAccount;

View File

@ -128,7 +128,7 @@ class MessageSenderTest {
return MessageProtos.Envelope.newBuilder()
.setClientTimestamp(System.currentTimeMillis())
.setServerTimestamp(System.currentTimeMillis())
.setContent(ByteString.copyFromUtf8(RandomStringUtils.randomAlphanumeric(256)))
.setContent(ByteString.copyFromUtf8(RandomStringUtils.secure().nextAlphanumeric(256)))
.setType(MessageProtos.Envelope.Type.CIPHERTEXT)
.setServerGuid(UUID.randomUUID().toString())
.build();

View File

@ -55,7 +55,7 @@ class PushNotificationSchedulerTest {
private static final UUID ACCOUNT_UUID = UUID.randomUUID();
private static final String ACCOUNT_NUMBER = "+18005551234";
private static final byte DEVICE_ID = 1;
private static final String APN_ID = RandomStringUtils.randomAlphanumeric(32);
private static final String APN_ID = RandomStringUtils.secure().nextAlphanumeric(32);
@BeforeEach
void setUp() throws Exception {

View File

@ -122,8 +122,8 @@ class SecureStorageClientTest {
@Test
void deleteStoredData() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);
final String username = RandomStringUtils.secure().nextAlphabetic(16);
final String password = RandomStringUtils.secure().nextAlphanumeric(32);
when(credentialsGenerator.generateForUuid(accountUuid)).thenReturn(
new ExternalServiceCredentials(username, password));
@ -139,8 +139,8 @@ class SecureStorageClientTest {
@Test
void deleteStoredDataFailure() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);
final String username = RandomStringUtils.secure().nextAlphabetic(16);
final String password = RandomStringUtils.secure().nextAlphanumeric(32);
when(credentialsGenerator.generateForUuid(accountUuid)).thenReturn(
new ExternalServiceCredentials(username, password));

View File

@ -121,8 +121,8 @@ class SecureValueRecovery2ClientTest {
@Test
void deleteStoredData() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);
final String username = RandomStringUtils.secure().nextAlphabetic(16);
final String password = RandomStringUtils.secure().nextAlphanumeric(32);
when(credentialsGenerator.generateForUuid(accountUuid)).thenReturn(
new ExternalServiceCredentials(username, password));
@ -136,8 +136,8 @@ class SecureValueRecovery2ClientTest {
@Test
void deleteStoredDataFailure() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);
final String username = RandomStringUtils.secure().nextAlphabetic(16);
final String password = RandomStringUtils.secure().nextAlphanumeric(32);
when(credentialsGenerator.generateForUuid(accountUuid)).thenReturn(
new ExternalServiceCredentials(username, password));

View File

@ -23,7 +23,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
@ -182,12 +181,12 @@ public class AccountCreationDeletionIntegrationTest {
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
final String password = RandomStringUtils.randomAlphanumeric(16);
final String signalAgent = RandomStringUtils.randomAlphabetic(3);
final String password = RandomStringUtils.secure().nextAlphanumeric(16);
final String signalAgent = RandomStringUtils.secure().nextAlphabetic(3);
final int registrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final int pniRegistrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final byte[] deviceName = RandomStringUtils.randomAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.randomAlphanumeric(16);
final byte[] deviceName = RandomStringUtils.secure().nextAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.secure().nextAlphanumeric(16);
final Set<DeviceCapability> deviceCapabilities = Set.of();
@ -200,7 +199,7 @@ public class AccountCreationDeletionIntegrationTest {
deviceCapabilities);
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
RandomStringUtils.randomAlphabetic(8),
RandomStringUtils.secure().nextAlphabetic(8),
CLOCK.instant().plus(Duration.ofDays(7)),
true)));
@ -323,12 +322,12 @@ public class AccountCreationDeletionIntegrationTest {
existingAccountUuid = originalAccount.getUuid();
}
final String password = RandomStringUtils.randomAlphanumeric(16);
final String signalAgent = RandomStringUtils.randomAlphabetic(3);
final String password = RandomStringUtils.secure().nextAlphanumeric(16);
final String signalAgent = RandomStringUtils.secure().nextAlphabetic(3);
final int registrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final int pniRegistrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final byte[] deviceName = RandomStringUtils.randomAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.randomAlphanumeric(16);
final byte[] deviceName = RandomStringUtils.secure().nextAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.secure().nextAlphanumeric(16);
final Set<DeviceCapability> deviceCapabilities = Set.of();
@ -341,7 +340,7 @@ public class AccountCreationDeletionIntegrationTest {
deviceCapabilities);
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
RandomStringUtils.randomAlphabetic(8),
RandomStringUtils.secure().nextAlphabetic(8),
CLOCK.instant().plus(Duration.ofDays(7)),
true)));
@ -412,12 +411,12 @@ public class AccountCreationDeletionIntegrationTest {
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
final String password = RandomStringUtils.randomAlphanumeric(16);
final String signalAgent = RandomStringUtils.randomAlphabetic(3);
final String password = RandomStringUtils.secure().nextAlphanumeric(16);
final String signalAgent = RandomStringUtils.secure().nextAlphabetic(3);
final int registrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final int pniRegistrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
final byte[] deviceName = RandomStringUtils.randomAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.randomAlphanumeric(16);
final byte[] deviceName = RandomStringUtils.secure().nextAlphabetic(16).getBytes(StandardCharsets.UTF_8);
final String registrationLockSecret = RandomStringUtils.secure().nextAlphanumeric(16);
final Set<DeviceCapability> deviceCapabilities = Set.of();
@ -430,7 +429,7 @@ public class AccountCreationDeletionIntegrationTest {
deviceCapabilities);
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
RandomStringUtils.randomAlphabetic(8),
RandomStringUtils.secure().nextAlphabetic(8),
CLOCK.instant().plus(Duration.ofDays(7)),
true)));

View File

@ -151,7 +151,7 @@ public class AccountsManagerDeviceTransferIntegrationTest {
@Test
void waitForRestoreAccountRequest() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
final RestoreAccountRequest restoreAccountRequest =
new RestoreAccountRequest(RestoreAccountRequest.Method.DEVICE_TRANSFER);
@ -170,7 +170,7 @@ public class AccountsManagerDeviceTransferIntegrationTest {
@Test
void waitForRestoreAccountRequestAlreadyRequested() {
final String token = RandomStringUtils.randomAlphanumeric(16);
final String token = RandomStringUtils.secure().nextAlphanumeric(16);
final RestoreAccountRequest restoreAccountRequest =
new RestoreAccountRequest(RestoreAccountRequest.Method.DEVICE_TRANSFER);
@ -183,6 +183,7 @@ public class AccountsManagerDeviceTransferIntegrationTest {
@Test
void waitForRestoreAccountRequestTimeout() {
assertEquals(Optional.empty(),
accountsManager.waitForRestoreAccountRequest(RandomStringUtils.randomAlphanumeric(16), Duration.ofMillis(1)).join());
accountsManager.waitForRestoreAccountRequest(RandomStringUtils.secure().nextAlphanumeric(16),
Duration.ofMillis(1)).join());
}
}

View File

@ -197,7 +197,7 @@ class MessagePersisterIntegrationTest {
return MessageProtos.Envelope.newBuilder()
.setClientTimestamp(serverTimestamp * 2) // client timestamp may not be accurate
.setServerTimestamp(serverTimestamp)
.setContent(ByteString.copyFromUtf8(RandomStringUtils.randomAlphanumeric(256)))
.setContent(ByteString.copyFromUtf8(RandomStringUtils.secure().nextAlphanumeric(256)))
.setType(MessageProtos.Envelope.Type.CIPHERTEXT)
.setServerGuid(messageGuid.toString())
.setDestinationServiceId(UUID.randomUUID().toString())

View File

@ -353,7 +353,7 @@ class MessagePersisterTest {
.setDestinationServiceId(accountUuid.toString())
.setClientTimestamp(firstMessageTimestamp.toEpochMilli() + i)
.setServerTimestamp(firstMessageTimestamp.toEpochMilli() + i)
.setContent(ByteString.copyFromUtf8(RandomStringUtils.randomAlphanumeric(256)))
.setContent(ByteString.copyFromUtf8(RandomStringUtils.secure().nextAlphanumeric(256)))
.setType(MessageProtos.Envelope.Type.CIPHERTEXT)
.setServerGuid(messageGuid.toString())
.build();

View File

@ -827,7 +827,7 @@ class MessagesCacheTest {
final MessageProtos.Envelope.Builder envelopeBuilder = MessageProtos.Envelope.newBuilder()
.setClientTimestamp(timestamp)
.setServerTimestamp(timestamp)
.setContent(ByteString.copyFromUtf8(RandomStringUtils.randomAlphanumeric(256)))
.setContent(ByteString.copyFromUtf8(RandomStringUtils.secure().nextAlphanumeric(256)))
.setType(MessageProtos.Envelope.Type.CIPHERTEXT)
.setServerGuid(messageGuid.toString())
.setDestinationServiceId(destinationServiceId.toServiceIdentifierString());

View File

@ -389,7 +389,7 @@ class WebSocketConnectionIntegrationTest {
return MessageProtos.Envelope.newBuilder()
.setClientTimestamp(timestamp)
.setServerTimestamp(timestamp)
.setContent(ByteString.copyFromUtf8(RandomStringUtils.randomAlphanumeric(256)))
.setContent(ByteString.copyFromUtf8(RandomStringUtils.secure().nextAlphanumeric(256)))
.setType(MessageProtos.Envelope.Type.CIPHERTEXT)
.setServerGuid(messageGuid.toString())
.setDestinationServiceId(UUID.randomUUID().toString())