mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-24 07:08:06 +01:00
Add basic support for phone number identifiers
This commit is contained in:
@@ -224,14 +224,14 @@ class AccountControllerTest {
|
||||
when(pendingAccountsManager.getCodeForNumber(SENDER_HAS_STORAGE)).thenReturn(Optional.of(new StoredVerificationCode("666666", System.currentTimeMillis(), null, null)));
|
||||
when(pendingAccountsManager.getCodeForNumber(SENDER_TRANSFER)).thenReturn(Optional.of(new StoredVerificationCode("1234", System.currentTimeMillis(), null, null)));
|
||||
|
||||
when(accountsManager.get(eq(SENDER_PIN))).thenReturn(Optional.of(senderPinAccount));
|
||||
when(accountsManager.get(eq(SENDER_REG_LOCK))).thenReturn(Optional.of(senderRegLockAccount));
|
||||
when(accountsManager.get(eq(SENDER_OVER_PIN))).thenReturn(Optional.of(senderPinAccount));
|
||||
when(accountsManager.get(eq(SENDER))).thenReturn(Optional.empty());
|
||||
when(accountsManager.get(eq(SENDER_OLD))).thenReturn(Optional.empty());
|
||||
when(accountsManager.get(eq(SENDER_PREAUTH))).thenReturn(Optional.empty());
|
||||
when(accountsManager.get(eq(SENDER_HAS_STORAGE))).thenReturn(Optional.of(senderHasStorage));
|
||||
when(accountsManager.get(eq(SENDER_TRANSFER))).thenReturn(Optional.of(senderTransfer));
|
||||
when(accountsManager.getByE164(eq(SENDER_PIN))).thenReturn(Optional.of(senderPinAccount));
|
||||
when(accountsManager.getByE164(eq(SENDER_REG_LOCK))).thenReturn(Optional.of(senderRegLockAccount));
|
||||
when(accountsManager.getByE164(eq(SENDER_OVER_PIN))).thenReturn(Optional.of(senderPinAccount));
|
||||
when(accountsManager.getByE164(eq(SENDER))).thenReturn(Optional.empty());
|
||||
when(accountsManager.getByE164(eq(SENDER_OLD))).thenReturn(Optional.empty());
|
||||
when(accountsManager.getByE164(eq(SENDER_PREAUTH))).thenReturn(Optional.empty());
|
||||
when(accountsManager.getByE164(eq(SENDER_HAS_STORAGE))).thenReturn(Optional.of(senderHasStorage));
|
||||
when(accountsManager.getByE164(eq(SENDER_TRANSFER))).thenReturn(Optional.of(senderTransfer));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any())).thenAnswer((Answer<Account>) invocation -> {
|
||||
final Account account = mock(Account.class);
|
||||
@@ -1338,7 +1338,7 @@ class AccountControllerTest {
|
||||
when(existingAccount.getUuid()).thenReturn(UUID.randomUUID());
|
||||
when(existingAccount.getRegistrationLock()).thenReturn(existingRegistrationLock);
|
||||
|
||||
when(accountsManager.get(number)).thenReturn(Optional.of(existingAccount));
|
||||
when(accountsManager.getByE164(number)).thenReturn(Optional.of(existingAccount));
|
||||
|
||||
final Response response =
|
||||
resources.getJerseyTest()
|
||||
@@ -1368,7 +1368,7 @@ class AccountControllerTest {
|
||||
when(existingAccount.getUuid()).thenReturn(UUID.randomUUID());
|
||||
when(existingAccount.getRegistrationLock()).thenReturn(existingRegistrationLock);
|
||||
|
||||
when(accountsManager.get(number)).thenReturn(Optional.of(existingAccount));
|
||||
when(accountsManager.getByE164(number)).thenReturn(Optional.of(existingAccount));
|
||||
|
||||
final Response response =
|
||||
resources.getJerseyTest()
|
||||
@@ -1400,7 +1400,7 @@ class AccountControllerTest {
|
||||
when(existingAccount.getUuid()).thenReturn(UUID.randomUUID());
|
||||
when(existingAccount.getRegistrationLock()).thenReturn(existingRegistrationLock);
|
||||
|
||||
when(accountsManager.get(number)).thenReturn(Optional.of(existingAccount));
|
||||
when(accountsManager.getByE164(number)).thenReturn(Optional.of(existingAccount));
|
||||
|
||||
final Response response =
|
||||
resources.getJerseyTest()
|
||||
@@ -1432,7 +1432,7 @@ class AccountControllerTest {
|
||||
when(existingAccount.getUuid()).thenReturn(UUID.randomUUID());
|
||||
when(existingAccount.getRegistrationLock()).thenReturn(existingRegistrationLock);
|
||||
|
||||
when(accountsManager.get(number)).thenReturn(Optional.of(existingAccount));
|
||||
when(accountsManager.getByE164(number)).thenReturn(Optional.of(existingAccount));
|
||||
|
||||
final Response response =
|
||||
resources.getJerseyTest()
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.whispersystems.textsecuregcm.tests.controllers;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -132,8 +131,8 @@ class DeviceControllerTest {
|
||||
when(pendingDevicesManager.getCodeForNumber(AuthHelper.VALID_NUMBER)).thenReturn(
|
||||
Optional.of(new StoredVerificationCode("5678901", System.currentTimeMillis(), null, null)));
|
||||
when(pendingDevicesManager.getCodeForNumber(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.empty());
|
||||
when(accountsManager.get(AuthHelper.VALID_NUMBER)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.get(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.of(maxedAccount));
|
||||
when(accountsManager.getByE164(AuthHelper.VALID_NUMBER)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.getByE164(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.of(maxedAccount));
|
||||
|
||||
AccountsHelper.setupMockUpdate(accountsManager);
|
||||
}
|
||||
@@ -156,7 +155,7 @@ class DeviceControllerTest {
|
||||
|
||||
@Test
|
||||
void validDeviceRegisterTest() {
|
||||
when(accountsManager.get(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT));
|
||||
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT));
|
||||
|
||||
final Device existingDevice = mock(Device.class);
|
||||
when(existingDevice.getId()).thenReturn(Device.MASTER_ID);
|
||||
|
||||
@@ -210,7 +210,7 @@ class DonationControllerTest {
|
||||
when(receiptCredentialPresentation.getReceiptExpirationTime()).thenReturn(receiptExpiration);
|
||||
when(redeemedReceiptsManager.put(same(receiptSerial), eq(receiptExpiration), eq(receiptLevel), eq(AuthHelper.VALID_UUID))).thenReturn(
|
||||
CompletableFuture.completedFuture(Boolean.TRUE));
|
||||
when(accountsManager.get(eq(AuthHelper.VALID_UUID))).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT));
|
||||
when(accountsManager.getByAccountIdentifier(eq(AuthHelper.VALID_UUID))).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT));
|
||||
|
||||
RedeemReceiptRequest request = new RedeemReceiptRequest(presentation, true, true);
|
||||
Response response = resources.getJerseyTest()
|
||||
|
||||
@@ -153,11 +153,11 @@ class KeysControllerTest {
|
||||
when(existsAccount.getNumber()).thenReturn(EXISTS_NUMBER);
|
||||
when(existsAccount.getUnidentifiedAccessKey()).thenReturn(Optional.of("1337".getBytes()));
|
||||
|
||||
when(accounts.get(EXISTS_NUMBER)).thenReturn(Optional.of(existsAccount));
|
||||
when(accounts.get(EXISTS_UUID)).thenReturn(Optional.of(existsAccount));
|
||||
when(accounts.getByE164(EXISTS_NUMBER)).thenReturn(Optional.of(existsAccount));
|
||||
when(accounts.getByAccountIdentifier(EXISTS_UUID)).thenReturn(Optional.of(existsAccount));
|
||||
|
||||
when(accounts.get(NOT_EXISTS_NUMBER)).thenReturn(Optional.empty());
|
||||
when(accounts.get(NOT_EXISTS_UUID)).thenReturn(Optional.empty());
|
||||
when(accounts.getByE164(NOT_EXISTS_NUMBER)).thenReturn(Optional.empty());
|
||||
when(accounts.getByAccountIdentifier(NOT_EXISTS_UUID)).thenReturn(Optional.empty());
|
||||
|
||||
when(rateLimiters.getPreKeysLimiter()).thenReturn(rateLimiter);
|
||||
|
||||
|
||||
@@ -160,13 +160,15 @@ class MessageControllerTest {
|
||||
false, false, false)));
|
||||
}};
|
||||
|
||||
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, SINGLE_DEVICE_UUID, singleDeviceList, "1234".getBytes());
|
||||
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, MULTI_DEVICE_UUID, multiDeviceList, "1234".getBytes());
|
||||
internationalAccount = new Account(INTERNATIONAL_RECIPIENT, INTERNATIONAL_UUID, singleDeviceList, "1234".getBytes());
|
||||
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, SINGLE_DEVICE_UUID, UUID.randomUUID(),
|
||||
singleDeviceList, "1234".getBytes());
|
||||
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, MULTI_DEVICE_UUID, UUID.randomUUID(),
|
||||
multiDeviceList, "1234".getBytes());
|
||||
internationalAccount = new Account(INTERNATIONAL_RECIPIENT, INTERNATIONAL_UUID, UUID.randomUUID(), singleDeviceList, "1234".getBytes());
|
||||
|
||||
when(accountsManager.get(eq(SINGLE_DEVICE_UUID))).thenReturn(Optional.of(singleDeviceAccount));
|
||||
when(accountsManager.get(eq(MULTI_DEVICE_UUID))).thenReturn(Optional.of(multiDeviceAccount));
|
||||
when(accountsManager.get(INTERNATIONAL_UUID)).thenReturn(Optional.of(internationalAccount));
|
||||
when(accountsManager.getByAccountIdentifier(eq(SINGLE_DEVICE_UUID))).thenReturn(Optional.of(singleDeviceAccount));
|
||||
when(accountsManager.getByAccountIdentifier(eq(MULTI_DEVICE_UUID))).thenReturn(Optional.of(multiDeviceAccount));
|
||||
when(accountsManager.getByAccountIdentifier(INTERNATIONAL_UUID)).thenReturn(Optional.of(internationalAccount));
|
||||
|
||||
when(rateLimiters.getMessagesLimiter()).thenReturn(rateLimiter);
|
||||
}
|
||||
|
||||
@@ -169,13 +169,13 @@ class ProfileControllerTest {
|
||||
when(capabilitiesAccount.isAnnouncementGroupSupported()).thenReturn(true);
|
||||
when(capabilitiesAccount.isChangeNumberSupported()).thenReturn(true);
|
||||
|
||||
when(accountsManager.get(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.of(profileAccount));
|
||||
when(accountsManager.get(AuthHelper.VALID_UUID_TWO)).thenReturn(Optional.of(profileAccount));
|
||||
when(accountsManager.getByE164(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.of(profileAccount));
|
||||
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID_TWO)).thenReturn(Optional.of(profileAccount));
|
||||
when(usernamesManager.get(AuthHelper.VALID_UUID_TWO)).thenReturn(Optional.of("n00bkiller"));
|
||||
when(usernamesManager.get("n00bkiller")).thenReturn(Optional.of(AuthHelper.VALID_UUID_TWO));
|
||||
|
||||
when(accountsManager.get(AuthHelper.VALID_NUMBER)).thenReturn(Optional.of(capabilitiesAccount));
|
||||
when(accountsManager.get(AuthHelper.VALID_UUID)).thenReturn(Optional.of(capabilitiesAccount));
|
||||
when(accountsManager.getByE164(AuthHelper.VALID_NUMBER)).thenReturn(Optional.of(capabilitiesAccount));
|
||||
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(capabilitiesAccount));
|
||||
|
||||
when(profilesManager.get(eq(AuthHelper.VALID_UUID), eq("someversion"))).thenReturn(Optional.empty());
|
||||
when(profilesManager.get(eq(AuthHelper.VALID_UUID_TWO), eq("validversion"))).thenReturn(Optional.of(new VersionedProfile(
|
||||
@@ -208,7 +208,7 @@ class ProfileControllerTest {
|
||||
assertThat(profile.getBadges()).hasSize(1).element(0).has(new Condition<>(
|
||||
badge -> "Test Badge".equals(badge.getName()), "has badge with expected name"));
|
||||
|
||||
verify(accountsManager).get(AuthHelper.VALID_UUID_TWO);
|
||||
verify(accountsManager).getByAccountIdentifier(AuthHelper.VALID_UUID_TWO);
|
||||
verify(usernamesManager, times(1)).get(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(rateLimiter, times(1)).validate(AuthHelper.VALID_UUID);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class ProfileControllerTest {
|
||||
assertThat(profile.getBadges()).hasSize(1).element(0).has(new Condition<>(
|
||||
badge -> "Test Badge".equals(badge.getName()), "has badge with expected name"));
|
||||
|
||||
verify(accountsManager, times(1)).get(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(usernamesManager, times(1)).get(eq("n00bkiller"));
|
||||
verify(usernameRateLimiter, times(1)).validate(eq(AuthHelper.VALID_UUID));
|
||||
}
|
||||
@@ -591,7 +591,7 @@ class ProfileControllerTest {
|
||||
assertThat(profile.getBadges()).hasSize(1).element(0).has(new Condition<>(
|
||||
badge -> "Test Badge".equals(badge.getName()), "has badge with expected name"));
|
||||
|
||||
verify(accountsManager, times(1)).get(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(usernamesManager, times(1)).get(eq(AuthHelper.VALID_UUID_TWO));
|
||||
verify(profilesManager, times(1)).get(eq(AuthHelper.VALID_UUID_TWO), eq("validversion"));
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class APNSenderTest {
|
||||
public void setup() {
|
||||
when(destinationAccount.getDevice(1)).thenReturn(Optional.of(destinationDevice));
|
||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||
when(accountsManager.get(DESTINATION_UUID)).thenReturn(Optional.of(destinationAccount));
|
||||
when(accountsManager.getByAccountIdentifier(DESTINATION_UUID)).thenReturn(Optional.of(destinationAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +158,7 @@ public class APNSenderTest {
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
verify(accountsManager, times(1)).get(eq(DESTINATION_UUID));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(DESTINATION_UUID));
|
||||
verify(destinationAccount, times(1)).getDevice(1);
|
||||
verify(destinationDevice, times(1)).getApnId();
|
||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
@@ -261,7 +261,7 @@ public class APNSenderTest {
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
verify(accountsManager, times(1)).get(eq(DESTINATION_UUID));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(DESTINATION_UUID));
|
||||
verify(destinationAccount, times(1)).getDevice(1);
|
||||
verify(destinationDevice, times(1)).getApnId();
|
||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GCMSenderTest {
|
||||
AccountsHelper.setupMockUpdate(accountsManager);
|
||||
|
||||
when(destinationAccount.getDevice(1)).thenReturn(Optional.of(destinationDevice));
|
||||
when(accountsManager.get(destinationUuid)).thenReturn(Optional.of(destinationAccount));
|
||||
when(accountsManager.getByAccountIdentifier(destinationUuid)).thenReturn(Optional.of(destinationAccount));
|
||||
when(destinationDevice.getGcmId()).thenReturn(gcmId);
|
||||
|
||||
when(invalidResult.isInvalidRegistrationId()).thenReturn(true);
|
||||
@@ -90,7 +90,7 @@ public class GCMSenderTest {
|
||||
gcmSender.sendMessage(message);
|
||||
|
||||
verify(sender, times(1)).send(any(Message.class));
|
||||
verify(accountsManager, times(1)).get(eq(destinationUuid));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(destinationUuid));
|
||||
verify(accountsManager, times(1)).updateDevice(eq(destinationAccount), eq(1L), any());
|
||||
verify(destinationDevice, times(1)).setUninstalledFeedbackTimestamp(eq(Util.todayInMillis()));
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class GCMSenderTest {
|
||||
Device destinationDevice = mock(Device.class );
|
||||
|
||||
when(destinationAccount.getDevice(1)).thenReturn(Optional.of(destinationDevice));
|
||||
when(accountsManager.get(destinationUuid)).thenReturn(Optional.of(destinationAccount));
|
||||
when(accountsManager.getByAccountIdentifier(destinationUuid)).thenReturn(Optional.of(destinationAccount));
|
||||
when(destinationDevice.getGcmId()).thenReturn(gcmId);
|
||||
|
||||
AccountsHelper.setupMockUpdate(accountsManager);
|
||||
@@ -131,7 +131,7 @@ public class GCMSenderTest {
|
||||
gcmSender.sendMessage(message);
|
||||
|
||||
verify(sender, times(1)).send(any(Message.class));
|
||||
verify(accountsManager, times(1)).get(eq(destinationUuid));
|
||||
verify(accountsManager, times(1)).getByAccountIdentifier(eq(destinationUuid));
|
||||
verify(accountsManager, times(1)).updateDevice(eq(destinationAccount), eq(1L), any());
|
||||
verify(destinationDevice, times(1)).setGcmId(eq(canonicalId));
|
||||
}
|
||||
|
||||
@@ -158,26 +158,30 @@ class AccountTest {
|
||||
when(disabledMasterDevice.getId()).thenReturn(1L);
|
||||
when(disabledLinkedDevice.getId()).thenReturn(2L);
|
||||
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice), new byte[0]).isEnabled());
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Set.of(enabledMasterDevice), new byte[0]).isEnabled());
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(enabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertTrue( new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(enabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Set.of(disabledMasterDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(disabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
|
||||
assertFalse(new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(disabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCapabilities() {
|
||||
Account uuidCapable = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{
|
||||
Account uuidCapable = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<Device>() {{
|
||||
add(gv2CapableDevice);
|
||||
}}, "1234".getBytes());
|
||||
|
||||
Account uuidIncapable = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{
|
||||
Account uuidIncapable = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<Device>() {{
|
||||
add(gv2CapableDevice);
|
||||
add(gv2IncapableDevice);
|
||||
}}, "1234".getBytes());
|
||||
|
||||
Account uuidCapableWithExpiredIncapable = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{
|
||||
Account uuidCapableWithExpiredIncapable = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<Device>() {{
|
||||
add(gv2CapableDevice);
|
||||
add(gv2IncapableExpiredDevice);
|
||||
}}, "1234".getBytes());
|
||||
@@ -213,20 +217,20 @@ class AccountTest {
|
||||
|
||||
{
|
||||
final Account transferableMasterAccount =
|
||||
new Account("+14152222222", UUID.randomUUID(), Collections.singleton(transferCapableMasterDevice), "1234".getBytes());
|
||||
new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), Collections.singleton(transferCapableMasterDevice), "1234".getBytes());
|
||||
|
||||
assertTrue(transferableMasterAccount.isTransferSupported());
|
||||
}
|
||||
|
||||
{
|
||||
final Account nonTransferableMasterAccount =
|
||||
new Account("+14152222222", UUID.randomUUID(), Collections.singleton(nonTransferCapableMasterDevice), "1234".getBytes());
|
||||
new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), Collections.singleton(nonTransferCapableMasterDevice), "1234".getBytes());
|
||||
|
||||
assertFalse(nonTransferableMasterAccount.isTransferSupported());
|
||||
}
|
||||
|
||||
{
|
||||
final Account transferableLinkedAccount = new Account("+14152222222", UUID.randomUUID(), new HashSet<>() {{
|
||||
final Account transferableLinkedAccount = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<>() {{
|
||||
add(nonTransferCapableMasterDevice);
|
||||
add(transferCapableLinkedDevice);
|
||||
}}, "1234".getBytes());
|
||||
@@ -237,7 +241,7 @@ class AccountTest {
|
||||
|
||||
@Test
|
||||
void testDiscoverableByPhoneNumber() {
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), Collections.singleton(recentMasterDevice),
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), Collections.singleton(recentMasterDevice),
|
||||
"1234".getBytes());
|
||||
|
||||
assertTrue(account.isDiscoverableByPhoneNumber(),
|
||||
@@ -252,66 +256,70 @@ class AccountTest {
|
||||
|
||||
@Test
|
||||
void isGroupsV2Supported() {
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice),
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(), Set.of(gv2CapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, gv2IncapableExpiredDevice),
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(gv2CapableDevice, gv2IncapableExpiredDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
assertFalse(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, gv2IncapableDevice),
|
||||
assertFalse(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(gv2CapableDevice, gv2IncapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isGv1MigrationSupported() {
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice),
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(), Set.of(gv1MigrationCapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported());
|
||||
assertFalse(
|
||||
new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableDevice),
|
||||
new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported());
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableExpiredDevice), "1234".getBytes(StandardCharsets.UTF_8))
|
||||
UUID.randomUUID(), Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableExpiredDevice), "1234".getBytes(StandardCharsets.UTF_8))
|
||||
.isGv1MigrationSupported());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isSenderKeySupported() {
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(), Set.of(senderKeyCapableDevice),
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(), Set.of(senderKeyCapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isSenderKeySupported()).isTrue();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(), Set.of(senderKeyCapableDevice, senderKeyIncapableDevice),
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||
Set.of(senderKeyCapableDevice, senderKeyIncapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isSenderKeySupported()).isFalse();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(senderKeyCapableDevice, senderKeyIncapableExpiredDevice),
|
||||
UUID.randomUUID(), Set.of(senderKeyCapableDevice, senderKeyIncapableExpiredDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isSenderKeySupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAnnouncementGroupSupported() {
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(announcementGroupCapableDevice),
|
||||
UUID.randomUUID(), Set.of(announcementGroupCapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isAnnouncementGroupSupported()).isTrue();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(announcementGroupCapableDevice, announcementGroupIncapableDevice),
|
||||
UUID.randomUUID(), Set.of(announcementGroupCapableDevice, announcementGroupIncapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isAnnouncementGroupSupported()).isFalse();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(announcementGroupCapableDevice, announcementGroupIncapableExpiredDevice),
|
||||
UUID.randomUUID(), Set.of(announcementGroupCapableDevice, announcementGroupIncapableExpiredDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isAnnouncementGroupSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isChangeNumberSupported() {
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(changeNumberCapableDevice),
|
||||
UUID.randomUUID(), Set.of(changeNumberCapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isChangeNumberSupported()).isTrue();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(changeNumberCapableDevice, changeNumberIncapableDevice),
|
||||
UUID.randomUUID(), Set.of(changeNumberCapableDevice, changeNumberIncapableDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isChangeNumberSupported()).isFalse();
|
||||
assertThat(new Account("+18005551234", UUID.randomUUID(),
|
||||
Set.of(changeNumberCapableDevice, changeNumberIncapableExpiredDevice),
|
||||
UUID.randomUUID(), Set.of(changeNumberCapableDevice, changeNumberIncapableExpiredDevice),
|
||||
"1234".getBytes(StandardCharsets.UTF_8)).isChangeNumberSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void stale() {
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), Collections.emptySet(), new byte[0]);
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Collections.emptySet(), new byte[0]);
|
||||
|
||||
assertDoesNotThrow(account::getNumber);
|
||||
|
||||
@@ -327,7 +335,7 @@ class AccountTest {
|
||||
final Set<Device> devices = new HashSet<>();
|
||||
devices.add(createDevice(Device.MASTER_ID));
|
||||
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), devices, new byte[0]);
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(), devices, new byte[0]);
|
||||
|
||||
assertThat(account.getNextDeviceId()).isEqualTo(2L);
|
||||
|
||||
@@ -348,7 +356,7 @@ class AccountTest {
|
||||
|
||||
@Test
|
||||
void addAndRemoveBadges() {
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), Set.of(createDevice(Device.MASTER_ID)), new byte[0]);
|
||||
final Account account = new Account("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Set.of(createDevice(Device.MASTER_ID)), new byte[0]);
|
||||
final Clock clock = mock(Clock.class);
|
||||
when(clock.instant()).thenReturn(Instant.ofEpochSecond(40));
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ import io.lettuce.core.RedisException;
|
||||
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||
import java.time.Clock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -56,6 +58,7 @@ import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.Device.DeviceCapabilities;
|
||||
import org.whispersystems.textsecuregcm.storage.KeysDynamoDb;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers;
|
||||
import org.whispersystems.textsecuregcm.storage.ProfilesManager;
|
||||
import org.whispersystems.textsecuregcm.storage.StoredVerificationCodeManager;
|
||||
import org.whispersystems.textsecuregcm.storage.UsernamesManager;
|
||||
@@ -96,11 +99,12 @@ class AccountsManagerTest {
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
final Account account = invocation.getArgument(0, Account.class);
|
||||
final String number = invocation.getArgument(1, String.class);
|
||||
final UUID phoneNumberIdentifier = invocation.getArgument(2, UUID.class);
|
||||
|
||||
account.setNumber(number);
|
||||
account.setNumber(number, phoneNumberIdentifier);
|
||||
|
||||
return null;
|
||||
}).when(accounts).changeNumber(any(), anyString());
|
||||
}).when(accounts).changeNumber(any(), anyString(), any());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
//noinspection unchecked
|
||||
@@ -114,8 +118,17 @@ class AccountsManagerTest {
|
||||
final SecureBackupClient backupClient = mock(SecureBackupClient.class);
|
||||
when(backupClient.deleteBackups(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberIdentifiers phoneNumberIdentifiers = mock(PhoneNumberIdentifiers.class);
|
||||
final Map<String, UUID> phoneNumberIdentifiersByE164 = new HashMap<>();
|
||||
|
||||
when(phoneNumberIdentifiers.getPhoneNumberIdentifier(anyString())).thenAnswer((Answer<UUID>) invocation -> {
|
||||
final String number = invocation.getArgument(0, String.class);
|
||||
return phoneNumberIdentifiersByE164.computeIfAbsent(number, n -> UUID.randomUUID());
|
||||
});
|
||||
|
||||
accountsManager = new AccountsManager(
|
||||
accounts,
|
||||
phoneNumberIdentifiers,
|
||||
RedisClusterHelper.buildMockRedisCluster(commands),
|
||||
deletedAccountsManager,
|
||||
directoryQueue,
|
||||
@@ -135,13 +148,14 @@ class AccountsManagerTest {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
when(commands.get(eq("AccountMap::+14152222222"))).thenReturn(uuid.toString());
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn("{\"number\": \"+14152222222\", \"name\": \"test\"}");
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn("{\"number\": \"+14152222222\", \"name\": \"test\", \"pni\": \"de24dc73-fbd8-41be-a7d5-764c70d9da7e\"}");
|
||||
|
||||
Optional<Account> account = accountsManager.get("+14152222222");
|
||||
Optional<Account> account = accountsManager.getByE164("+14152222222");
|
||||
|
||||
assertTrue(account.isPresent());
|
||||
assertEquals(account.get().getNumber(), "+14152222222");
|
||||
assertEquals(account.get().getProfileName(), "test");
|
||||
assertEquals(Optional.of(UUID.fromString("de24dc73-fbd8-41be-a7d5-764c70d9da7e")), account.get().getPhoneNumberIdentifier());
|
||||
|
||||
verify(commands, times(1)).get(eq("AccountMap::+14152222222"));
|
||||
verify(commands, times(1)).get(eq("Account3::" + uuid));
|
||||
@@ -154,14 +168,15 @@ class AccountsManagerTest {
|
||||
void testGetAccountByUuidInCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn("{\"number\": \"+14152222222\", \"name\": \"test\"}");
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn("{\"number\": \"+14152222222\", \"name\": \"test\", \"pni\": \"de24dc73-fbd8-41be-a7d5-764c70d9da7e\"}");
|
||||
|
||||
Optional<Account> account = accountsManager.get(uuid);
|
||||
Optional<Account> account = accountsManager.getByAccountIdentifier(uuid);
|
||||
|
||||
assertTrue(account.isPresent());
|
||||
assertEquals(account.get().getNumber(), "+14152222222");
|
||||
assertEquals(account.get().getUuid(), uuid);
|
||||
assertEquals(account.get().getProfileName(), "test");
|
||||
assertEquals(Optional.of(UUID.fromString("de24dc73-fbd8-41be-a7d5-764c70d9da7e")), account.get().getPhoneNumberIdentifier());
|
||||
|
||||
verify(commands, times(1)).get(eq("Account3::" + uuid));
|
||||
verifyNoMoreInteractions(commands);
|
||||
@@ -169,110 +184,189 @@ class AccountsManagerTest {
|
||||
verifyNoInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetByPniInCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID pni = UUID.randomUUID();
|
||||
|
||||
when(commands.get(eq("AccountMap::" + pni))).thenReturn(uuid.toString());
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn("{\"number\": \"+14152222222\", \"name\": \"test\", \"pni\": \"de24dc73-fbd8-41be-a7d5-764c70d9da7e\"}");
|
||||
|
||||
Optional<Account> account = accountsManager.getByPhoneNumberIdentifier(pni);
|
||||
|
||||
assertTrue(account.isPresent());
|
||||
assertEquals(account.get().getNumber(), "+14152222222");
|
||||
assertEquals(account.get().getProfileName(), "test");
|
||||
assertEquals(Optional.of(UUID.fromString("de24dc73-fbd8-41be-a7d5-764c70d9da7e")), account.get().getPhoneNumberIdentifier());
|
||||
|
||||
verify(commands).get(eq("AccountMap::" + pni));
|
||||
verify(commands).get(eq("Account3::" + uuid));
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verifyNoInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByNumberNotInCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
UUID pni = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("AccountMap::+14152222222"))).thenReturn(null);
|
||||
when(accounts.get(eq("+14152222222"))).thenReturn(Optional.of(account));
|
||||
when(accounts.getByE164(eq("+14152222222"))).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.get("+14152222222");
|
||||
Optional<Account> retrieved = accountsManager.getByE164("+14152222222");
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands, times(1)).get(eq("AccountMap::+14152222222"));
|
||||
verify(commands, times(1)).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts, times(1)).get(eq("+14152222222"));
|
||||
verify(accounts, times(1)).getByE164(eq("+14152222222"));
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByUuidNotInCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
UUID pni = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn(null);
|
||||
when(accounts.get(eq(uuid))).thenReturn(Optional.of(account));
|
||||
when(accounts.getByAccountIdentifier(eq(uuid))).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.get(uuid);
|
||||
Optional<Account> retrieved = accountsManager.getByAccountIdentifier(uuid);
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands, times(1)).get(eq("Account3::" + uuid));
|
||||
verify(commands, times(1)).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts, times(1)).get(eq(uuid));
|
||||
verify(accounts, times(1)).getByAccountIdentifier(eq(uuid));
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByPniNotInCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID pni = UUID.randomUUID();
|
||||
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("AccountMap::" + pni))).thenReturn(null);
|
||||
when(accounts.getByPhoneNumberIdentifier(pni)).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.getByPhoneNumberIdentifier(pni);
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands).get(eq("AccountMap::" + pni));
|
||||
verify(commands).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts).getByPhoneNumberIdentifier(pni);
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByNumberBrokenCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
UUID pni = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("AccountMap::+14152222222"))).thenThrow(new RedisException("Connection lost!"));
|
||||
when(accounts.get(eq("+14152222222"))).thenReturn(Optional.of(account));
|
||||
when(accounts.getByE164(eq("+14152222222"))).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.get("+14152222222");
|
||||
Optional<Account> retrieved = accountsManager.getByE164("+14152222222");
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands, times(1)).get(eq("AccountMap::+14152222222"));
|
||||
verify(commands, times(1)).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts, times(1)).get(eq("+14152222222"));
|
||||
verify(accounts, times(1)).getByE164(eq("+14152222222"));
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByUuidBrokenCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
UUID pni = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("Account3::" + uuid))).thenThrow(new RedisException("Connection lost!"));
|
||||
when(accounts.get(eq(uuid))).thenReturn(Optional.of(account));
|
||||
when(accounts.getByAccountIdentifier(eq(uuid))).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.get(uuid);
|
||||
Optional<Account> retrieved = accountsManager.getByAccountIdentifier(uuid);
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands, times(1)).get(eq("Account3::" + uuid));
|
||||
verify(commands, times(1)).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands, times(1)).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts, times(1)).get(eq(uuid));
|
||||
verify(accounts, times(1)).getByAccountIdentifier(eq(uuid));
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAccountByPniBrokenCache() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID pni = UUID.randomUUID();
|
||||
|
||||
Account account = new Account("+14152222222", uuid, pni, new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("AccountMap::" + pni))).thenThrow(new RedisException("OH NO"));
|
||||
when(accounts.getByPhoneNumberIdentifier(pni)).thenReturn(Optional.of(account));
|
||||
|
||||
Optional<Account> retrieved = accountsManager.getByPhoneNumberIdentifier(pni);
|
||||
|
||||
assertTrue(retrieved.isPresent());
|
||||
assertSame(retrieved.get(), account);
|
||||
|
||||
verify(commands).get(eq("AccountMap::" + pni));
|
||||
verify(commands).set(eq("AccountMap::" + pni), eq(uuid.toString()));
|
||||
verify(commands).set(eq("AccountMap::+14152222222"), eq(uuid.toString()));
|
||||
verify(commands).set(eq("Account3::" + uuid), anyString());
|
||||
verifyNoMoreInteractions(commands);
|
||||
|
||||
verify(accounts).getByPhoneNumberIdentifier(pni);
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdate_optimisticLockingFailure() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
Account account = new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn(null);
|
||||
|
||||
when(accounts.get(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, new HashSet<>(), new byte[16])));
|
||||
when(accounts.getByAccountIdentifier(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16])));
|
||||
doThrow(ContestedOptimisticLockException.class)
|
||||
.doAnswer(ACCOUNT_UPDATE_ANSWER)
|
||||
.when(accounts).update(any());
|
||||
|
||||
when(accounts.get(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, new HashSet<>(), new byte[16])));
|
||||
when(accounts.getByAccountIdentifier(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16])));
|
||||
doThrow(ContestedOptimisticLockException.class)
|
||||
.doAnswer(ACCOUNT_UPDATE_ANSWER)
|
||||
.when(accounts).update(any());
|
||||
@@ -282,7 +376,7 @@ class AccountsManagerTest {
|
||||
assertEquals(1, account.getVersion());
|
||||
assertEquals("name", account.getProfileName());
|
||||
|
||||
verify(accounts, times(1)).get(uuid);
|
||||
verify(accounts, times(1)).getByAccountIdentifier(uuid);
|
||||
verify(accounts, times(2)).update(any());
|
||||
verifyNoMoreInteractions(accounts);
|
||||
}
|
||||
@@ -290,10 +384,10 @@ class AccountsManagerTest {
|
||||
@Test
|
||||
void testUpdate_dynamoOptimisticLockingFailureDuringCreate() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
Account account = new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
|
||||
when(commands.get(eq("Account3::" + uuid))).thenReturn(null);
|
||||
when(accounts.get(uuid)).thenReturn(Optional.empty())
|
||||
when(accounts.getByAccountIdentifier(uuid)).thenReturn(Optional.empty())
|
||||
.thenReturn(Optional.of(account));
|
||||
when(accounts.create(any())).thenThrow(ContestedOptimisticLockException.class);
|
||||
|
||||
@@ -307,10 +401,10 @@ class AccountsManagerTest {
|
||||
@Test
|
||||
void testUpdateDevice() {
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
Account account = new Account("+14152222222", uuid, new HashSet<>(), new byte[16]);
|
||||
Account account = new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
|
||||
when(accounts.get(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, new HashSet<>(), new byte[16])));
|
||||
when(accounts.getByAccountIdentifier(uuid)).thenReturn(
|
||||
Optional.of(new Account("+14152222222", uuid, UUID.randomUUID(), new HashSet<>(), new byte[16])));
|
||||
|
||||
assertTrue(account.getDevices().isEmpty());
|
||||
|
||||
@@ -422,7 +516,7 @@ class AccountsManagerTest {
|
||||
@MethodSource
|
||||
void testUpdateDirectoryQueue(final boolean visibleBeforeUpdate, final boolean visibleAfterUpdate,
|
||||
final boolean expectRefresh) {
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
|
||||
// this sets up the appropriate result for Account#shouldBeVisibleInDirectory
|
||||
final Device device = new Device(Device.MASTER_ID, "device", "token", "salt", null, null, null, true, 1,
|
||||
@@ -449,7 +543,7 @@ class AccountsManagerTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void testUpdateDeviceLastSeen(final boolean expectUpdate, final long initialLastSeen, final long updatedLastSeen) {
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
final Account account = new Account("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
final Device device = new Device(Device.MASTER_ID, "device", "token", "salt", null, null, null, true, 1,
|
||||
new SignedPreKey(1, "key", "sig"), initialLastSeen, 0,
|
||||
"OWT", 0, new DeviceCapabilities());
|
||||
@@ -479,7 +573,7 @@ class AccountsManagerTest {
|
||||
final String targetNumber = "+14153333333";
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
|
||||
Account account = new Account(originalNumber, uuid, new HashSet<>(), new byte[16]);
|
||||
Account account = new Account(originalNumber, uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
account = accountsManager.changeNumber(account, targetNumber);
|
||||
|
||||
assertEquals(targetNumber, account.getNumber());
|
||||
@@ -491,7 +585,7 @@ class AccountsManagerTest {
|
||||
void testChangePhoneNumberSameNumber() throws InterruptedException {
|
||||
final String number = "+14152222222";
|
||||
|
||||
Account account = new Account(number, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
Account account = new Account(number, UUID.randomUUID(), UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
account = accountsManager.changeNumber(account, number);
|
||||
|
||||
assertEquals(number, account.getNumber());
|
||||
@@ -509,10 +603,10 @@ class AccountsManagerTest {
|
||||
final UUID existingAccountUuid = UUID.randomUUID();
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
|
||||
final Account existingAccount = new Account(targetNumber, existingAccountUuid, new HashSet<>(), new byte[16]);
|
||||
when(accounts.get(targetNumber)).thenReturn(Optional.of(existingAccount));
|
||||
final Account existingAccount = new Account(targetNumber, existingAccountUuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
when(accounts.getByE164(targetNumber)).thenReturn(Optional.of(existingAccount));
|
||||
|
||||
Account account = new Account(originalNumber, uuid, new HashSet<>(), new byte[16]);
|
||||
Account account = new Account(originalNumber, uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
account = accountsManager.changeNumber(account, targetNumber);
|
||||
|
||||
assertEquals(targetNumber, account.getNumber());
|
||||
@@ -527,8 +621,8 @@ class AccountsManagerTest {
|
||||
final String targetNumber = "+14153333333";
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
|
||||
final Account account = new Account(originalNumber, uuid, new HashSet<>(), new byte[16]);
|
||||
final Account account = new Account(originalNumber, uuid, UUID.randomUUID(), new HashSet<>(), new byte[16]);
|
||||
|
||||
assertThrows(AssertionError.class, () -> accountsManager.update(account, a -> a.setNumber(targetNumber)));
|
||||
assertThrows(AssertionError.class, () -> accountsManager.update(account, a -> a.setNumber(targetNumber, UUID.randomUUID())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class AccountsHelper {
|
||||
}
|
||||
|
||||
public static void setupMockGet(final AccountsManager mockAccountsManager, final Set<Account> mockAccounts) {
|
||||
when(mockAccountsManager.get(any(UUID.class))).thenAnswer(answer -> {
|
||||
when(mockAccountsManager.getByAccountIdentifier(any(UUID.class))).thenAnswer(answer -> {
|
||||
|
||||
final UUID uuid = answer.getArgument(0, UUID.class);
|
||||
|
||||
@@ -176,7 +176,7 @@ public class AccountsHelper {
|
||||
} else {
|
||||
final ObjectMapper mapper = SystemMapper.getMapper();
|
||||
updatedAccount = mapper.readValue(mapper.writeValueAsBytes(account), Account.class);
|
||||
updatedAccount.setNumber(account.getNumber());
|
||||
updatedAccount.setNumber(account.getNumber(), account.getPhoneNumberIdentifier().orElse(null));
|
||||
account.markStale();
|
||||
}
|
||||
|
||||
|
||||
@@ -137,17 +137,17 @@ public class AuthHelper {
|
||||
|
||||
reset(ACCOUNTS_MANAGER);
|
||||
|
||||
when(ACCOUNTS_MANAGER.get(VALID_NUMBER)).thenReturn(Optional.of(VALID_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.get(VALID_UUID)).thenReturn(Optional.of(VALID_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByE164(VALID_NUMBER)).thenReturn(Optional.of(VALID_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByAccountIdentifier(VALID_UUID)).thenReturn(Optional.of(VALID_ACCOUNT));
|
||||
|
||||
when(ACCOUNTS_MANAGER.get(VALID_NUMBER_TWO)).thenReturn(Optional.of(VALID_ACCOUNT_TWO));
|
||||
when(ACCOUNTS_MANAGER.get(VALID_UUID_TWO)).thenReturn(Optional.of(VALID_ACCOUNT_TWO));
|
||||
when(ACCOUNTS_MANAGER.getByE164(VALID_NUMBER_TWO)).thenReturn(Optional.of(VALID_ACCOUNT_TWO));
|
||||
when(ACCOUNTS_MANAGER.getByAccountIdentifier(VALID_UUID_TWO)).thenReturn(Optional.of(VALID_ACCOUNT_TWO));
|
||||
|
||||
when(ACCOUNTS_MANAGER.get(DISABLED_NUMBER)).thenReturn(Optional.of(DISABLED_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.get(DISABLED_UUID)).thenReturn(Optional.of(DISABLED_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByE164(DISABLED_NUMBER)).thenReturn(Optional.of(DISABLED_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByAccountIdentifier(DISABLED_UUID)).thenReturn(Optional.of(DISABLED_ACCOUNT));
|
||||
|
||||
when(ACCOUNTS_MANAGER.get(UNDISCOVERABLE_NUMBER)).thenReturn(Optional.of(UNDISCOVERABLE_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.get(UNDISCOVERABLE_UUID)).thenReturn(Optional.of(UNDISCOVERABLE_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByE164(UNDISCOVERABLE_NUMBER)).thenReturn(Optional.of(UNDISCOVERABLE_ACCOUNT));
|
||||
when(ACCOUNTS_MANAGER.getByAccountIdentifier(UNDISCOVERABLE_UUID)).thenReturn(Optional.of(UNDISCOVERABLE_ACCOUNT));
|
||||
|
||||
AccountsHelper.setupMockUpdateForAuthHelper(ACCOUNTS_MANAGER);
|
||||
|
||||
@@ -220,8 +220,8 @@ public class AuthHelper {
|
||||
when(account.getUuid()).thenReturn(uuid);
|
||||
when(account.getRelay()).thenReturn(Optional.empty());
|
||||
when(account.isEnabled()).thenReturn(true);
|
||||
when(accountsManager.get(number)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.get(uuid)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.getByE164(number)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.getByAccountIdentifier(uuid)).thenReturn(Optional.of(account));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user