mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 09:16:47 +00:00
Use getByPhoneNumberIdentifier in getAccountsForChangeNumber
This commit is contained in:
1 parent
e6c24c373d
commit
f8f60c92ff
2 files changed
+22
-2
No files matched your search
@@ -1148,7 +1148,7 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
Pair<Account, Optional<Account>> getAccountsForChangeNumber(final UUID accountIdentifier, final String targetNumber) {
|
||||
return new Pair<>(accounts.getByAccountIdentifier(accountIdentifier)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Account not found: " + accountIdentifier)),
|
||||
accounts.getByE164(targetNumber));
|
||||
accounts.getByPhoneNumberIdentifier(getPhoneNumberIdentifier(targetNumber)));
|
||||
}
|
||||
|
||||
public UUID getPhoneNumberIdentifier(String e164) {
|
||||
|
||||
+21
-1
@@ -118,6 +118,7 @@ class AccountsManagerTest {
|
||||
private static TestClock CLOCK;
|
||||
|
||||
private Accounts accounts;
|
||||
private PhoneNumberIdentifiers phoneNumberIdentifiers;
|
||||
private KeysManager keysManager;
|
||||
private MessagesManager messagesManager;
|
||||
private ProfilesManager profilesManager;
|
||||
@@ -179,7 +180,7 @@ class AccountsManagerTest {
|
||||
svr2Client = mock(SecureValueRecoveryClient.class);
|
||||
when(svr2Client.removeData(any(UUID.class))).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberIdentifiers phoneNumberIdentifiers = mock(PhoneNumberIdentifiers.class);
|
||||
phoneNumberIdentifiers = mock(PhoneNumberIdentifiers.class);
|
||||
phoneNumberIdentifiersByE164 = new HashMap<>();
|
||||
|
||||
when(phoneNumberIdentifiers.getPhoneNumberIdentifier(anyString())).thenAnswer((Answer<CompletableFuture<UUID>>) invocation -> {
|
||||
@@ -1479,6 +1480,25 @@ class AccountsManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAccountsForChangeNumber() {
|
||||
final Account account = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), new ArrayList<>(), new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]);
|
||||
final UUID accountIdentifier = account.getIdentifier(IdentityType.ACI);
|
||||
addRetrievableAccount(account);
|
||||
|
||||
final String targetNumber = "+13102222222";
|
||||
|
||||
assertFalse(phoneNumberIdentifiersByE164.containsKey(targetNumber));
|
||||
|
||||
final Pair<Account, Optional<Account>> accountsForChangeNumber = accountsManager.getAccountsForChangeNumber(
|
||||
accountIdentifier, targetNumber);
|
||||
|
||||
assertEquals(account, accountsForChangeNumber.first());
|
||||
verify(accounts).getByAccountIdentifier(accountIdentifier);
|
||||
// getPhoneNumberIdentifier handles alternate forms
|
||||
verify(phoneNumberIdentifiers).getPhoneNumberIdentifier(targetNumber);
|
||||
}
|
||||
|
||||
static Collection<Arguments> updateCurrentProfileVersion() {
|
||||
|
||||
final byte[] empty = new byte[0];
|
||||
|
||||
Reference in new issue
Block a user