Add a phased enrollment mechanism for verification code push notifications

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-05-20 12:20:00 -04:00
1 parent 0945e953f2
commit f83efce4d4
3 files changed
+33 -8

No files matched your search

@@ -1170,7 +1170,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
new VerificationController(registrationServiceClient, new VerificationSessionManager(verificationSessions),
pushNotificationManager, registrationCaptchaManager, registrationRecoveryPasswordsManager,
phoneNumberIdentifiers, rateLimiters, accountsManager, carrierDataProvider, registrationFraudChecker,
dynamicConfigurationManager, clock)
dynamicConfigurationManager, experimentEnrollmentManager, clock)
);
if (config.getSubscription() != null && config.getOneTimeDonations() != null) {
SubscriptionManager subscriptionManager = new SubscriptionManager(subscriptions,
@@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.controllers;
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
import com.google.common.annotations.VisibleForTesting;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
@@ -74,7 +75,9 @@ import org.whispersystems.textsecuregcm.entities.SubmitVerificationCodeRequest;
import org.whispersystems.textsecuregcm.entities.UpdateVerificationSessionRequest;
import org.whispersystems.textsecuregcm.entities.VerificationCodeRequest;
import org.whispersystems.textsecuregcm.entities.VerificationSessionResponse;
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
import org.whispersystems.textsecuregcm.filters.RemoteAddressFilter;
import org.whispersystems.textsecuregcm.identity.IdentityType;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.mappers.RegistrationServiceSenderExceptionMapper;
import org.whispersystems.textsecuregcm.metrics.CaptchaMetrics;
@@ -133,6 +136,9 @@ public class VerificationController {
private static final String EXISTING_ACCOUNT_PLATFORM = "existingAccountPlatform";
private static final String EXISTING_ACCOUNT_RECENTLY_SEEN_TAG_NAME = "existingAccountRecentlySeen";
@VisibleForTesting
static final String VERIFICATION_CODE_PUSH_NOTIFICATION_EXPERIMENT_NAME = "verificationCodePushNotification";
private final RegistrationServiceClient registrationServiceClient;
private final VerificationSessionManager verificationSessionManager;
private final PushNotificationManager pushNotificationManager;
@@ -144,6 +150,7 @@ public class VerificationController {
private final CarrierDataProvider carrierDataProvider;
private final RegistrationFraudChecker registrationFraudChecker;
private final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager;
private final ExperimentEnrollmentManager experimentEnrollmentManager;
private final Clock clock;
public VerificationController(final RegistrationServiceClient registrationServiceClient,
@@ -157,6 +164,7 @@ public class VerificationController {
final CarrierDataProvider carrierDataProvider,
final RegistrationFraudChecker registrationFraudChecker,
final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager,
final ExperimentEnrollmentManager experimentEnrollmentManager,
final Clock clock) {
this.registrationServiceClient = registrationServiceClient;
this.verificationSessionManager = verificationSessionManager;
@@ -169,6 +177,7 @@ public class VerificationController {
this.carrierDataProvider = carrierDataProvider;
this.registrationFraudChecker = registrationFraudChecker;
this.dynamicConfigurationManager = dynamicConfigurationManager;
this.experimentEnrollmentManager = experimentEnrollmentManager;
this.clock = clock;
}
@@ -657,8 +666,11 @@ public class VerificationController {
senderOverride,
REGISTRATION_RPC_TIMEOUT).join();
accountsManager.getByE164(registrationServiceSession.number()).ifPresent(existingAccount ->
pushNotificationManager.trySendVerificationCodeRequestedNotifications(existingAccount, clock.instant()));
accountsManager.getByE164(registrationServiceSession.number())
.filter(existingAccount ->
experimentEnrollmentManager.isEnrolled(existingAccount.getIdentifier(IdentityType.ACI), VERIFICATION_CODE_PUSH_NOTIFICATION_EXPERIMENT_NAME))
.ifPresent(existingAccount ->
pushNotificationManager.trySendVerificationCodeRequestedNotifications(existingAccount, clock.instant()));
} catch (final CancellationException e) {
throw new ServerErrorException("registration service unavailable", Response.Status.SERVICE_UNAVAILABLE);
} catch (final CompletionException e) {
@@ -57,6 +57,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junitpioneer.jupiter.cartesian.CartesianTest;
import org.mockito.ArgumentCaptor;
import org.whispersystems.textsecuregcm.captcha.AssessmentResult;
import org.whispersystems.textsecuregcm.captcha.RegistrationCaptchaManager;
@@ -65,6 +66,8 @@ import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfigurati
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicRegistrationConfiguration;
import org.whispersystems.textsecuregcm.entities.RegistrationServiceSession;
import org.whispersystems.textsecuregcm.entities.VerificationSessionResponse;
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
import org.whispersystems.textsecuregcm.identity.IdentityType;
import org.whispersystems.textsecuregcm.limits.RateLimiter;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.mappers.ImpossiblePhoneNumberExceptionMapper;
@@ -112,6 +115,7 @@ class VerificationControllerTest {
private final RateLimiters rateLimiters = mock(RateLimiters.class);
private final AccountsManager accountsManager = mock(AccountsManager.class);
private final CarrierDataProvider carrierDataProvider = mock(CarrierDataProvider.class);
private final ExperimentEnrollmentManager experimentEnrollmentManager = mock(ExperimentEnrollmentManager.class);
private final Clock clock = TestClock.pinned(Instant.now());
private final RateLimiter captchaLimiter = mock(RateLimiter.class);
@@ -133,7 +137,7 @@ class VerificationControllerTest {
.addResource(
new VerificationController(registrationServiceClient, verificationSessionManager, pushNotificationManager,
registrationCaptchaManager, registrationRecoveryPasswordsManager, phoneNumberIdentifiers, rateLimiters, accountsManager,
carrierDataProvider, RegistrationFraudChecker.noop(), dynamicConfigurationManager, clock))
carrierDataProvider, RegistrationFraudChecker.noop(), dynamicConfigurationManager, experimentEnrollmentManager, clock))
.build();
@BeforeEach
@@ -152,6 +156,8 @@ class VerificationControllerTest {
.thenReturn(dynamicConfiguration);
when(phoneNumberIdentifiers.getPhoneNumberIdentifier(NUMBER))
.thenReturn(CompletableFuture.completedFuture(PNI));
when(experimentEnrollmentManager.isEnrolled(any(UUID.class), eq(VerificationController.VERIFICATION_CODE_PUSH_NOTIFICATION_EXPERIMENT_NAME)))
.thenReturn(true);
}
@ParameterizedTest
@@ -1126,9 +1132,9 @@ class VerificationControllerTest {
}
}
@ParameterizedTest
@ValueSource(booleans = {true, false})
void requestVerificationCodeSuccess(final boolean accountExistsWithNumber) {
@CartesianTest
void requestVerificationCodeSuccess(@CartesianTest.Values(booleans = {true, false}) final boolean accountExistsWithNumber,
@CartesianTest.Values(booleans = {true, false}) final boolean enrolledInExperiment) {
final String encodedSessionId = encodeSessionId(SESSION_ID);
final RegistrationServiceSession registrationServiceSession = new RegistrationServiceSession(SESSION_ID, NUMBER,
false, null, null,
@@ -1142,15 +1148,22 @@ class VerificationControllerTest {
when(registrationServiceClient.sendVerificationCode(any(), any(), any(), any(), any(), any()))
.thenReturn(CompletableFuture.completedFuture(registrationServiceSession));
final UUID accountIdentifier = UUID.randomUUID();
final Account existingAccount = mock(Account.class);
when(existingAccount.getIdentifier(IdentityType.ACI)).thenReturn(accountIdentifier);
when(accountsManager.getByE164(any()))
.thenReturn(accountExistsWithNumber ? Optional.of(existingAccount) : Optional.empty());
when(experimentEnrollmentManager.isEnrolled(accountIdentifier, VerificationController.VERIFICATION_CODE_PUSH_NOTIFICATION_EXPERIMENT_NAME))
.thenReturn(enrolledInExperiment);
final Invocation.Builder request = resources.getJerseyTest()
.target("/v1/verification/session/" + encodedSessionId + "/code")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1");
try (Response response = request.post(Entity.json(requestVerificationCodeJson("sms", "android")))) {
assertEquals(HttpStatus.SC_OK, response.getStatus());
@@ -1160,7 +1173,7 @@ class VerificationControllerTest {
assertTrue(verificationSessionResponse.allowedToRequestCode());
assertTrue(verificationSessionResponse.requestedInformation().isEmpty());
if (accountExistsWithNumber) {
if (accountExistsWithNumber && enrolledInExperiment) {
verify(pushNotificationManager).trySendVerificationCodeRequestedNotifications(existingAccount, clock.instant());
} else {
verify(pushNotificationManager, never()).trySendVerificationCodeRequestedNotifications(any(), any());