mirror of
https://github.com/signalapp/Signal-Server
synced 2026-08-22 01:07:26 +01:00
Return 422 rather than 500 for an empty account recovery password
This commit is contained in:
+3
-3
@@ -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 {
|
||||
|
||||
+8
-4
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user