Handle "transport not allowed" responses from the registration service

This commit is contained in:
Jon Chambers
2023-05-16 18:54:01 -04:00
committed by Jon Chambers
parent 3e53884979
commit 300ac16cf1
5 changed files with 64 additions and 2 deletions

View File

@@ -68,6 +68,7 @@ import org.whispersystems.textsecuregcm.push.PushNotificationManager;
import org.whispersystems.textsecuregcm.registration.RegistrationServiceClient;
import org.whispersystems.textsecuregcm.registration.RegistrationServiceException;
import org.whispersystems.textsecuregcm.registration.RegistrationServiceSenderException;
import org.whispersystems.textsecuregcm.registration.TransportNotAllowedException;
import org.whispersystems.textsecuregcm.registration.VerificationSession;
import org.whispersystems.textsecuregcm.spam.ScoreThresholdProvider;
import org.whispersystems.textsecuregcm.storage.Account;
@@ -983,6 +984,38 @@ class VerificationControllerTest {
}
}
@Test
void requestVerificationCodeTransportNotAllowed() {
final String encodedSessionId = encodeSessionId(SESSION_ID);
final RegistrationServiceSession registrationServiceSession = new RegistrationServiceSession(SESSION_ID, NUMBER,
false, null, null,
null, SESSION_EXPIRATION_SECONDS);
when(registrationServiceClient.getSession(any(), any()))
.thenReturn(CompletableFuture.completedFuture(Optional.of(registrationServiceSession)));
when(verificationSessionManager.findForId(any()))
.thenReturn(CompletableFuture.completedFuture(
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
when(registrationServiceClient.sendVerificationCode(any(), any(), any(), any(), any()))
.thenReturn(CompletableFuture.failedFuture(
new CompletionException(new TransportNotAllowedException(registrationServiceSession))));
final Invocation.Builder request = resources.getJerseyTest()
.target("/v1/verification/session/" + encodedSessionId + "/code")
.request()
.header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1");
try (final Response response = request.post(Entity.json(requestVerificationCodeJson("sms", "android")))) {
assertEquals(418, response.getStatus());
final VerificationSessionResponse verificationSessionResponse =
response.readEntity(VerificationSessionResponse.class);
assertTrue(verificationSessionResponse.allowedToRequestCode());
assertTrue(verificationSessionResponse.requestedInformation().isEmpty());
}
}
@Test
void requestVerificationCodeSuccess() {
final String encodedSessionId = encodeSessionId(SESSION_ID);