Check max device limit inside lock scope

This commit is contained in:
Chris Eager authored and ravi-signal committed 2026-10-07 14:45:53 -05:00
1 parent 12d7157a4e
commit b2c638a635
7 files changed
+156 -58

No files matched your search

@@ -72,6 +72,7 @@ import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.DeviceCapability;
import org.whispersystems.textsecuregcm.storage.DeviceIdentityInfo;
import org.whispersystems.textsecuregcm.storage.DeviceLimitExceededException;
import org.whispersystems.textsecuregcm.storage.DeviceSpec;
import org.whispersystems.textsecuregcm.storage.LinkDeviceTokenAlreadyUsedException;
import org.whispersystems.textsecuregcm.storage.PersistentTimer;
@@ -88,8 +89,6 @@ import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
@Tag(name = "Devices")
public class DeviceController {
static final int MAX_DEVICES = 6;
private final AccountsManager accounts;
private final RateLimiters rateLimiters;
private final PersistentTimer persistentTimer;
@@ -198,15 +197,11 @@ public class DeviceController {
rateLimiters.getAllocateDeviceLimiter().validate(account.getAccountIdentifier());
if (account.getDevices().size() >= MAX_DEVICES) {
throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES);
}
if (auth.deviceId() != Device.PRIMARY_ID) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
final String token = accounts.generateLinkDeviceToken(account.getAccountIdentifier());
final String token = accounts.generateLinkDeviceToken(account);
return new LinkDeviceToken(token, AccountsManager.getLinkDeviceTokenIdentifier(token));
}
@@ -271,10 +266,6 @@ public class DeviceController {
throw new WebApplicationException(Response.status(422).build());
}
if (account.getDevices().size() >= MAX_DEVICES) {
throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES);
}
final Set<DeviceCapability> capabilities = deviceAttributes.capabilities();
if (capabilities == null) {
@@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.whispersystems.textsecuregcm.controllers.DeviceLimitExceededException;
import org.whispersystems.textsecuregcm.storage.DeviceLimitExceededException;
@Provider
public class DeviceLimitExceededExceptionMapper implements ExceptionMapper<DeviceLimitExceededException> {
@@ -197,6 +197,8 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
private static final int MAX_UPDATE_ATTEMPTS = 10;
public static final int MAX_DEVICES = 6;
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
private static final int AUTH_CREDENTIAL_SALT_SIZE = 16;
@@ -683,20 +685,31 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
}
public Pair<Account, Device> addDevice(final UUID accountIdentifier, final DeviceSpec deviceSpec, final String linkDeviceToken)
throws LinkDeviceTokenAlreadyUsedException {
throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Account account = accounts.getByAccountIdentifier(accountIdentifier)
.orElseThrow(() -> new IllegalArgumentException("Account not found: " + accountIdentifier));
return accountLockManager.withSingleAccountLock(account,
() -> addDevice(accountIdentifier, deviceSpec, linkDeviceToken, MAX_UPDATE_ATTEMPTS));
try {
return accountLockManager.withSingleAccountLock(account,
() -> addDevice(accountIdentifier, deviceSpec, linkDeviceToken, MAX_UPDATE_ATTEMPTS));
} catch (final LinkDeviceTokenAlreadyUsedException | DeviceLimitExceededException | RuntimeException e) {
throw e;
} catch (final Exception e) {
throw new AssertionError("Unexpected exception adding device", e);
}
}
private Pair<Account, Device> addDevice(final UUID accountIdentifier, final DeviceSpec deviceSpec, final String linkDeviceToken, final int retries)
throws LinkDeviceTokenAlreadyUsedException {
throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Account account = accounts.getByAccountIdentifier(accountIdentifier)
.orElseThrow(ContestedOptimisticLockException::new);
if (account.getDevices().size() >= MAX_DEVICES) {
throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES);
}
final byte nextDeviceId = account.getNextDeviceId();
CompletableFuture
@@ -789,8 +802,13 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
}
}
public String generateLinkDeviceToken(final UUID aci) {
final String claims = aci + "." + clock.instant().toEpochMilli();
public String generateLinkDeviceToken(final Account account) throws DeviceLimitExceededException {
if (account.getDevices().size() >= MAX_DEVICES) {
throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES);
}
final String claims = account.getAccountIdentifier() + "." + clock.instant().toEpochMilli();
final byte[] signature = getInitializedMac().doFinal(claims.getBytes(StandardCharsets.UTF_8));
return claims + ":" + Base64.getUrlEncoder().encodeToString(signature);
@@ -1,9 +1,9 @@
/*
* Copyright 2013-2020 Signal Messenger, LLC
* Copyright 2013 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.controllers;
package org.whispersystems.textsecuregcm.storage;
public class DeviceLimitExceededException extends Exception {
@@ -13,7 +13,7 @@ public class DeviceLimitExceededException extends Exception {
public DeviceLimitExceededException(int currentDevices, int maxDevices) {
this.currentDevices = currentDevices;
this.maxDevices = maxDevices;
this.maxDevices = maxDevices;
}
public int getCurrentDevices() {
@@ -34,11 +34,11 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils;
import org.glassfish.jersey.server.ServerProperties;
@@ -80,6 +80,7 @@ import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.DeviceCapability;
import org.whispersystems.textsecuregcm.storage.DeviceLimitExceededException;
import org.whispersystems.textsecuregcm.storage.DeviceSpec;
import org.whispersystems.textsecuregcm.storage.LinkDeviceTokenAlreadyUsedException;
import org.whispersystems.textsecuregcm.storage.PersistentTimer;
@@ -216,7 +217,7 @@ class DeviceControllerTest {
final Optional<ApnRegistrationId> apnRegistrationId,
final Optional<GcmRegistrationId> gcmRegistrationId,
final Optional<String> expectedApnsToken,
final Optional<String> expectedGcmToken) throws LinkDeviceTokenAlreadyUsedException {
final Optional<String> expectedGcmToken) throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Device existingDevice = mock(Device.class);
when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID);
@@ -304,7 +305,7 @@ class DeviceControllerTest {
void deviceDowngrade(@CartesianTest.Enum(mode = CartesianTest.Enum.Mode.EXCLUDE, names = "SPARSE_POST_QUANTUM_RATCHET") final DeviceCapability capability,
@CartesianTest.Values(booleans = {true, false}) final boolean accountHasCapability,
@CartesianTest.Values(booleans = {true, false}) final boolean requestHasCapability)
throws LinkDeviceTokenAlreadyUsedException {
throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
when(accountsManager.addDevice(any(), any(), any()))
@@ -360,7 +361,7 @@ class DeviceControllerTest {
}
@Test
void missingRequiredCapability() throws LinkDeviceTokenAlreadyUsedException {
void missingRequiredCapability() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
when(accountsManager.addDevice(any(), any(), any()))
@@ -447,7 +448,7 @@ class DeviceControllerTest {
}
@Test
void linkDeviceAtomicReusedToken() throws LinkDeviceTokenAlreadyUsedException {
void linkDeviceAtomicReusedToken() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Device existingDevice = mock(Device.class);
when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID);
when(account.getDevices()).thenReturn(List.of(existingDevice));
@@ -492,6 +493,47 @@ class DeviceControllerTest {
}
}
@Test
void linkDeviceMaxDevices() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Device existingDevice = mock(Device.class);
when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID);
when(account.getDevices()).thenReturn(List.of(existingDevice));
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciIdentityKeyPair);
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciIdentityKeyPair);
when(account.getAccountIdentityKey()).thenReturn(new IdentityKey(aciIdentityKeyPair.getPublicKey()));
when(account.getPhoneNumberIdentityKey()).thenReturn(Optional.empty());
when(accountsManager.checkDeviceLinkingToken(anyString())).thenReturn(Optional.of(AuthHelper.VALID_UUID));
when(accountsManager.addDevice(any(), any(), any()))
.thenThrow(new DeviceLimitExceededException(AccountsManager.MAX_DEVICES, AccountsManager.MAX_DEVICES));
final DeviceAttributes deviceAttributes = new DeviceAttributes(true, 1234, null, null,
DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES);
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
deviceAttributes,
new DeviceActivationRequest(aciSignedPreKey, Optional.empty(), aciPqLastResortPreKey, Optional.empty(), Optional.empty(), Optional.empty()));
try (final Response response = resources.getJerseyTest()
.target("/v1/devices/link")
.request()
.header("Authorization", AuthHelper.getProvisioningAuthHeader(AuthHelper.VALID_NUMBER, "password1"))
.put(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE))) {
assertEquals(411, response.getStatus());
final Map<?, ?> details = response.readEntity(Map.class);
assertEquals(Map.of("current", AccountsManager.MAX_DEVICES, "max", AccountsManager.MAX_DEVICES), details);
}
verify(accountsManager).addDevice(eq(AuthHelper.VALID_UUID), any(), eq("link-device-token"));
}
@Test
void linkDeviceAtomicWithVerificationTokenUsed() {
@@ -538,7 +580,7 @@ class DeviceControllerTest {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
void linkDeviceAtomicConflictingChannel(final boolean fetchesMessages,
final Optional<ApnRegistrationId> apnRegistrationId,
final Optional<GcmRegistrationId> gcmRegistrationId) {
final Optional<GcmRegistrationId> gcmRegistrationId) throws Exception {
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
when(accountsManager.generateLinkDeviceToken(any())).thenReturn("test");
@@ -849,7 +891,7 @@ class DeviceControllerTest {
@ParameterizedTest
@MethodSource
void linkDeviceRegistrationId(final int registrationId, final int pniRegistrationId, final int expectedStatusCode)
throws LinkDeviceTokenAlreadyUsedException {
throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final Device existingDevice = mock(Device.class);
when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID);
when(account.getDevices()).thenReturn(List.of(existingDevice));
@@ -955,12 +997,9 @@ class DeviceControllerTest {
}
@Test
void maxDevicesTest() throws LinkDeviceTokenAlreadyUsedException {
final List<Device> devices = IntStream.range(0, DeviceController.MAX_DEVICES + 1)
.mapToObj(_ -> mock(Device.class))
.toList();
void generateTokenMaxDevicesTest() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
when(account.getDevices()).thenReturn(devices);
when(accountsManager.generateLinkDeviceToken(any())).thenThrow(new DeviceLimitExceededException(5, 5));
Response response = resources.getJerseyTest()
.target("/v1/devices/provisioning/code")
@@ -1223,7 +1223,7 @@ class AccountsManagerTest {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testAddDevice(boolean accountHasPhoneNumber) throws LinkDeviceTokenAlreadyUsedException {
void testAddDevice(boolean accountHasPhoneNumber) throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String phoneNumber =
PhoneNumberUtil.getInstance().format(PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -1269,7 +1269,7 @@ class AccountsManagerTest {
true,
Optional.empty(),
Optional.empty()),
accountsManager.generateLinkDeviceToken(aci));
accountsManager.generateLinkDeviceToken(account));
verify(keysManager).deleteSingleUsePreKeys(aci, nextDeviceId);
maybePni.ifPresent(pni -> verify(keysManager).deleteSingleUsePreKeys(pni, nextDeviceId));
@@ -1298,6 +1298,55 @@ class AccountsManagerTest {
assertNull(device.getGcmId());
}
@Test
void testAddDeviceExceedsMaxDevices() {
final List<Device> devices = IntStream.range(0, AccountsManager.MAX_DEVICES - 1)
.mapToObj(i -> {
final Device device = generateTestDevice(CLOCK.millis());
device.setId((byte) (Device.PRIMARY_ID + i));
return device;
})
.toList();
final Account account = AccountsHelper.generateTestAccount("+14152222222", devices);
final UUID aci = account.getAccountIdentifier();
account.setIdentityKey(new IdentityKey(ECKeyPair.generate().getPublicKey()));
final String linkDeviceToken = assertDoesNotThrow(() -> accountsManager.generateLinkDeviceToken(account),
"the account should still have a free device slot");
// Simulate a concurrent link request
final Device concurrentlyLinkedDevice = generateTestDevice(CLOCK.millis());
concurrentlyLinkedDevice.setId(account.getNextDeviceId());
account.addDevice(concurrentlyLinkedDevice);
when(accounts.getByAccountIdentifier(aci)).thenReturn(Optional.of(account));
final ECKeyPair aciKeyPair = ECKeyPair.generate();
final ECKeyPair pniKeyPair = ECKeyPair.generate();
final DeviceLimitExceededException exception = assertThrows(DeviceLimitExceededException.class,
() -> accountsManager.addDevice(aci,
new DeviceSpec(
"device-name".getBytes(StandardCharsets.UTF_8),
"password",
"OWT",
Set.of(),
new DeviceIdentityInfo(17, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
Optional.of(new DeviceIdentityInfo(19, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
true,
Optional.empty(),
Optional.empty()),
linkDeviceToken));
assertEquals(AccountsManager.MAX_DEVICES, exception.getCurrentDevices());
assertEquals(AccountsManager.MAX_DEVICES, exception.getMaxDevices());
verify(accounts, never()).updateTransactionally(any(), any());
verifyNoInteractions(keysManager);
verifyNoInteractions(messagesManager);
}
@ParameterizedTest
@MethodSource
void testUpdateDeviceLastSeen(final boolean expectUpdate, final long initialLastSeen, final long updatedLastSeen) {
@@ -1765,11 +1814,12 @@ class AccountsManagerTest {
}
@Test
void checkDeviceLinkingToken() {
final UUID aci = UUID.randomUUID();
void checkDeviceLinkingToken() throws Exception {
final Account account = createAccount(new AccountAttributes(false, 1, 2, null, null, false, null,
TestRandomUtil.nextBytes(16)));
assertEquals(Optional.of(aci),
accountsManager.checkDeviceLinkingToken(accountsManager.generateLinkDeviceToken(aci)));
assertEquals(Optional.of(account.getAccountIdentifier()),
accountsManager.checkDeviceLinkingToken(accountsManager.generateLinkDeviceToken(account)));
}
@ParameterizedTest
@@ -163,12 +163,12 @@ public class AddRemoveDeviceIntegrationTest {
}
@AfterEach
void tearDown() throws InterruptedException {
void tearDown() {
accountsManager.stop();
}
@Test
void addDevice() throws LinkDeviceTokenAlreadyUsedException {
void addDevice() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -190,7 +190,7 @@ public class AddRemoveDeviceIntegrationTest {
true,
Optional.empty(),
Optional.empty()),
accountsManager.generateLinkDeviceToken(account.getAccountIdentifier()));
accountsManager.generateLinkDeviceToken(account));
assertEquals(2, updatedAccountAndDevice.first().getDevices().size());
@@ -212,7 +212,7 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void addDeviceReusedToken() throws LinkDeviceTokenAlreadyUsedException {
void addDeviceReusedToken() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -223,7 +223,7 @@ public class AddRemoveDeviceIntegrationTest {
final Account account = AccountsHelper.createAccount(accountsManager, number);
assertEquals(1, accountsManager.getByAccountIdentifier(account.getAccountIdentifier()).orElseThrow().getDevices().size());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account.getAccountIdentifier());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final Pair<Account, Device> updatedAccountAndDevice =
accountsManager.addDevice(account.getAccountIdentifier(), new DeviceSpec(
@@ -261,7 +261,7 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void removeDevice() throws LinkDeviceTokenAlreadyUsedException {
void removeDevice()throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -283,7 +283,7 @@ public class AddRemoveDeviceIntegrationTest {
true,
Optional.empty(),
Optional.empty()),
accountsManager.generateLinkDeviceToken(account.getAccountIdentifier()));
accountsManager.generateLinkDeviceToken(account));
final byte addedDeviceId = updatedAccountAndDevice.second().getId();
@@ -306,7 +306,7 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void removeDevicePartialFailure() throws LinkDeviceTokenAlreadyUsedException {
void removeDevicePartialFailure() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -330,7 +330,7 @@ public class AddRemoveDeviceIntegrationTest {
true,
Optional.empty(),
Optional.empty()),
accountsManager.generateLinkDeviceToken(account.getAccountIdentifier()));
accountsManager.generateLinkDeviceToken(account));
final byte addedDeviceId = updatedAccountAndDevice.second().getId();
@@ -360,7 +360,7 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void waitForNewLinkedDevice() throws LinkDeviceTokenAlreadyUsedException {
void waitForNewLinkedDevice() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -370,7 +370,7 @@ public class AddRemoveDeviceIntegrationTest {
final Account account = AccountsHelper.createAccount(accountsManager, number);
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account.getAccountIdentifier());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final String linkDeviceTokenIdentifier = AccountsManager.getLinkDeviceTokenIdentifier(linkDeviceToken);
final CompletableFuture<Optional<DeviceInfo>> displacedFuture = accountsManager.waitForNewLinkedDevice(
@@ -409,7 +409,7 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void waitForNewLinkedDeviceAlreadyAdded() throws LinkDeviceTokenAlreadyUsedException {
void waitForNewLinkedDeviceAlreadyAdded() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -419,7 +419,7 @@ public class AddRemoveDeviceIntegrationTest {
final Account account = AccountsHelper.createAccount(accountsManager, number);
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account.getAccountIdentifier());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final String linkDeviceTokenIdentifier = AccountsManager.getLinkDeviceTokenIdentifier(linkDeviceToken);
final Pair<Account, Device> updatedAccountAndDevice =
@@ -452,13 +452,13 @@ public class AddRemoveDeviceIntegrationTest {
}
@Test
void waitForNewLinkedDeviceTimeout() {
void waitForNewLinkedDeviceTimeout() throws Exception {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
final Account account = AccountsHelper.createAccount(accountsManager, number);
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(UUID.randomUUID());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final String linkDeviceTokenIdentifier = AccountsManager.getLinkDeviceTokenIdentifier(linkDeviceToken);
final CompletableFuture<Optional<DeviceInfo>> linkedDeviceFuture = accountsManager.waitForNewLinkedDevice(
@@ -477,7 +477,7 @@ public class AddRemoveDeviceIntegrationTest {
"10_000,10_001,false", // pending message after now
})
void waitForMessageFetch(long currentTime, Long oldestMessage, boolean shouldWait)
throws LinkDeviceTokenAlreadyUsedException {
throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -485,7 +485,7 @@ public class AddRemoveDeviceIntegrationTest {
final ECKeyPair pniKeyPair = ECKeyPair.generate();
final Account account = AccountsHelper.createAccount(accountsManager, number);
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(UUID.randomUUID());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final String linkDeviceTokenIdentifier = AccountsManager.getLinkDeviceTokenIdentifier(linkDeviceToken);
accountsManager.addDevice(account.getAccountIdentifier(), new DeviceSpec(
@@ -514,7 +514,7 @@ public class AddRemoveDeviceIntegrationTest {
// preempted by the timeout check
@Timeout(value = 10, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
@Test
void waitForMessageFetchRetries() throws LinkDeviceTokenAlreadyUsedException {
void waitForMessageFetchRetries() throws LinkDeviceTokenAlreadyUsedException, DeviceLimitExceededException {
final String number = PhoneNumberUtil.getInstance().format(
PhoneNumberUtil.getInstance().getExampleNumber("US"),
PhoneNumberUtil.PhoneNumberFormat.E164);
@@ -522,7 +522,7 @@ public class AddRemoveDeviceIntegrationTest {
final ECKeyPair pniKeyPair = ECKeyPair.generate();
final Account account = AccountsHelper.createAccount(accountsManager, number);
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(UUID.randomUUID());
final String linkDeviceToken = accountsManager.generateLinkDeviceToken(account);
final String linkDeviceTokenIdentifier = AccountsManager.getLinkDeviceTokenIdentifier(linkDeviceToken);
clock.pin(Instant.ofEpochMilli(0));