Return 422 rather than 500 for an empty account recovery password

This commit is contained in:
moiseev-signal
2026-08-20 15:55:16 -04:00
committed by GitHub
parent e8979082a7
commit 2bcecc7f7d
2 changed files with 11 additions and 7 deletions
@@ -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 {
@@ -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,