From f4f2ffff21bbcf788545303c67a31c852ba7cd31 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 3 Aug 2026 12:39:28 -0400 Subject: [PATCH] Reframe "registration recovery passwords" as "phone number recovery passwords" --- .../signal/integration/IntegrationTools.java | 16 ++++---- .../textsecuregcm/WhisperServerService.java | 23 ++++++----- .../auth/PhoneVerificationTokenManager.java | 10 ++--- .../RegistrationLockVerificationManager.java | 10 ++--- .../controllers/AccountController.java | 10 ++--- .../controllers/VerificationController.java | 12 +++--- .../grpc/AccountsGrpcService.java | 10 ++--- .../storage/AccountsManager.java | 10 ++--- ...java => PhoneNumberRecoveryPasswords.java} | 6 +-- ... PhoneNumberRecoveryPasswordsManager.java} | 14 +++---- .../workers/CommandDependencies.java | 16 ++++---- .../PhoneVerificationTokenManagerTest.java | 14 +++---- ...gistrationLockVerificationManagerTest.java | 16 ++++---- .../controllers/AccountControllerTest.java | 10 ++--- .../VerificationControllerTest.java | 16 ++++---- .../grpc/AccountsGrpcServiceTest.java | 8 ++-- ...ccountCreationDeletionIntegrationTest.java | 6 +-- ...ntsManagerChangeNumberIntegrationTest.java | 6 +-- ...ConcurrentModificationIntegrationTest.java | 2 +- ...sManagerDeviceTransferIntegrationTest.java | 2 +- .../storage/AccountsManagerTest.java | 6 +-- ...ccountsManagerUsernameIntegrationTest.java | 2 +- .../AddRemoveDeviceIntegrationTest.java | 6 +-- .../storage/DynamoDbExtensionSchema.java | 4 +- .../storage/RegistrationRecoveryTest.java | 40 +++++++++---------- 25 files changed, 138 insertions(+), 137 deletions(-) rename service/src/main/java/org/whispersystems/textsecuregcm/storage/{RegistrationRecoveryPasswords.java => PhoneNumberRecoveryPasswords.java} (96%) rename service/src/main/java/org/whispersystems/textsecuregcm/storage/{RegistrationRecoveryPasswordsManager.java => PhoneNumberRecoveryPasswordsManager.java} (60%) diff --git a/integration-tests/src/main/java/org/signal/integration/IntegrationTools.java b/integration-tests/src/main/java/org/signal/integration/IntegrationTools.java index b736abd22..af238e9ca 100644 --- a/integration-tests/src/main/java/org/signal/integration/IntegrationTools.java +++ b/integration-tests/src/main/java/org/signal/integration/IntegrationTools.java @@ -17,8 +17,8 @@ import org.whispersystems.textsecuregcm.metrics.NoopAwsSdkMetricPublisher; import org.whispersystems.textsecuregcm.registration.VerificationSession; import org.whispersystems.textsecuregcm.storage.ChangeNumberWaitingPeriods; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswords; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswords; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.VerificationSessionManager; import org.whispersystems.textsecuregcm.storage.VerificationSessions; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; @@ -28,7 +28,7 @@ import software.amazon.awssdk.services.dynamodb.DynamoDbClient; public class IntegrationTools { - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private final VerificationSessionManager verificationSessionManager; @@ -45,14 +45,14 @@ public class IntegrationTools { final DynamoDbClient dynamoDbClient = config.dynamoDbClient().buildSyncClient(credentialsProvider, new NoopAwsSdkMetricPublisher()); - final RegistrationRecoveryPasswords registrationRecoveryPasswords = new RegistrationRecoveryPasswords( + final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords = new PhoneNumberRecoveryPasswords( config.dynamoDbTables().registrationRecovery(), Duration.ofDays(1), dynamoDbClient, Clock.systemUTC()); final VerificationSessions verificationSessions = new VerificationSessions( dynamoDbClient, config.dynamoDbTables().verificationSessions(), Clock.systemUTC()); return new IntegrationTools( - new RegistrationRecoveryPasswordsManager(registrationRecoveryPasswords), + new PhoneNumberRecoveryPasswordsManager(phoneNumberRecoveryPasswords), new VerificationSessionManager(verificationSessions), new PhoneNumberIdentifiers(dynamoDbAsyncClient, config.dynamoDbTables().phoneNumberIdentifiers()), new ChangeNumberWaitingPeriods(config.dynamoDbTables().changeNumberWaitingPeriods(), dynamoDbClient) @@ -60,11 +60,11 @@ public class IntegrationTools { } private IntegrationTools( - final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, final VerificationSessionManager verificationSessionManager, final PhoneNumberIdentifiers phoneNumberIdentifiers, final ChangeNumberWaitingPeriods changeNumberWaitingPeriods) { - this.registrationRecoveryPasswordsManager = registrationRecoveryPasswordsManager; + this.phoneNumberRecoveryPasswordsManager = phoneNumberRecoveryPasswordsManager; this.verificationSessionManager = verificationSessionManager; this.phoneNumberIdentifiers = phoneNumberIdentifiers; this.changeNumberWaitingPeriods = changeNumberWaitingPeriods; @@ -74,7 +74,7 @@ public class IntegrationTools { try { final UUID pni = phoneNumberIdentifiers .getPhoneNumberIdentifier(phoneNumber).get(5, TimeUnit.SECONDS); - registrationRecoveryPasswordsManager.store(pni, password); + phoneNumberRecoveryPasswordsManager.store(pni, password); } catch (ExecutionException | InterruptedException | TimeoutException e) { throw new RuntimeException("failed to get pni", e); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 0002394ed..3d65c9d4e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -277,8 +277,8 @@ import org.whispersystems.textsecuregcm.storage.ProfilesManager; import org.whispersystems.textsecuregcm.storage.ProfilesV2; import org.whispersystems.textsecuregcm.storage.PushChallengeDynamoDb; import org.whispersystems.textsecuregcm.storage.RedeemedReceiptsManager; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswords; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswords; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.RemoteConfigs; import org.whispersystems.textsecuregcm.storage.RemoteConfigsManager; import org.whispersystems.textsecuregcm.storage.RepeatedUseECSignedPreKeyStore; @@ -581,7 +581,7 @@ public class WhisperServerService extends Application authenticatedServices = Stream.of( - new AccountsGrpcService(accountsManager, rateLimiters, usernameHashZkProofVerifier, registrationRecoveryPasswordsManager, Clock.systemUTC(), changeNumberManager), + new AccountsGrpcService(accountsManager, rateLimiters, usernameHashZkProofVerifier, + phoneNumberRecoveryPasswordsManager, Clock.systemUTC(), changeNumberManager), new CallingGrpcService(cloudflareTurnCredentialsManager, rateLimiters), new CredentialsGrpcService(accountsManager, certificateGenerator, zkAuthOperations, callingGenericZkSecretParams, rateLimiters, Clock.systemUTC(), ExternalServiceDefinitions.createExternalServiceList(config, Clock.systemUTC())), new KeysGrpcService(accountsManager, keysManager, rateLimiters), @@ -1242,7 +1243,7 @@ public class WhisperServerService extends Application commonControllers = Lists.newArrayList( - new AccountController(accountsManager, rateLimiters, registrationRecoveryPasswordsManager, + new AccountController(accountsManager, rateLimiters, phoneNumberRecoveryPasswordsManager, usernameHashZkProofVerifier), new AccountControllerV2(accountsManager, changeNumberManager), new AttachmentControllerV4(rateLimiters, gcsAttachmentGenerator, tusAttachmentGenerator, @@ -1276,7 +1277,7 @@ public class WhisperServerService extends Application deviceIds = updatedAccount.getDevices().stream().map(Device::getId).toList(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java index 17075ee49..31a3792e3 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java @@ -66,7 +66,7 @@ import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.UsernameHashNotAvailableException; import org.whispersystems.textsecuregcm.storage.UsernameReservationNotFoundException; import org.whispersystems.textsecuregcm.util.HeaderUtils; @@ -87,17 +87,17 @@ public class AccountController { private final AccountsManager accounts; private final RateLimiters rateLimiters; - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private final UsernameHashZkProofVerifier usernameHashZkProofVerifier; public AccountController( AccountsManager accounts, RateLimiters rateLimiters, - RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, UsernameHashZkProofVerifier usernameHashZkProofVerifier) { this.accounts = accounts; this.rateLimiters = rateLimiters; - this.registrationRecoveryPasswordsManager = registrationRecoveryPasswordsManager; + this.phoneNumberRecoveryPasswordsManager = phoneNumberRecoveryPasswordsManager; this.usernameHashZkProofVerifier = usernameHashZkProofVerifier; } @@ -247,7 +247,7 @@ public class AccountController { // if registration recovery password was sent to us, store it (or refresh its expiration) attributes.recoveryPassword().ifPresent(registrationRecoveryPassword -> { - final boolean rrpCreated = registrationRecoveryPasswordsManager + final boolean rrpCreated = phoneNumberRecoveryPasswordsManager .store(updatedAccount.getIdentifier(IdentityType.PNI), registrationRecoveryPassword); Metrics.counter(RECOVERY_PASSWORD_SET_COUNTER_NAME, Tags.of( UserAgentTagUtil.getPlatformTag(userAgent), diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java index a90763007..100b496f5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java @@ -97,7 +97,7 @@ import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.VerificationSessionManager; import org.whispersystems.textsecuregcm.telephony.CarrierData; import org.whispersystems.textsecuregcm.telephony.CarrierDataException; @@ -139,7 +139,7 @@ public class VerificationController { private final VerificationSessionManager verificationSessionManager; private final PushNotificationManager pushNotificationManager; private final RegistrationCaptchaManager registrationCaptchaManager; - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private final PhoneNumberIdentifiers phoneNumberIdentifiers; private final RateLimiters rateLimiters; private final AccountsManager accountsManager; @@ -153,7 +153,7 @@ public class VerificationController { final VerificationSessionManager verificationSessionManager, final PushNotificationManager pushNotificationManager, final RegistrationCaptchaManager registrationCaptchaManager, - final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, final PhoneNumberIdentifiers phoneNumberIdentifiers, final RateLimiters rateLimiters, final AccountsManager accountsManager, @@ -166,7 +166,7 @@ public class VerificationController { this.verificationSessionManager = verificationSessionManager; this.pushNotificationManager = pushNotificationManager; this.registrationCaptchaManager = registrationCaptchaManager; - this.registrationRecoveryPasswordsManager = registrationRecoveryPasswordsManager; + this.phoneNumberRecoveryPasswordsManager = phoneNumberRecoveryPasswordsManager; this.phoneNumberIdentifiers = phoneNumberIdentifiers; this.rateLimiters = rateLimiters; this.accountsManager = accountsManager; @@ -749,7 +749,7 @@ public class VerificationController { // the RRP. It's possible the client will not actually be able to register (e.g. failed reglock challenge), and // so we will have removed the RRP unnecessarily. The impact of this is low, since the owner of the RRP // can always just fallback to session-based verification. - existingRRP = registrationRecoveryPasswordsManager.remove(phoneNumberIdentifiers.getPhoneNumberIdentifier(registrationServiceSession.number()).join()); + existingRRP = phoneNumberRecoveryPasswordsManager.remove(phoneNumberIdentifiers.getPhoneNumberIdentifier(registrationServiceSession.number()).join()); } Optional maybeExistingAccount; @@ -824,7 +824,7 @@ public class VerificationController { // the RRP. It's possible the client will not actually be able to register (e.g. failed reglock challenge), and // so we will have removed the RRP unnecessarily. The impact of this is low, since the owner of the RRP // can always just fallback to session-based verification. - registrationRecoveryPasswordsManager.remove(phoneNumberIdentifiers.getPhoneNumberIdentifier(registrationServiceSession.number()).join()); + phoneNumberRecoveryPasswordsManager.remove(phoneNumberIdentifiers.getPhoneNumberIdentifier(registrationServiceSession.number()).join()); } return registrationServiceSession; diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java index 1b13b5c0f..ca5848c20 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java @@ -91,7 +91,7 @@ import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.ChangeNumberManager; import org.whispersystems.textsecuregcm.storage.DeviceCapability; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.UsernameHashNotAvailableException; import org.whispersystems.textsecuregcm.storage.UsernameReservationNotFoundException; import org.whispersystems.textsecuregcm.util.RegistrationIdValidator; @@ -106,21 +106,21 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { private final AccountsManager accountsManager; private final RateLimiters rateLimiters; private final UsernameHashZkProofVerifier usernameHashZkProofVerifier; - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private final Clock clock; private final ChangeNumberManager changeNumberManager; public AccountsGrpcService(final AccountsManager accountsManager, final RateLimiters rateLimiters, final UsernameHashZkProofVerifier usernameHashZkProofVerifier, - final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, final Clock clock, final ChangeNumberManager changeNumberManager) { this.accountsManager = accountsManager; this.rateLimiters = rateLimiters; this.usernameHashZkProofVerifier = usernameHashZkProofVerifier; - this.registrationRecoveryPasswordsManager = registrationRecoveryPasswordsManager; + this.phoneNumberRecoveryPasswordsManager = phoneNumberRecoveryPasswordsManager; this.clock = clock; this.changeNumberManager = changeNumberManager; } @@ -321,7 +321,7 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { @Override public SetRegistrationRecoveryPasswordResponse setRegistrationRecoveryPassword(final SetRegistrationRecoveryPasswordRequest request) { - registrationRecoveryPasswordsManager.store(getAuthenticatedAccount().getIdentifier(IdentityType.PNI), + phoneNumberRecoveryPasswordsManager.store(getAuthenticatedAccount().getIdentifier(IdentityType.PNI), request.getRegistrationRecoveryPassword().toByteArray()); return SetRegistrationRecoveryPasswordResponse.getDefaultInstance(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index 120867c7c..2f529d041 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -133,7 +133,7 @@ public class AccountsManager extends RedisPubSubAdapter implemen private final SecureStorageClient secureStorageClient; private final SecureValueRecoveryClient secureValueRecovery2Client; private final DisconnectionRequestManager disconnectionRequestManager; - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private final Executor accountLockExecutor; private final ScheduledExecutorService messagesPollExecutor; private final ScheduledExecutorService retryExecutor; @@ -215,7 +215,7 @@ public class AccountsManager extends RedisPubSubAdapter implemen final SecureStorageClient secureStorageClient, final SecureValueRecoveryClient secureValueRecovery2Client, final DisconnectionRequestManager disconnectionRequestManager, - final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, final Executor accountLockExecutor, final ScheduledExecutorService messagesPollExecutor, final ScheduledExecutorService retryExecutor, final Clock clock, @@ -232,7 +232,7 @@ public class AccountsManager extends RedisPubSubAdapter implemen this.secureStorageClient = secureStorageClient; this.secureValueRecovery2Client = secureValueRecovery2Client; this.disconnectionRequestManager = disconnectionRequestManager; - this.registrationRecoveryPasswordsManager = requireNonNull(registrationRecoveryPasswordsManager); + this.phoneNumberRecoveryPasswordsManager = requireNonNull(phoneNumberRecoveryPasswordsManager); this.accountLockExecutor = accountLockExecutor; this.messagesPollExecutor = messagesPollExecutor; this.retryExecutor = retryExecutor; @@ -413,7 +413,7 @@ public class AccountsManager extends RedisPubSubAdapter implemen redisSet(account); final boolean rrpCreated = accountAttributes.recoveryPassword().map(registrationRecoveryPassword -> - registrationRecoveryPasswordsManager + phoneNumberRecoveryPasswordsManager .store(account.getIdentifier(IdentityType.PNI), registrationRecoveryPassword)) .orElse(false); @@ -1217,7 +1217,7 @@ public class AccountsManager extends RedisPubSubAdapter implemen profilesManager.deleteAll(account.getAccountIdentifier(), true)) .join(); - registrationRecoveryPasswordsManager.remove(account.getIdentifier(IdentityType.PNI)); + phoneNumberRecoveryPasswordsManager.remove(account.getIdentifier(IdentityType.PNI)); accounts.delete(account.getAccountIdentifier(), additionalWriteItems); redisDelete(account); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswords.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswords.java similarity index 96% rename from service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswords.java rename to service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswords.java index a9ff277a4..114d93fee 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswords.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswords.java @@ -25,7 +25,7 @@ import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; import software.amazon.awssdk.services.dynamodb.model.PutItemResponse; import software.amazon.awssdk.services.dynamodb.model.ReturnValue; -public class RegistrationRecoveryPasswords { +public class PhoneNumberRecoveryPasswords { // For historical reasons, we record the PNI as a UUID string rather than a compact byte array static final String KEY_PNI = "P"; @@ -41,7 +41,7 @@ public class RegistrationRecoveryPasswords { private final Clock clock; - public RegistrationRecoveryPasswords( + public PhoneNumberRecoveryPasswords( final String tableName, final Duration expiration, final DynamoDbClient dynamoDbClient, @@ -62,7 +62,7 @@ public class RegistrationRecoveryPasswords { return Optional.ofNullable(getItemResponse.item()) .filter(item -> item.containsKey(ATTR_SALT)) .filter(item -> item.containsKey(ATTR_HASH)) - .map(RegistrationRecoveryPasswords::saltedTokenHashFromItem); + .map(PhoneNumberRecoveryPasswords::saltedTokenHashFromItem); } /// Add a PNI -> RRP mapping, or replace the current one if it already exists diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswordsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswordsManager.java similarity index 60% rename from service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswordsManager.java rename to service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswordsManager.java index 1fe3e040a..16a10ed68 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryPasswordsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PhoneNumberRecoveryPasswordsManager.java @@ -11,16 +11,16 @@ import java.util.HexFormat; import java.util.UUID; import org.whispersystems.textsecuregcm.auth.SaltedTokenHash; -public class RegistrationRecoveryPasswordsManager { +public class PhoneNumberRecoveryPasswordsManager { - private final RegistrationRecoveryPasswords registrationRecoveryPasswords; + private final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords; - public RegistrationRecoveryPasswordsManager(final RegistrationRecoveryPasswords registrationRecoveryPasswords) { - this.registrationRecoveryPasswords = requireNonNull(registrationRecoveryPasswords); + public PhoneNumberRecoveryPasswordsManager(final PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords) { + this.phoneNumberRecoveryPasswords = requireNonNull(phoneNumberRecoveryPasswords); } public boolean verify(final UUID phoneNumberIdentifier, final byte[] password) { - return registrationRecoveryPasswords.lookup(phoneNumberIdentifier) + return phoneNumberRecoveryPasswords.lookup(phoneNumberIdentifier) .filter(hash -> hash.verify(bytesToString(password))).isPresent(); } @@ -28,11 +28,11 @@ public class RegistrationRecoveryPasswordsManager { final String token = bytesToString(password); final SaltedTokenHash tokenHash = SaltedTokenHash.generateFor(token); - return registrationRecoveryPasswords.addOrReplace(phoneNumberIdentifier, tokenHash); + return phoneNumberRecoveryPasswords.addOrReplace(phoneNumberIdentifier, tokenHash); } public boolean remove(final UUID phoneNumberIdentifier) { - return registrationRecoveryPasswords.removeEntry(phoneNumberIdentifier); + return phoneNumberRecoveryPasswords.removeEntry(phoneNumberIdentifier); } private static String bytesToString(final byte[] bytes) { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java index 626fe2814..a4c14b582 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java @@ -73,8 +73,8 @@ import org.whispersystems.textsecuregcm.storage.ProfileAvatars; import org.whispersystems.textsecuregcm.storage.Profiles; import org.whispersystems.textsecuregcm.storage.ProfilesManager; import org.whispersystems.textsecuregcm.storage.ProfilesV2; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswords; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswords; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.RepeatedUseECSignedPreKeyStore; import org.whispersystems.textsecuregcm.storage.RepeatedUseKEMSignedPreKeyStore; import org.whispersystems.textsecuregcm.storage.ReportMessageDynamoDb; @@ -107,7 +107,7 @@ public record CommandDependencies( MessagesCache messagesCache, MessagesManager messagesManager, KeysManager keysManager, - RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager, + PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager, APNSender apnSender, FcmSender fcmSender, PushNotificationManager pushNotificationManager, @@ -253,7 +253,7 @@ public record CommandDependencies( .build(); - RegistrationRecoveryPasswords registrationRecoveryPasswords = new RegistrationRecoveryPasswords( + PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords = new PhoneNumberRecoveryPasswords( configuration.getDynamoDbTables().getRegistrationRecovery().getTableName(), configuration.getDynamoDbTables().getRegistrationRecovery().getExpiration(), dynamoDbClient, @@ -340,8 +340,8 @@ public record CommandDependencies( reportMessageManager, messageDeletionExecutor, Clock.systemUTC(), experimentEnrollmentManager); AccountLockManager accountLockManager = new AccountLockManager(dynamoDbClient, configuration.getDynamoDbTables().getDeletedAccountsLock().getTableName()); - RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager = - new RegistrationRecoveryPasswordsManager(registrationRecoveryPasswords); + PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager = + new PhoneNumberRecoveryPasswordsManager(phoneNumberRecoveryPasswords); final ChangeNumberWaitingPeriods changeNumberWaitingPeriods = new ChangeNumberWaitingPeriods( configuration.getDynamoDbTables().getChangeNumberWaitingPeriods().getTableName(), dynamoDbClient); final ChangeNumberWaitingPeriodManager changeNumberWaitingPeriodManager = new ChangeNumberWaitingPeriodManager( @@ -349,7 +349,7 @@ public record CommandDependencies( AccountsManager accountsManager = new AccountsManager(accounts, phoneNumberIdentifiers, cacheCluster, pubsubClient, accountLockManager, keys, messagesManager, profilesManager, changeNumberWaitingPeriodManager, secureStorageClient, secureValueRecovery2Client, disconnectionRequestManager, - registrationRecoveryPasswordsManager, accountLockExecutor, messagePollExecutor, + phoneNumberRecoveryPasswordsManager, accountLockExecutor, messagePollExecutor, retryExecutor, clock, configuration.getLinkDeviceSecretConfiguration().secret().value()); RateLimiters rateLimiters = RateLimiters.create(dynamicConfigurationManager, rateLimitersCluster, retryExecutor); final BackupsDb backupsDb = @@ -434,7 +434,7 @@ public record CommandDependencies( messagesCache, messagesManager, keys, - registrationRecoveryPasswordsManager, + phoneNumberRecoveryPasswordsManager, apnSender, fcmSender, pushNotificationManager, diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneVerificationTokenManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneVerificationTokenManagerTest.java index 94e6b268f..2082d9846 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneVerificationTokenManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneVerificationTokenManagerTest.java @@ -31,13 +31,13 @@ import org.whispersystems.textsecuregcm.entities.RegistrationServiceSession; import org.whispersystems.textsecuregcm.registration.RegistrationServiceClient; import org.whispersystems.textsecuregcm.spam.RegistrationRecoveryChecker; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.util.TestRandomUtil; class PhoneVerificationTokenManagerTest { private RegistrationServiceClient registrationServiceClient; - private RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager; + private PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager; private RegistrationRecoveryChecker registrationRecoveryChecker; private PhoneNumberIdentifiers phoneNumberIdentifiers; @@ -55,12 +55,12 @@ class PhoneVerificationTokenManagerTest { .thenReturn(CompletableFuture.completedFuture(PHONE_NUMBER_IDENTIFIER)); registrationServiceClient = mock(RegistrationServiceClient.class); - registrationRecoveryPasswordsManager = mock(RegistrationRecoveryPasswordsManager.class); + phoneNumberRecoveryPasswordsManager = mock(PhoneNumberRecoveryPasswordsManager.class); registrationRecoveryChecker = mock(RegistrationRecoveryChecker.class); phoneVerificationTokenManager = new PhoneVerificationTokenManager(phoneNumberIdentifiers, registrationServiceClient, - registrationRecoveryPasswordsManager, + phoneNumberRecoveryPasswordsManager, registrationRecoveryChecker); } @@ -169,7 +169,7 @@ class PhoneVerificationTokenManagerTest { when(registrationRecoveryChecker.checkRegistrationRecoveryAttempt(PHONE_NUMBER, null, null, null)) .thenReturn(true); - when(registrationRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) + when(phoneNumberRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) .thenReturn(true); assertDoesNotThrow(() -> phoneVerificationTokenManager.verify( @@ -188,7 +188,7 @@ class PhoneVerificationTokenManagerTest { when(registrationRecoveryChecker.checkRegistrationRecoveryAttempt(PHONE_NUMBER, null, null, null)) .thenReturn(false); - when(registrationRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) + when(phoneNumberRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) .thenReturn(true); assertThrows(RecoveryPasswordVerificationFailedException.class, () -> phoneVerificationTokenManager.verify( @@ -207,7 +207,7 @@ class PhoneVerificationTokenManagerTest { when(registrationRecoveryChecker.checkRegistrationRecoveryAttempt(PHONE_NUMBER, null, null, null)) .thenReturn(true); - when(registrationRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) + when(phoneNumberRecoveryPasswordsManager.verify(PHONE_NUMBER_IDENTIFIER, recoveryPassword)) .thenReturn(false); assertThrows(RecoveryPasswordVerificationFailedException.class, () -> phoneVerificationTokenManager.verify( diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java index aec0afd2b..85ed68537 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java @@ -39,7 +39,7 @@ import org.whispersystems.textsecuregcm.push.PushNotificationManager; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; import org.whispersystems.textsecuregcm.util.Pair; @@ -49,12 +49,12 @@ class RegistrationLockVerificationManagerTest { private final DisconnectionRequestManager disconnectionRequestManager = mock(DisconnectionRequestManager.class); private final ExternalServiceCredentialsGenerator svr2CredentialsGenerator = mock( ExternalServiceCredentialsGenerator.class); - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager = mock( - RegistrationRecoveryPasswordsManager.class); + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager = mock( + PhoneNumberRecoveryPasswordsManager.class); private final PushNotificationManager pushNotificationManager = mock(PushNotificationManager.class); private final RateLimiters rateLimiters = mock(RateLimiters.class); private final RegistrationLockVerificationManager registrationLockVerificationManager = new RegistrationLockVerificationManager( - accountsManager, disconnectionRequestManager, svr2CredentialsGenerator, registrationRecoveryPasswordsManager, + accountsManager, disconnectionRequestManager, svr2CredentialsGenerator, phoneNumberRecoveryPasswordsManager, pushNotificationManager, rateLimiters); private final RateLimiter pinLimiter = mock(RateLimiter.class); @@ -104,9 +104,9 @@ class RegistrationLockVerificationManagerTest { yield new Pair<>(RegistrationLockFailureException.class, e -> { if (e instanceof RegistrationLockFailureException) { if (!verificationType.equals(PhoneVerificationRequest.VerificationType.RECOVERY_PASSWORD) || clientRegistrationLock != null) { - verify(registrationRecoveryPasswordsManager).remove(account.getIdentifier(IdentityType.PNI)); + verify(phoneNumberRecoveryPasswordsManager).remove(account.getIdentifier(IdentityType.PNI)); } else { - verify(registrationRecoveryPasswordsManager, never()).remove(any()); + verify(phoneNumberRecoveryPasswordsManager, never()).remove(any()); } verify(disconnectionRequestManager).requestDisconnection(account.getAccountIdentifier(), List.of(Device.PRIMARY_ID)); try { @@ -134,7 +134,7 @@ class RegistrationLockVerificationManagerTest { } catch (final NotPushRegisteredException ignored2) { } - verify(registrationRecoveryPasswordsManager, never()).remove(any()); + verify(phoneNumberRecoveryPasswordsManager, never()).remove(any()); verify(disconnectionRequestManager, never()).requestDisconnection(any(), any()); }); } @@ -172,7 +172,7 @@ class RegistrationLockVerificationManagerTest { PhoneVerificationRequest.VerificationType.SESSION)); verify(account, never()).lockAuthTokenHash(); - verify(registrationRecoveryPasswordsManager, never()).remove(any()); + verify(phoneNumberRecoveryPasswordsManager, never()).remove(any()); verify(disconnectionRequestManager, never()).requestDisconnection(any(), any()); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java index c4f80cfdf..a16e2fc2a 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java @@ -88,7 +88,7 @@ import org.whispersystems.textsecuregcm.storage.AccountBadge; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.storage.DeviceCapability; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.UsernameHashNotAvailableException; import org.whispersystems.textsecuregcm.storage.UsernameReservationNotFoundException; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; @@ -133,8 +133,8 @@ class AccountControllerTest { private static final Account senderRegLockAccount = mock(Account.class); private static final Account senderHasStorage = mock(Account.class); private static final Account senderTransfer = mock(Account.class); - private static final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager = - mock(RegistrationRecoveryPasswordsManager.class); + private static final PhoneNumberRecoveryPasswordsManager PHONE_NUMBER_RECOVERY_PASSWORDS_MANAGER = + mock(PhoneNumberRecoveryPasswordsManager.class); private static final UsernameHashZkProofVerifier usernameZkProofVerifier = mock(UsernameHashZkProofVerifier.class); private final byte[] registration_lock_key = new byte[32]; @@ -157,7 +157,7 @@ class AccountControllerTest { .addResource(new AccountController( accountsManager, rateLimiters, - registrationRecoveryPasswordsManager, + PHONE_NUMBER_RECOVERY_PASSWORDS_MANAGER, usernameZkProofVerifier )) .build(); @@ -856,7 +856,7 @@ class AccountControllerTest { .setRecoveryPassword(recoveryPassword)))) { assertThat(response.getStatus()).isEqualTo(204); - verify(registrationRecoveryPasswordsManager).store(AuthHelper.UNDISCOVERABLE_PNI, recoveryPassword); + verify(PHONE_NUMBER_RECOVERY_PASSWORDS_MANAGER).store(AuthHelper.UNDISCOVERABLE_PNI, recoveryPassword); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java index ea8d84fe7..ca67d1667 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java @@ -87,7 +87,7 @@ import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.VerificationSessionManager; import org.whispersystems.textsecuregcm.telephony.CarrierDataProvider; import org.whispersystems.textsecuregcm.util.SystemMapper; @@ -109,8 +109,8 @@ class VerificationControllerTest { private final VerificationSessionManager verificationSessionManager = mock(VerificationSessionManager.class); private final PushNotificationManager pushNotificationManager = mock(PushNotificationManager.class); private final RegistrationCaptchaManager registrationCaptchaManager = mock(RegistrationCaptchaManager.class); - private final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager = mock( - RegistrationRecoveryPasswordsManager.class); + private final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager = mock( + PhoneNumberRecoveryPasswordsManager.class); private final PhoneNumberIdentifiers phoneNumberIdentifiers = mock(PhoneNumberIdentifiers.class); private final RateLimiters rateLimiters = mock(RateLimiters.class); private final AccountsManager accountsManager = mock(AccountsManager.class); @@ -136,7 +136,7 @@ class VerificationControllerTest { .setTestContainerFactory(new GrizzlyWebTestContainerFactory()) .addResource( new VerificationController(registrationServiceClient, verificationSessionManager, pushNotificationManager, - registrationCaptchaManager, registrationRecoveryPasswordsManager, phoneNumberIdentifiers, rateLimiters, accountsManager, + registrationCaptchaManager, phoneNumberRecoveryPasswordsManager, phoneNumberIdentifiers, rateLimiters, accountsManager, carrierDataProvider, RegistrationFraudChecker.noop(), dynamicConfigurationManager, experimentEnrollmentManager, clock)) .build(); @@ -608,7 +608,7 @@ class VerificationControllerTest { assertTrue(verificationSessionResponse.verified()); assertTrue(verificationSessionResponse.requestedInformation().isEmpty()); - verify(registrationRecoveryPasswordsManager).remove(PNI); + verify(phoneNumberRecoveryPasswordsManager).remove(PNI); } } @@ -885,7 +885,7 @@ class VerificationControllerTest { try (Response response = request.get()) { assertEquals(HttpStatus.SC_OK, response.getStatus()); - verify(registrationRecoveryPasswordsManager).remove(PNI); + verify(phoneNumberRecoveryPasswordsManager).remove(PNI); } } @@ -1214,7 +1214,7 @@ class VerificationControllerTest { VerificationSessionResponse.class); assertTrue(verificationSessionResponse.verified()); - verify(registrationRecoveryPasswordsManager).remove(PNI); + verify(phoneNumberRecoveryPasswordsManager).remove(PNI); } } @@ -1335,7 +1335,7 @@ class VerificationControllerTest { assertTrue(verificationSessionResponse.verified()); - verify(registrationRecoveryPasswordsManager).remove(PNI); + verify(phoneNumberRecoveryPasswordsManager).remove(PNI); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java index 8c68c30dd..5d85c3828 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java @@ -111,7 +111,7 @@ import org.whispersystems.textsecuregcm.storage.ChangeNumberManager; import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.storage.DeviceCapability; import org.whispersystems.textsecuregcm.storage.KeyIdUtil; -import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; +import org.whispersystems.textsecuregcm.storage.PhoneNumberRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.UsernameHashNotAvailableException; import org.whispersystems.textsecuregcm.storage.UsernameReservationNotFoundException; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; @@ -134,7 +134,7 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest { connection.sync().flushall(); @@ -149,7 +149,7 @@ public class AddRemoveDeviceIntegrationTest { secureStorageClient, svr2Client, mock(DisconnectionRequestManager.class), - mock(RegistrationRecoveryPasswordsManager.class), + mock(PhoneNumberRecoveryPasswordsManager.class), accountLockExecutor, scheduledExecutorService, scheduledExecutorService, diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtensionSchema.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtensionSchema.java index e28cb977d..bf05fa441 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtensionSchema.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtensionSchema.java @@ -317,10 +317,10 @@ public final class DynamoDbExtensionSchema { List.of(), List.of()), REGISTRATION_RECOVERY_PASSWORDS("registration_recovery_passwords_test", - RegistrationRecoveryPasswords.KEY_PNI, + PhoneNumberRecoveryPasswords.KEY_PNI, null, List.of(AttributeDefinition.builder() - .attributeName(RegistrationRecoveryPasswords.KEY_PNI) + .attributeName(PhoneNumberRecoveryPasswords.KEY_PNI) .attributeType(ScalarAttributeType.S) .build()), List.of(), List.of()), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryTest.java index a75f284d0..14c0c7246 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/RegistrationRecoveryTest.java @@ -41,31 +41,31 @@ public class RegistrationRecoveryTest { private static final DynamoDbExtension DYNAMO_DB_EXTENSION = new DynamoDbExtension(Tables.REGISTRATION_RECOVERY_PASSWORDS); - private RegistrationRecoveryPasswords registrationRecoveryPasswords; + private PhoneNumberRecoveryPasswords phoneNumberRecoveryPasswords; - private RegistrationRecoveryPasswordsManager manager; + private PhoneNumberRecoveryPasswordsManager manager; @BeforeEach public void before() throws Exception { CLOCK.setTimeMillis(Clock.systemUTC().millis()); - registrationRecoveryPasswords = new RegistrationRecoveryPasswords( + phoneNumberRecoveryPasswords = new PhoneNumberRecoveryPasswords( Tables.REGISTRATION_RECOVERY_PASSWORDS.tableName(), EXPIRATION, DYNAMO_DB_EXTENSION.getDynamoDbClient(), CLOCK ); - manager = new RegistrationRecoveryPasswordsManager(registrationRecoveryPasswords); + manager = new PhoneNumberRecoveryPasswordsManager(phoneNumberRecoveryPasswords); } @Test public void testLookupAfterWrite() throws Exception { - assertTrue(registrationRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH)); + assertTrue(phoneNumberRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH)); final long initialExp = fetchTimestamp(PNI); final long expectedExpiration = CLOCK.instant().getEpochSecond() + EXPIRATION.getSeconds(); assertEquals(expectedExpiration, initialExp); - final Optional saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI); + final Optional saltedTokenHashByPni = phoneNumberRecoveryPasswords.lookup(PNI); assertTrue(saltedTokenHashByPni.isPresent()); assertEquals(ORIGINAL_HASH.salt(), saltedTokenHashByPni.get().salt()); assertEquals(ORIGINAL_HASH.hash(), saltedTokenHashByPni.get().hash()); @@ -73,15 +73,15 @@ public class RegistrationRecoveryTest { @Test public void testLookupAfterRefresh() throws Exception { - registrationRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); + phoneNumberRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); CLOCK.increment(50, TimeUnit.SECONDS); - registrationRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); + phoneNumberRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); final long updatedExp = fetchTimestamp(PNI); final long expectedExp = CLOCK.instant().getEpochSecond() + EXPIRATION.getSeconds(); assertEquals(expectedExp, updatedExp); - final Optional saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI); + final Optional saltedTokenHashByPni = phoneNumberRecoveryPasswords.lookup(PNI); assertTrue(saltedTokenHashByPni.isPresent()); assertEquals(ORIGINAL_HASH.salt(), saltedTokenHashByPni.get().salt()); assertEquals(ORIGINAL_HASH.hash(), saltedTokenHashByPni.get().hash()); @@ -89,10 +89,10 @@ public class RegistrationRecoveryTest { @Test public void testReplace() { - assertTrue(registrationRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH)); - assertFalse(registrationRecoveryPasswords.addOrReplace(PNI, ANOTHER_HASH)); + assertTrue(phoneNumberRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH)); + assertFalse(phoneNumberRecoveryPasswords.addOrReplace(PNI, ANOTHER_HASH)); - final Optional saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI); + final Optional saltedTokenHashByPni = phoneNumberRecoveryPasswords.lookup(PNI); assertTrue(saltedTokenHashByPni.isPresent()); assertEquals(ANOTHER_HASH.salt(), saltedTokenHashByPni.get().salt()); assertEquals(ANOTHER_HASH.hash(), saltedTokenHashByPni.get().hash()); @@ -100,13 +100,13 @@ public class RegistrationRecoveryTest { @Test public void testRemove() { - assertFalse(registrationRecoveryPasswords.removeEntry(PNI)); + assertFalse(phoneNumberRecoveryPasswords.removeEntry(PNI)); - registrationRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); - assertTrue(registrationRecoveryPasswords.lookup(PNI).isPresent()); + phoneNumberRecoveryPasswords.addOrReplace(PNI, ORIGINAL_HASH); + assertTrue(phoneNumberRecoveryPasswords.lookup(PNI).isPresent()); - assertTrue(registrationRecoveryPasswords.removeEntry(PNI)); - assertTrue(registrationRecoveryPasswords.lookup(PNI).isEmpty()); + assertTrue(phoneNumberRecoveryPasswords.removeEntry(PNI)); + assertTrue(phoneNumberRecoveryPasswords.lookup(PNI).isEmpty()); } @Test @@ -140,14 +140,14 @@ 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()) - .key(Map.of(RegistrationRecoveryPasswords.KEY_PNI, AttributeValues.fromString(phoneNumberIdentifier.toString()))) + .key(Map.of(PhoneNumberRecoveryPasswords.KEY_PNI, AttributeValues.fromString(phoneNumberIdentifier.toString()))) .build()); final Map item = getItemResponse.item(); - if (item == null || !item.containsKey(RegistrationRecoveryPasswords.ATTR_EXP)) { + if (item == null || !item.containsKey(PhoneNumberRecoveryPasswords.ATTR_EXP)) { throw new RuntimeException("Data not found"); } - final String exp = item.get(RegistrationRecoveryPasswords.ATTR_EXP).n(); + final String exp = item.get(PhoneNumberRecoveryPasswords.ATTR_EXP).n(); return Long.parseLong(exp); } }