mirror of
https://github.com/signalapp/Signal-Server
synced 2026-08-24 05:21:43 +01:00
Move responsibility for copying badges on account reclamation to AccountsManager
This commit is contained in:
committed by
Jon Chambers
parent
30c642324a
commit
8ba7da0568
-3
@@ -39,7 +39,6 @@ import java.io.IOException;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -255,7 +254,6 @@ public class RegistrationController {
|
||||
|
||||
final Account account = accounts.create(number,
|
||||
registrationRequest.accountAttributes(),
|
||||
existingAccount.map(Account::getBadges).orElseGet(ArrayList::new),
|
||||
registrationRequest.aciIdentityKey(),
|
||||
registrationRequest.pniIdentityKey(),
|
||||
new DeviceSpec(
|
||||
@@ -341,7 +339,6 @@ public class RegistrationController {
|
||||
try {
|
||||
final Account account = accounts.create(
|
||||
registrationRequest.accountAttributes(),
|
||||
Collections.emptyList(),
|
||||
registrationRequest.aciIdentityKey(),
|
||||
receiptCredentialPresentation,
|
||||
new DeviceSpec(
|
||||
|
||||
@@ -400,6 +400,9 @@ public class Accounts {
|
||||
// Carry over the existing backup voucher to the new account
|
||||
accountToCreate.setBackupVoucher(existingAccount.getBackupVoucher());
|
||||
|
||||
// Carry over any existing badges to the new account
|
||||
accountToCreate.setBadges(clock, existingAccount.getBadges());
|
||||
|
||||
// Carry over the existing ZK credential key to the new account
|
||||
accountToCreate.setZkCredentialKey(existingAccount.getZkCredentialKey().orElse(null));
|
||||
accountToCreate.setZkCredentialKeyRotationId(existingAccount.getZkCredentialKeyRotationId());
|
||||
|
||||
@@ -296,7 +296,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
/// Create an account without a phone number.
|
||||
///
|
||||
/// @param accountAttributes the account-level attributes to set on the account
|
||||
/// @param accountBadges the badges to set on the account
|
||||
/// @param aciIdentityKey the ACI identity key to associate with the account
|
||||
/// @param receiptCredentialPresentation the receipt credential presentation of proof of payment for a Signal Login
|
||||
/// @param primaryDeviceSpec the attributes to set on the account's primary device
|
||||
@@ -304,7 +303,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
///
|
||||
/// @return the created account
|
||||
public Account create(final AccountAttributes accountAttributes,
|
||||
final List<AccountBadge> accountBadges,
|
||||
final IdentityKey aciIdentityKey,
|
||||
final ReceiptCredentialPresentation receiptCredentialPresentation,
|
||||
final DeviceSpec primaryDeviceSpec,
|
||||
@@ -324,7 +322,7 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
final Timer.Sample sample = Timer.start();
|
||||
|
||||
try {
|
||||
return create(Optional.empty(), Optional.empty(), Optional.of(receiptCredentialPresentation), Optional.of(authCredentialSalt), accountAttributes, accountBadges, aciIdentityKey, Optional.empty(), primaryDeviceSpec, userAgent);
|
||||
return create(Optional.empty(), Optional.empty(), Optional.of(receiptCredentialPresentation), Optional.of(authCredentialSalt), accountAttributes, aciIdentityKey, Optional.empty(), primaryDeviceSpec, userAgent);
|
||||
} catch (final RuntimeException e) {
|
||||
logger.error("Unexpected exception while creating account", e);
|
||||
throw e;
|
||||
@@ -337,7 +335,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
///
|
||||
/// @param number the e164-formatted phone number to set on the account
|
||||
/// @param accountAttributes the account-level attributes to set on the account
|
||||
/// @param accountBadges the badges to set on the account
|
||||
/// @param aciIdentityKey the ACI identity key to associate with the account
|
||||
/// @param pniIdentityKey the PNI identity key to associate with the account
|
||||
/// @param primaryDeviceSpec the attributes to set on the account's primary device
|
||||
@@ -346,7 +343,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
/// @return the created account
|
||||
public Account create(final String number,
|
||||
final AccountAttributes accountAttributes,
|
||||
final List<AccountBadge> accountBadges,
|
||||
final IdentityKey aciIdentityKey,
|
||||
final IdentityKey pniIdentityKey,
|
||||
final DeviceSpec primaryDeviceSpec,
|
||||
@@ -357,7 +353,7 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
return Metrics.timer(CREATE_TIMER_NAME, HAS_NUMBER_TAG_NAME, "true").record(() -> {
|
||||
try {
|
||||
return accountLockManager.withLock(Set.of(pni),
|
||||
() -> create(Optional.of(number), Optional.of(pni), Optional.empty(), Optional.empty(), accountAttributes, accountBadges, aciIdentityKey, Optional.of(pniIdentityKey), primaryDeviceSpec, userAgent), accountLockExecutor);
|
||||
() -> create(Optional.of(number), Optional.of(pni), Optional.empty(), Optional.empty(), accountAttributes, aciIdentityKey, Optional.of(pniIdentityKey), primaryDeviceSpec, userAgent), accountLockExecutor);
|
||||
} catch (final ReceiptAlreadyRedeemedException e) {
|
||||
throw new AssertionError("ReceiptAlreadyRedeemedException must never be thrown for accounts with numbers");
|
||||
} catch (final RuntimeException e) {
|
||||
@@ -373,7 +369,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
final Optional<ReceiptCredentialPresentation> maybeReceiptCredentialPresentation,
|
||||
final Optional<byte[]> maybeAuthCredentialSalt,
|
||||
final AccountAttributes accountAttributes,
|
||||
final List<AccountBadge> accountBadges,
|
||||
final IdentityKey aciIdentityKey,
|
||||
final Optional<IdentityKey> maybePniIdentityKey,
|
||||
final DeviceSpec primaryDeviceSpec,
|
||||
@@ -401,7 +396,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
account.setUnidentifiedAccessKey(accountAttributes.getUnidentifiedAccessKey());
|
||||
account.setUnrestrictedUnidentifiedAccess(accountAttributes.isUnrestrictedUnidentifiedAccess());
|
||||
account.setDiscoverableByPhoneNumber(accountAttributes.isDiscoverableByPhoneNumber());
|
||||
account.setBadges(clock, accountBadges);
|
||||
|
||||
accountAttributes.recoveryPassword().ifPresent(account::setAccountRecoveryPassword);
|
||||
|
||||
|
||||
+19
-20
@@ -200,6 +200,7 @@ class RegistrationControllerTest {
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void invalidRegistrationId(Optional<Integer> registrationId, Optional<Integer> pniRegistrationId, int statusCode) {
|
||||
@@ -211,7 +212,7 @@ class RegistrationControllerTest {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final String json = requestJson("sessionId", new byte[0], true, registrationId.orElse(0), pniRegistrationId.orElse(null));
|
||||
@@ -318,7 +319,7 @@ class RegistrationControllerTest {
|
||||
final Account createdAccount = mock(Account.class);
|
||||
when(createdAccount.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(createdAccount);
|
||||
|
||||
expectedStatus = 200;
|
||||
@@ -377,7 +378,7 @@ class RegistrationControllerTest {
|
||||
"true, true, true, 200"
|
||||
})
|
||||
void deviceTransferAvailable(final boolean existingAccount, final boolean transferSupported,
|
||||
final boolean skipDeviceTransfer, final int expectedStatus) throws Exception {
|
||||
final boolean skipDeviceTransfer, final int expectedStatus) {
|
||||
|
||||
final Optional<Account> maybeAccount;
|
||||
if (existingAccount) {
|
||||
@@ -393,7 +394,7 @@ class RegistrationControllerTest {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -408,11 +409,11 @@ class RegistrationControllerTest {
|
||||
// this is functionally the same as deviceTransferAvailable(existingAccount=false)
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void registrationSuccess(final boolean useSessionVerification) throws Exception {
|
||||
void registrationSuccess(final boolean useSessionVerification) {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -658,7 +659,7 @@ class RegistrationControllerTest {
|
||||
void atomicAccountCreationSuccess(final RegistrationRequest registrationRequest,
|
||||
final IdentityKey expectedAciIdentityKey,
|
||||
final IdentityKey expectedPniIdentityKey,
|
||||
final DeviceSpec expectedDeviceSpec) throws InterruptedException {
|
||||
final DeviceSpec expectedDeviceSpec) {
|
||||
|
||||
final UUID accountIdentifier = UUID.randomUUID();
|
||||
final UUID phoneNumberIdentifier = UUID.randomUUID();
|
||||
@@ -666,11 +667,11 @@ class RegistrationControllerTest {
|
||||
|
||||
final Account account = MockUtils.buildMock(Account.class, a -> {
|
||||
when(a.getAccountIdentifier()).thenReturn(accountIdentifier);
|
||||
when(a.getPhoneNumberIdentifier()).thenReturn(phoneNumberIdentifier);
|
||||
when(a.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(phoneNumberIdentifier));
|
||||
when(a.getPrimaryDevice()).thenReturn(device);
|
||||
});
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -687,7 +688,6 @@ class RegistrationControllerTest {
|
||||
verify(accountsManager).create(
|
||||
eq(NUMBER),
|
||||
argThat(attributes -> accountAttributesEqual(attributes, registrationRequest.accountAttributes())),
|
||||
eq(Collections.emptyList()),
|
||||
eq(expectedAciIdentityKey),
|
||||
eq(expectedPniIdentityKey),
|
||||
eq(expectedDeviceSpec),
|
||||
@@ -696,7 +696,7 @@ class RegistrationControllerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void reregistrationFlag(final boolean accountExists) throws InterruptedException {
|
||||
void reregistrationFlag(final boolean accountExists) {
|
||||
final Account existingAccount = mock(Account.class);
|
||||
when(existingAccount.getNumberOptional()).thenReturn(Optional.of(NUMBER));
|
||||
when(accountsManager.getByE164(any())).thenReturn(accountExists ? Optional.of(existingAccount) : Optional.empty());
|
||||
@@ -704,7 +704,7 @@ class RegistrationControllerTest {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -720,11 +720,11 @@ class RegistrationControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void registrationMissingSpqrCapability() throws Exception {
|
||||
void registrationMissingSpqrCapability() {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -775,7 +775,7 @@ class RegistrationControllerTest {
|
||||
final Account account = MockUtils.buildMock(Account.class,
|
||||
a -> when(a.getAccountIdentifier()).thenReturn(accountIdentifier));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any())).thenReturn(account);
|
||||
when(accountsManager.create(any(), any(), any(), any(), any())).thenReturn(account);
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
.target("/v1/registration")
|
||||
@@ -794,7 +794,6 @@ class RegistrationControllerTest {
|
||||
|
||||
verify(accountsManager).create(
|
||||
argThat(attributes -> accountAttributesEqual(attributes, accountAttributes)),
|
||||
eq(Collections.emptyList()),
|
||||
eq(aciIdentityKey),
|
||||
argThat(presentation ->
|
||||
Arrays.equals(presentation.serialize(), receiptCredentialPresentation.serialize())),
|
||||
@@ -861,7 +860,7 @@ class RegistrationControllerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void registerAccountBadReceipt(final byte[] receiptCredentialPresentation) throws Exception {
|
||||
void registerAccountBadReceipt(final byte[] receiptCredentialPresentation) {
|
||||
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
|
||||
final IdentityKey aciIdentityKey = new IdentityKey(aciIdentityKeyPair.getPublicKey());
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciIdentityKeyPair);
|
||||
@@ -1108,7 +1107,7 @@ class RegistrationControllerTest {
|
||||
Optional.empty(),
|
||||
Optional.empty()));
|
||||
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any()))
|
||||
when(accountsManager.create(any(), any(), any(), any(), any()))
|
||||
.thenThrow(new ReceiptAlreadyRedeemedException());
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -1122,14 +1121,13 @@ class RegistrationControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerAccountWithNumberMissingPniKeys() throws Exception {
|
||||
void registerAccountWithNumberMissingPniKeys() {
|
||||
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
|
||||
final IdentityKey aciIdentityKey = new IdentityKey(aciIdentityKeyPair.getPublicKey());
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciIdentityKeyPair);
|
||||
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciIdentityKeyPair);
|
||||
|
||||
final ECKeyPair pniIdentityKeyPair = ECKeyPair.generate();
|
||||
final ECSignedPreKey pniSignedPreKey = KeysHelper.signedECPreKey(1, pniIdentityKeyPair);
|
||||
final IdentityKey pniIdentityKey = new IdentityKey(pniIdentityKeyPair.getPublicKey());
|
||||
|
||||
final byte[] deviceName = "test".getBytes(StandardCharsets.UTF_8);
|
||||
@@ -1359,6 +1357,7 @@ class RegistrationControllerTest {
|
||||
/**
|
||||
* Valid request JSON with the given session ID
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static String requestJson(final String sessionId) {
|
||||
return requestJson(sessionId, new byte[0], false, 1, 2);
|
||||
}
|
||||
|
||||
+11
-39
@@ -212,11 +212,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceCapabilities,
|
||||
recoveryPassword);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniKeyPair = ECKeyPair.generate();
|
||||
|
||||
@@ -236,7 +231,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
final Account account = accountsManager.create(number,
|
||||
accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
@@ -261,7 +255,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
Collections.emptyList(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
Optional.of(registrationLockSecret),
|
||||
@@ -297,11 +291,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceCapabilities,
|
||||
TestRandomUtil.nextBytes(16));
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciKeyPair);
|
||||
@@ -317,7 +306,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
: Optional.empty();
|
||||
|
||||
final Account account = accountsManager.create(accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(
|
||||
@@ -342,7 +330,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
false,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
Collections.emptyList(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
Optional.empty(),
|
||||
@@ -386,6 +374,11 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final byte[] originalRecoveryPassword = TestRandomUtil.nextBytes(16);
|
||||
final byte[] updatedRecoveryPassword = TestRandomUtil.nextBytes(17);
|
||||
|
||||
final List<AccountBadge> existingAccountBadges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final UUID existingAccountUuid;
|
||||
{
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
@@ -399,7 +392,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final Account existingAccount = accountsManager.create(number,
|
||||
new AccountAttributes(true, 1, 1, "name".getBytes(StandardCharsets.UTF_8), "registration-lock", false, Set.of(),
|
||||
originalRecoveryPassword),
|
||||
Collections.emptyList(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(null,
|
||||
@@ -413,6 +405,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
Optional.empty()),
|
||||
null);
|
||||
|
||||
accountsManager.update(existingAccount, a -> a.setBadges(CLOCK, existingAccountBadges));
|
||||
|
||||
existingAccountUuid = existingAccount.getAccountIdentifier();
|
||||
}
|
||||
|
||||
@@ -434,11 +428,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceCapabilities,
|
||||
updatedRecoveryPassword);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniKeyPair = ECKeyPair.generate();
|
||||
|
||||
@@ -458,7 +447,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
final Account reregisteredAccount = accountsManager.create(number,
|
||||
accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(deviceName,
|
||||
@@ -482,7 +470,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
existingAccountBadges,
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
Optional.of(registrationLockSecret),
|
||||
@@ -527,11 +515,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
accountAttributes.setRecoveryPassword(TestRandomUtil.nextBytes(16));
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniKeyPair = ECKeyPair.generate();
|
||||
|
||||
@@ -544,7 +527,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
if (hasE164) {
|
||||
account = accountsManager.create(number,
|
||||
accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
@@ -562,7 +544,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
} else {
|
||||
account = accountsManager.create(accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(
|
||||
@@ -613,7 +594,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final Account existingAccount = accountsManager.create(
|
||||
new AccountAttributes(true, 1, null, "name".getBytes(StandardCharsets.UTF_8), null, false, Set.of(), null)
|
||||
.setRecoveryPassword(recoveryPassword),
|
||||
Collections.emptyList(),
|
||||
aciIdentityKey,
|
||||
receiptPresentation(receiptSerial, CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(null,
|
||||
@@ -644,11 +624,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
false,
|
||||
deviceCapabilities, null).setRecoveryPassword(recoveryPassword);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(5, aciKeyPair);
|
||||
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(7, aciKeyPair);
|
||||
|
||||
@@ -662,7 +637,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
: Optional.empty();
|
||||
|
||||
final Account retriedAccount = accountsManager.create(accountAttributes,
|
||||
badges,
|
||||
aciIdentityKey,
|
||||
receiptPresentation(receiptSerial, CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(deviceName,
|
||||
@@ -686,7 +660,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
false,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
Collections.emptyList(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
Optional.empty(),
|
||||
@@ -717,7 +691,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
final Account existingAccount = accountsManager.create(
|
||||
new AccountAttributes(true, 1, null, "name".getBytes(StandardCharsets.UTF_8), null, false, Set.of(), recoveryPassword),
|
||||
Collections.emptyList(),
|
||||
aciIdentityKey,
|
||||
receiptPresentation(receiptSerial, CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(null,
|
||||
@@ -736,7 +709,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
assertThrows(ReceiptAlreadyRedeemedException.class, () -> accountsManager.create(
|
||||
// Using a different account recovery password should throw an exception
|
||||
new AccountAttributes(true, 1, null, "name".getBytes(StandardCharsets.UTF_8), null, false, Set.of(), TestRandomUtil.nextBytes(16)),
|
||||
Collections.emptyList(),
|
||||
aciIdentityKey,
|
||||
receiptPresentation(receiptSerial, CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(null,
|
||||
|
||||
+10
-2
@@ -69,7 +69,8 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
Tables.PAGED_PQ_KEYS,
|
||||
Tables.REDEEMED_RECEIPTS,
|
||||
Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS);
|
||||
Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
Tables.PHONE_NUMBER_RECOVERY_PASSWORDS);
|
||||
|
||||
private Accounts accounts;
|
||||
|
||||
@@ -110,6 +111,13 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
when(phoneNumberIdentifiers.getPhoneNumberIdentifier(anyString()))
|
||||
.thenAnswer((Answer<CompletableFuture<UUID>>) _ -> CompletableFuture.completedFuture(UUID.randomUUID()));
|
||||
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
new PhoneNumberRecoveryPasswordsManager(new PhoneNumberRecoveryPasswords(
|
||||
Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
Clock.systemUTC()));
|
||||
|
||||
accountsManager = new AccountsManager(
|
||||
accounts,
|
||||
phoneNumberIdentifiers,
|
||||
@@ -123,7 +131,7 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
mock(SecureStorageClient.class),
|
||||
mock(SecureValueRecoveryClient.class),
|
||||
mock(DisconnectionRequestManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
mock(Executor.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
|
||||
-3
@@ -1494,7 +1494,6 @@ class AccountsManagerTest {
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
|
||||
return accountsManager.create(accountAttributes,
|
||||
new ArrayList<>(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
mock(ReceiptCredentialPresentation.class),
|
||||
new DeviceSpec(
|
||||
@@ -1516,7 +1515,6 @@ class AccountsManagerTest {
|
||||
|
||||
return accountsManager.create(e164,
|
||||
accountAttributes,
|
||||
new ArrayList<>(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
@@ -1682,7 +1680,6 @@ class AccountsManagerTest {
|
||||
void createAccountWithoutNumberOrRecoveryPassword() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> accountsManager.create(new AccountAttributes(),
|
||||
Collections.emptyList(),
|
||||
new IdentityKey(ECKeyPair.generate().getPublicKey()),
|
||||
ReceiptCredentialTestUtil.receiptPresentation(),
|
||||
mock(DeviceSpec.class),
|
||||
|
||||
@@ -15,7 +15,6 @@ import static org.mockito.Mockito.when;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -340,7 +339,6 @@ public class AccountsHelper {
|
||||
if (e164 != null) {
|
||||
return accountsManager.create(e164,
|
||||
accountAttributes,
|
||||
new ArrayList<>(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
primaryDeviceSpec,
|
||||
@@ -348,7 +346,6 @@ public class AccountsHelper {
|
||||
} else {
|
||||
try {
|
||||
return accountsManager.create(accountAttributes,
|
||||
new ArrayList<>(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
generateReceiptCredentialPresentation(),
|
||||
primaryDeviceSpec,
|
||||
|
||||
Reference in New Issue
Block a user