mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Reframe "registration recovery passwords" as "phone number recovery passwords"
This commit is contained in:
1 parent
5b6d6f28c9
commit
f4f2ffff21
25 files changed
+138
-137
No files matched your search
+7
-7
@@ -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(
|
||||
|
||||
+8
-8
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -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<AccountsGrpcService, Ac
|
||||
private UsernameHashZkProofVerifier usernameHashZkProofVerifier;
|
||||
|
||||
@Mock
|
||||
private RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager;
|
||||
private PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager;
|
||||
|
||||
private final TestClock testClock = TestClock.pinned(Instant.now());
|
||||
|
||||
@@ -155,7 +155,7 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
return new AccountsGrpcService(accountsManager,
|
||||
rateLimiters,
|
||||
usernameHashZkProofVerifier,
|
||||
registrationRecoveryPasswordsManager,
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
testClock,
|
||||
changeNumberManager);
|
||||
}
|
||||
@@ -729,7 +729,7 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
.setRegistrationRecoveryPassword(ByteString.copyFrom(registrationRecoveryPassword))
|
||||
.build()));
|
||||
|
||||
verify(registrationRecoveryPasswordsManager).store(account.getIdentifier(IdentityType.PNI), registrationRecoveryPassword);
|
||||
verify(phoneNumberRecoveryPasswordsManager).store(account.getIdentifier(IdentityType.PNI), registrationRecoveryPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -131,8 +131,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final ProfilesManager profilesManager = mock(ProfilesManager.class);
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager =
|
||||
mock(RegistrationRecoveryPasswordsManager.class);
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class);
|
||||
|
||||
disconnectionRequestManager = mock(DisconnectionRequestManager.class);
|
||||
when(disconnectionRequestManager.requestDisconnection(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
@@ -150,7 +150,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
secureStorageClient,
|
||||
svr2Client,
|
||||
disconnectionRequestManager,
|
||||
registrationRecoveryPasswordsManager,
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
executor,
|
||||
executor,
|
||||
executor,
|
||||
|
||||
+3
-3
@@ -123,8 +123,8 @@ class AccountsManagerChangeNumberIntegrationTest {
|
||||
final ProfilesManager profilesManager = mock(ProfilesManager.class);
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager =
|
||||
mock(RegistrationRecoveryPasswordsManager.class);
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class);
|
||||
|
||||
accountsManager = new AccountsManager(
|
||||
accounts,
|
||||
@@ -139,7 +139,7 @@ class AccountsManagerChangeNumberIntegrationTest {
|
||||
secureStorageClient,
|
||||
svr2Client,
|
||||
disconnectionRequestManager,
|
||||
registrationRecoveryPasswordsManager,
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
executor,
|
||||
executor,
|
||||
executor,
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
mock(SecureStorageClient.class),
|
||||
mock(SecureValueRecoveryClient.class),
|
||||
mock(DisconnectionRequestManager.class),
|
||||
mock(RegistrationRecoveryPasswordsManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
mock(Executor.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class AccountsManagerDeviceTransferIntegrationTest {
|
||||
mock(SecureStorageClient.class),
|
||||
mock(SecureValueRecoveryClient.class),
|
||||
mock(DisconnectionRequestManager.class),
|
||||
mock(RegistrationRecoveryPasswordsManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
mock(ExecutorService.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
|
||||
+3
-3
@@ -195,8 +195,8 @@ class AccountsManagerTest {
|
||||
return task.get();
|
||||
}).when(accountLockManager).withLock(anySet(), any(), any());
|
||||
|
||||
final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager =
|
||||
mock(RegistrationRecoveryPasswordsManager.class);
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class);
|
||||
|
||||
when(keysManager.deleteSingleUsePreKeys(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(messagesManager.clear(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
@@ -228,7 +228,7 @@ class AccountsManagerTest {
|
||||
storageClient,
|
||||
svr2Client,
|
||||
disconnectionRequestManager,
|
||||
registrationRecoveryPasswordsManager,
|
||||
phoneNumberRecoveryPasswordsManager,
|
||||
mock(Executor.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
mock(ScheduledExecutorService.class),
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
mock(SecureStorageClient.class),
|
||||
mock(SecureValueRecoveryClient.class),
|
||||
disconnectionRequestManager,
|
||||
mock(RegistrationRecoveryPasswordsManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
Executors.newSingleThreadExecutor(),
|
||||
Executors.newSingleThreadScheduledExecutor(),
|
||||
Executors.newSingleThreadScheduledExecutor(),
|
||||
|
||||
+3
-3
@@ -128,8 +128,8 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
final ProfilesManager profilesManager = mock(ProfilesManager.class);
|
||||
when(profilesManager.deleteAll(any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final RegistrationRecoveryPasswordsManager registrationRecoveryPasswordsManager =
|
||||
mock(RegistrationRecoveryPasswordsManager.class);
|
||||
final PhoneNumberRecoveryPasswordsManager phoneNumberRecoveryPasswordsManager =
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class);
|
||||
|
||||
PUBSUB_SERVER_EXTENSION.getRedisClient().useConnection(connection -> {
|
||||
connection.sync().flushall();
|
||||
@@ -149,7 +149,7 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
secureStorageClient,
|
||||
svr2Client,
|
||||
mock(DisconnectionRequestManager.class),
|
||||
mock(RegistrationRecoveryPasswordsManager.class),
|
||||
mock(PhoneNumberRecoveryPasswordsManager.class),
|
||||
accountLockExecutor,
|
||||
scheduledExecutorService,
|
||||
scheduledExecutorService,
|
||||
|
||||
+2
-2
@@ -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()),
|
||||
|
||||
+20
-20
@@ -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<SaltedTokenHash> saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI);
|
||||
final Optional<SaltedTokenHash> 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<SaltedTokenHash> saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI);
|
||||
final Optional<SaltedTokenHash> 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<SaltedTokenHash> saltedTokenHashByPni = registrationRecoveryPasswords.lookup(PNI);
|
||||
final Optional<SaltedTokenHash> 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<String, AttributeValue> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user