mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 01:16:50 +00:00
Set phone number recovery password transactionally when creating accounts
This commit is contained in:
1 parent
e7ec47aa25
commit
647b25b87c
11 files changed
+91
-63
No files matched your search
@@ -216,6 +216,7 @@ public class Accounts {
|
||||
|
||||
boolean create(final Account account, final List<TransactWriteItem> additionalWriteItems)
|
||||
throws AccountAlreadyExistsException {
|
||||
|
||||
if (account.getNumberOptional().isEmpty() || account.getPhoneNumberIdentifierOptional().isEmpty()) {
|
||||
throw new IllegalArgumentException("Phone number and phone number identifier must be set");
|
||||
}
|
||||
@@ -297,8 +298,10 @@ public class Accounts {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean create(final Account account, final ReceiptCredentialPresentation receiptCredentialPresentation, final
|
||||
byte[] accountRecoveryPasswordInRequest, final List<TransactWriteItem> additionalWriteItems)
|
||||
boolean create(final Account account,
|
||||
final ReceiptCredentialPresentation receiptCredentialPresentation,
|
||||
final byte[] accountRecoveryPasswordInRequest,
|
||||
final List<TransactWriteItem> additionalWriteItems)
|
||||
throws AccountAlreadyExistsException, ReceiptAlreadyRedeemedException {
|
||||
|
||||
final Timer.Sample sample = Timer.start();
|
||||
|
||||
+35
-31
@@ -57,7 +57,6 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
@@ -379,7 +378,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
final Optional<IdentityKey> maybePniIdentityKey,
|
||||
final DeviceSpec primaryDeviceSpec,
|
||||
@Nullable final String userAgent) throws ReceiptAlreadyRedeemedException {
|
||||
|
||||
assert maybeNumber.isPresent() ^ maybeReceiptCredentialPresentation.isPresent();
|
||||
|
||||
final Account account = new Account();
|
||||
final Optional<UUID> maybeRecentlyDeletedAccountIdentifier =
|
||||
maybePni.flatMap(accounts::findRecentlyDeletedAccountIdentifier);
|
||||
@@ -419,19 +420,26 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
String previousPushTokenType = null;
|
||||
|
||||
try {
|
||||
final List<TransactWriteItem> newDeviceWriteItems = keysManager.buildWriteItemsForNewDevice(account.getAccountIdentifier(),
|
||||
final List<TransactWriteItem> additionalWriteItems = new ArrayList<>(keysManager.buildWriteItemsForNewDevice(account.getAccountIdentifier(),
|
||||
account.getPhoneNumberIdentifierOptional(),
|
||||
Device.PRIMARY_ID,
|
||||
primaryDeviceSpec.aciInfo().signedPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::signedPreKey),
|
||||
primaryDeviceSpec.aciInfo().pqLastResortPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::pqLastResortPreKey));
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::pqLastResortPreKey)));
|
||||
|
||||
maybePni.ifPresent(phoneNumberIdentifier ->
|
||||
accountAttributes.recoveryPassword().ifPresent(phoneNumberRecoveryPassword ->
|
||||
additionalWriteItems.add(phoneNumberRecoveryPasswordsManager.buildTransactWriteItemForStorePassword(phoneNumberIdentifier, phoneNumberRecoveryPassword))));
|
||||
|
||||
if (maybeNumber.isPresent()) {
|
||||
accounts.create(account, newDeviceWriteItems);
|
||||
accounts.create(account, additionalWriteItems);
|
||||
} else {
|
||||
assert accountAttributes.recoveryPassword().isPresent();
|
||||
accounts.create(account, maybeReceiptCredentialPresentation.get(), accountAttributes.recoveryPassword().get(),
|
||||
newDeviceWriteItems);
|
||||
accounts.create(account,
|
||||
maybeReceiptCredentialPresentation.get(),
|
||||
accountAttributes.recoveryPassword().get(),
|
||||
additionalWriteItems);
|
||||
}
|
||||
} catch (final AccountAlreadyExistsException e) {
|
||||
accountCreationType = "re-registration";
|
||||
@@ -447,23 +455,27 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
final UUID aci = e.getExistingAccount().getAccountIdentifier();
|
||||
account.setAccountIdentifier(aci);
|
||||
|
||||
final List<TransactWriteItem> additionalWriteItems = Stream.concat(
|
||||
keysManager.buildWriteItemsForNewDevice(account.getAccountIdentifier(),
|
||||
account.getPhoneNumberIdentifierOptional(),
|
||||
Device.PRIMARY_ID,
|
||||
primaryDeviceSpec.aciInfo().signedPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::signedPreKey),
|
||||
primaryDeviceSpec.aciInfo().pqLastResortPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::pqLastResortPreKey)).stream(),
|
||||
e.getExistingAccount().getDevices()
|
||||
.stream()
|
||||
.map(Device::getId)
|
||||
// No need to clear the keys for the primary device since we'll just overwrite them in the same
|
||||
// transaction anyhow
|
||||
.filter(existingDeviceId -> existingDeviceId != Device.PRIMARY_ID)
|
||||
.flatMap(existingDeviceId ->
|
||||
keysManager.buildWriteItemsForRemovedDevice(aci, account.getPhoneNumberIdentifierOptional(), existingDeviceId).stream()))
|
||||
.toList();
|
||||
final List<TransactWriteItem> additionalWriteItems = new ArrayList<>(keysManager.buildWriteItemsForNewDevice(account.getAccountIdentifier(),
|
||||
account.getPhoneNumberIdentifierOptional(),
|
||||
Device.PRIMARY_ID,
|
||||
primaryDeviceSpec.aciInfo().signedPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::signedPreKey),
|
||||
primaryDeviceSpec.aciInfo().pqLastResortPreKey(),
|
||||
primaryDeviceSpec.pniInfo().map(DeviceIdentityInfo::pqLastResortPreKey)));
|
||||
|
||||
e.getExistingAccount().getDevices()
|
||||
.stream()
|
||||
.map(Device::getId)
|
||||
// No need to clear the keys for the primary device since we'll just overwrite them in the same
|
||||
// transaction anyhow
|
||||
.filter(existingDeviceId -> existingDeviceId != Device.PRIMARY_ID)
|
||||
.map(existingDeviceId ->
|
||||
keysManager.buildWriteItemsForRemovedDevice(aci, account.getPhoneNumberIdentifierOptional(), existingDeviceId))
|
||||
.forEach(additionalWriteItems::addAll);
|
||||
|
||||
maybePni.ifPresent(phoneNumberIdentifier ->
|
||||
accountAttributes.recoveryPassword().ifPresent(phoneNumberRecoveryPassword ->
|
||||
additionalWriteItems.add(phoneNumberRecoveryPasswordsManager.buildTransactWriteItemForStorePassword(phoneNumberIdentifier, phoneNumberRecoveryPassword))));
|
||||
|
||||
CompletableFuture.allOf(
|
||||
keysManager.deleteSingleUsePreKeys(aci),
|
||||
@@ -490,11 +502,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
|
||||
redisSet(account);
|
||||
|
||||
final boolean phoneNumberRecoveryPasswordCreated = accountAttributes.recoveryPassword().map(phoneNumberRecoveryPassword ->
|
||||
account.getPhoneNumberIdentifierOptional().map(pni -> phoneNumberRecoveryPasswordsManager.store(pni, phoneNumberRecoveryPassword))
|
||||
.orElse(false))
|
||||
.orElse(false);
|
||||
|
||||
changeNumberWaitingPeriodManager.handleAccountCreated(account.getAccountIdentifier(), clock.instant());
|
||||
|
||||
Tags tags = Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
|
||||
@@ -508,9 +515,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
if (StringUtils.isNotBlank(previousPushTokenType)) {
|
||||
tags = tags.and(Tag.of("previousPushTokenType", previousPushTokenType));
|
||||
}
|
||||
if (accountAttributes.recoveryPassword().isPresent() && account.getPhoneNumberIdentifierOptional().isPresent()) {
|
||||
tags = tags.and(Tag.of("recoveryPasswordOutcome", phoneNumberRecoveryPasswordCreated ? "created" : "updated"));
|
||||
}
|
||||
Metrics.counter(CREATE_COUNTER_NAME, tags).increment();
|
||||
return account;
|
||||
}
|
||||
|
||||
+2
@@ -10,6 +10,7 @@ import static java.util.Objects.requireNonNull;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.whispersystems.textsecuregcm.auth.SaltedTokenHash;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem;
|
||||
@@ -31,6 +32,7 @@ public class PhoneNumberRecoveryPasswordsManager {
|
||||
return saltedTokenHash.verify(bytesToString(password));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public boolean store(final UUID phoneNumberIdentifier, final byte[] password) {
|
||||
final String token = bytesToString(password);
|
||||
final SaltedTokenHash tokenHash = SaltedTokenHash.generateFor(token);
|
||||
|
||||
+20
-15
@@ -45,7 +45,6 @@ import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||
import org.signal.libsignal.zkgroup.ServerSecretParams;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptSerial;
|
||||
import org.whispersystems.textsecuregcm.auth.DisconnectionRequestManager;
|
||||
@@ -54,14 +53,12 @@ import org.whispersystems.textsecuregcm.entities.ApnRegistrationId;
|
||||
import org.whispersystems.textsecuregcm.entities.ECSignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.entities.GcmRegistrationId;
|
||||
import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisClient;
|
||||
import org.whispersystems.textsecuregcm.redis.RedisClusterExtension;
|
||||
import org.whispersystems.textsecuregcm.securestorage.SecureStorageClient;
|
||||
import org.whispersystems.textsecuregcm.securevaluerecovery.SecureValueRecoveryClient;
|
||||
import org.whispersystems.textsecuregcm.tests.util.KeysHelper;
|
||||
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ValidBase64URLString;
|
||||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
|
||||
|
||||
public class AccountCreationDeletionIntegrationTest {
|
||||
@@ -79,7 +76,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
DynamoDbExtensionSchema.Tables.PAGED_PQ_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS,
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS,
|
||||
DynamoDbExtensionSchema.Tables.REDEEMED_RECEIPTS);
|
||||
|
||||
@RegisterExtension
|
||||
@@ -90,8 +87,6 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
private static final Clock CLOCK = Clock.fixed(Instant.now(), ZoneId.systemDefault());
|
||||
|
||||
private static final ServerSecretParams RECEIPT_PARAMS = ServerSecretParams.generate();
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
private AccountsManager accountsManager;
|
||||
@@ -150,7 +145,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords =
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(),
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
CLOCK);
|
||||
@@ -192,7 +187,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
@CartesianTest
|
||||
@CartesianTest.MethodFactory("createAccount")
|
||||
void createAccount(final DeliveryChannels deliveryChannels,
|
||||
final boolean discoverableByPhoneNumber) throws InterruptedException {
|
||||
final boolean discoverableByPhoneNumber) {
|
||||
|
||||
final String number = PhoneNumberUtil.getInstance().format(
|
||||
PhoneNumberUtil.getInstance().getExampleNumber("US"),
|
||||
@@ -204,6 +199,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final int pniRegistrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
|
||||
final byte[] deviceName = RandomStringUtils.secure().nextAlphabetic(16).getBytes(StandardCharsets.UTF_8);
|
||||
final String registrationLockSecret = RandomStringUtils.secure().nextAlphanumeric(16);
|
||||
final byte[] recoveryPassword = TestRandomUtil.nextBytes(16);
|
||||
|
||||
final Set<DeviceCapability> deviceCapabilities = Set.of();
|
||||
|
||||
@@ -213,7 +209,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
registrationLockSecret,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities, null);
|
||||
deviceCapabilities,
|
||||
recoveryPassword);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
@@ -277,6 +274,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
assertEquals(Optional.of(pniSignedPreKey), keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciPqLastResortPreKey), keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniPqLastResortPreKey), keysManager.getLastResort(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join());
|
||||
assertTrue(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(), recoveryPassword));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -379,12 +377,15 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
@CartesianTest
|
||||
@CartesianTest.MethodFactory("createAccount")
|
||||
void reregisterAccount(final DeliveryChannels deliveryChannels,
|
||||
final boolean discoverableByPhoneNumber) throws InterruptedException {
|
||||
final boolean discoverableByPhoneNumber) {
|
||||
|
||||
final String number = PhoneNumberUtil.getInstance().format(
|
||||
PhoneNumberUtil.getInstance().getExampleNumber("US"),
|
||||
PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
|
||||
final byte[] originalRecoveryPassword = TestRandomUtil.nextBytes(16);
|
||||
final byte[] updatedRecoveryPassword = TestRandomUtil.nextBytes(17);
|
||||
|
||||
final UUID existingAccountUuid;
|
||||
{
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
@@ -397,7 +398,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
final Account existingAccount = accountsManager.create(number,
|
||||
new AccountAttributes(true, 1, 1, "name".getBytes(StandardCharsets.UTF_8), "registration-lock", false, Set.of(),
|
||||
null),
|
||||
originalRecoveryPassword),
|
||||
Collections.emptyList(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
@@ -430,7 +431,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
deviceName,
|
||||
registrationLockSecret,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities, null);
|
||||
deviceCapabilities,
|
||||
updatedRecoveryPassword);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
@@ -493,6 +495,9 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
verify(disconnectionRequestManager).requestDisconnection(argThat(account ->
|
||||
account.getAccountIdentifier().equals(existingAccountUuid) && account != reregisteredAccount));
|
||||
|
||||
assertTrue(phoneNumberRecoveryPasswordsManager.verify(reregisteredAccount.getPhoneNumberIdentifierOptional().orElseThrow(), updatedRecoveryPassword));
|
||||
assertFalse(phoneNumberRecoveryPasswordsManager.verify(reregisteredAccount.getPhoneNumberIdentifierOptional().orElseThrow(), originalRecoveryPassword));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -573,10 +578,10 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
null);
|
||||
}
|
||||
|
||||
final UUID aci = account.getIdentifier(IdentityType.ACI);
|
||||
final UUID aci = account.getAccountIdentifier();
|
||||
|
||||
assertTrue(accountsManager.getByAccountIdentifier(aci).isPresent());
|
||||
accountsManager.delete(account.getIdentifier(IdentityType.ACI), AccountsManager.DeletionReason.ADMIN_DELETED);
|
||||
accountsManager.delete(account.getAccountIdentifier(), AccountsManager.DeletionReason.ADMIN_DELETED);
|
||||
|
||||
assertFalse(accountsManager.getByAccountIdentifier(aci).isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
@@ -589,7 +594,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
}
|
||||
|
||||
verify(disconnectionRequestManager).requestDisconnection(argThat(disconnectedAccount ->
|
||||
disconnectedAccount.getIdentifier(IdentityType.ACI).equals(account.getIdentifier(IdentityType.ACI))));
|
||||
disconnectedAccount.getAccountIdentifier().equals(account.getAccountIdentifier())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ class AccountsManagerChangeNumberIntegrationTest {
|
||||
Tables.PAGED_PQ_KEYS,
|
||||
Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
Tables.REGISTRATION_RECOVERY_PASSWORDS,
|
||||
Tables.PHONE_NUMBER_RECOVERY_PASSWORDS,
|
||||
Tables.REDEEMED_RECEIPTS);
|
||||
|
||||
@RegisterExtension
|
||||
@@ -129,7 +129,7 @@ class AccountsManagerChangeNumberIntegrationTest {
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords =
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(),
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ public class AccountsManagerMigrateRecoveryPasswordIntegrationTest {
|
||||
DynamoDbExtensionSchema.Tables.PAGED_PQ_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS);
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS);
|
||||
|
||||
@RegisterExtension
|
||||
static final RedisClusterExtension CACHE_CLUSTER_EXTENSION = RedisClusterExtension.builder().build();
|
||||
@@ -116,7 +116,7 @@ public class AccountsManagerMigrateRecoveryPasswordIntegrationTest {
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords =
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(),
|
||||
new PhoneNumberRecoveryPasswords(DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+10
-2
@@ -75,7 +75,8 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
Tables.PAGED_PQ_KEYS,
|
||||
Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
Tables.REDEEMED_RECEIPTS);
|
||||
Tables.REDEEMED_RECEIPTS,
|
||||
Tables.PHONE_NUMBER_RECOVERY_PASSWORDS);
|
||||
|
||||
@RegisterExtension
|
||||
static RedisClusterExtension CACHE_CLUSTER_EXTENSION = RedisClusterExtension.builder().build();
|
||||
@@ -131,6 +132,13 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
final DisconnectionRequestManager disconnectionRequestManager = mock(DisconnectionRequestManager.class);
|
||||
when(disconnectionRequestManager.requestDisconnection(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
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,
|
||||
@@ -144,7 +152,7 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
mock(SecureStorageClient.class),
|
||||
mock(SecureValueRecoveryClient.class),
|
||||
disconnectionRequestManager,
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
Executors.newSingleThreadExecutor(),
|
||||
Executors.newSingleThreadScheduledExecutor(),
|
||||
Executors.newSingleThreadScheduledExecutor(),
|
||||
|
||||
+9
-3
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
@@ -60,7 +61,8 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
DynamoDbExtensionSchema.Tables.EC_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.PAGED_PQ_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_EC_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS);
|
||||
DynamoDbExtensionSchema.Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS,
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS);
|
||||
|
||||
@RegisterExtension
|
||||
static final RedisClusterExtension CACHE_CLUSTER_EXTENSION = RedisClusterExtension.builder().build();
|
||||
@@ -131,7 +133,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class);
|
||||
new PhoneNumberRecoveryPasswordsManager(new PhoneNumberRecoveryPasswords(
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
Clock.systemUTC()));
|
||||
|
||||
PUBSUB_SERVER_EXTENSION.getRedisClient().useConnection(connection -> {
|
||||
connection.sync().flushall();
|
||||
@@ -151,7 +157,7 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
secureStorageClient,
|
||||
svr2Client,
|
||||
mock(DisconnectionRequestManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
accountLockExecutor,
|
||||
scheduledExecutorService,
|
||||
scheduledExecutorService,
|
||||
|
||||
+1
-1
@@ -316,7 +316,7 @@ public final class DynamoDbExtensionSchema {
|
||||
.build()),
|
||||
List.of(), List.of()),
|
||||
|
||||
REGISTRATION_RECOVERY_PASSWORDS("registration_recovery_passwords_test",
|
||||
PHONE_NUMBER_RECOVERY_PASSWORDS("registration_recovery_passwords_test",
|
||||
PhoneNumberRecoveryPasswords.KEY_PNI,
|
||||
null,
|
||||
List.of(AttributeDefinition.builder()
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ class PhoneNumberRecoveryPasswordsTest {
|
||||
|
||||
@RegisterExtension
|
||||
static final DynamoDbExtension DYNAMO_DB_EXTENSION = new DynamoDbExtension(
|
||||
DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS
|
||||
);
|
||||
|
||||
private PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords;
|
||||
@@ -32,7 +32,7 @@ class PhoneNumberRecoveryPasswordsTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
phoneNumberRecoveryPasswords = new PhoneNumberRecoveryPasswords(
|
||||
DynamoDbExtensionSchema.Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(),
|
||||
DynamoDbExtensionSchema.Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
Duration.ofDays(1),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+3
-3
@@ -39,7 +39,7 @@ public class RegistrationRecoveryTest {
|
||||
|
||||
@RegisterExtension
|
||||
private static final DynamoDbExtension DYNAMO_DB_EXTENSION =
|
||||
new DynamoDbExtension(Tables.REGISTRATION_RECOVERY_PASSWORDS);
|
||||
new DynamoDbExtension(Tables.PHONE_NUMBER_RECOVERY_PASSWORDS);
|
||||
|
||||
private PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class RegistrationRecoveryTest {
|
||||
public void before() throws Exception {
|
||||
CLOCK.setTimeMillis(Clock.systemUTC().millis());
|
||||
phoneNumberRecoveryPasswords = new PhoneNumberRecoveryPasswords(
|
||||
Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(),
|
||||
Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName(),
|
||||
EXPIRATION,
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient(),
|
||||
CLOCK
|
||||
@@ -139,7 +139,7 @@ public class RegistrationRecoveryTest {
|
||||
|
||||
private static long fetchTimestamp(final UUID phoneNumberIdentifier) {
|
||||
final GetItemResponse getItemResponse = DYNAMO_DB_EXTENSION.getDynamoDbClient().getItem(GetItemRequest.builder()
|
||||
.tableName(Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName())
|
||||
.tableName(Tables.PHONE_NUMBER_RECOVERY_PASSWORDS.tableName())
|
||||
.key(Map.of(PhoneNumberRecoveryPasswords.KEY_PNI, AttributeValues.fromString(phoneNumberIdentifier.toString())))
|
||||
.build());
|
||||
|
||||
|
||||
Reference in new issue
Block a user