diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java index e52aa3d1f..378ee0fa9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java @@ -334,9 +334,9 @@ public class RegistrationController { throw new BadRequestException("login purchases are not enabled"); } - if (registrationRequest.accountAttributes().recoveryPassword().isEmpty()) { - throw new WebApplicationException("Account recovery password is required", 422); - } + registrationRequest.accountAttributes().recoveryPassword() + .filter(ArrayUtils::isNotEmpty) + .orElseThrow(() -> new WebApplicationException("Account recovery password is required", 422)); final ReceiptCredentialPresentation receiptCredentialPresentation; try { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java index d1df90b15..0128c3502 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java @@ -60,6 +60,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import org.junitpioneer.jupiter.cartesian.ArgumentSets; import org.junitpioneer.jupiter.cartesian.CartesianTest; @@ -1022,19 +1023,22 @@ class RegistrationControllerTest { } - @Test - void registerAccountMissingRecoveryPassword() throws Exception { + @ParameterizedTest + @NullSource + @ValueSource(ints = 0) + void registerAccountMissingRecoveryPassword(@Nullable final Integer recoveryPasswordLength) throws Exception { final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate(); final IdentityKey aciIdentityKey = new IdentityKey(aciIdentityKeyPair.getPublicKey()); final AccountAttributes accountAttributes = new AccountAttributes(true, 1, null, "test".getBytes(StandardCharsets.UTF_8), null, false, - DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES, null) + DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES, + recoveryPasswordLength == null ? null : new byte[recoveryPasswordLength]) .setUnidentifiedAccessKey(TestRandomUtil.nextBytes(16)); final RegistrationRequest registrationRequest = new RegistrationRequest(null, new byte[0], - receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), 1).serialize(), + receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), ReceiptLevel.LOGIN.getValue()).serialize(), null, accountAttributes, true,