From f83efce4d42d837c4ea0b8097f13d62bec33948f Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 20 May 2026 11:32:11 -0400 Subject: [PATCH] Add a phased enrollment mechanism for verification code push notifications --- .../textsecuregcm/WhisperServerService.java | 2 +- .../controllers/VerificationController.java | 16 +++++++++++-- .../VerificationControllerTest.java | 23 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 33a835b36..ac2d23afa 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -1170,7 +1170,7 @@ public class WhisperServerService extends Application 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 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) { 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 345d54e1d..f785a21fa 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java @@ -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());