From 0e0c0c5dfe0ba55ad81ad8adcd7991eef8598c7c Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Thu, 20 Apr 2023 19:11:33 -0500 Subject: [PATCH] return 400 instead of 503 for bad verification session-id --- .../controllers/VerificationController.java | 2 +- .../VerificationControllerTest.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 34611996b..de7897136 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java @@ -623,7 +623,7 @@ public class VerificationController { } catch (final CompletionException | CancellationException e) { final Throwable unwrapped = ExceptionUtils.unwrap(e); - if (unwrapped.getCause() instanceof StatusRuntimeException grpcRuntimeException) { + if (unwrapped instanceof StatusRuntimeException grpcRuntimeException) { if (grpcRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT) { throw new BadRequestException(); } 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 3e805027a..1b0db7350 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java @@ -25,6 +25,8 @@ import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import io.dropwizard.testing.junit5.ResourceExtension; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Clock; @@ -67,9 +69,9 @@ import org.whispersystems.textsecuregcm.registration.RegistrationServiceClient; import org.whispersystems.textsecuregcm.registration.RegistrationServiceException; import org.whispersystems.textsecuregcm.registration.RegistrationServiceSenderException; import org.whispersystems.textsecuregcm.registration.VerificationSession; +import org.whispersystems.textsecuregcm.spam.ScoreThresholdProvider; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; -import org.whispersystems.textsecuregcm.spam.ScoreThresholdProvider; import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; import org.whispersystems.textsecuregcm.storage.VerificationSessionManager; import org.whispersystems.textsecuregcm.util.SystemMapper; @@ -757,6 +759,20 @@ class VerificationControllerTest { } } + @Test + void getSessionInvalidArgs() { + when(registrationServiceClient.getSession(any(), any())) + .thenReturn(CompletableFuture.failedFuture(new StatusRuntimeException(Status.INVALID_ARGUMENT))); + + final Invocation.Builder request = resources.getJerseyTest() + .target("/v1/verification/session/" + encodeSessionId(SESSION_ID)) + .request() + .header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1"); + try (Response response = request.get()) { + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + } + } + @Test void getSessionNotFound() { when(registrationServiceClient.getSession(any(), any()))