Remove legacy methods from `RegistrationServiceClient`
This commit is contained in:
parent
08c7baafac
commit
2c0fc8fe3e
|
@ -157,7 +157,7 @@ public class VerificationController {
|
||||||
|
|
||||||
final RegistrationServiceSession registrationServiceSession;
|
final RegistrationServiceSession registrationServiceSession;
|
||||||
try {
|
try {
|
||||||
registrationServiceSession = registrationServiceClient.createRegistrationSessionSession(phoneNumber,
|
registrationServiceSession = registrationServiceClient.createRegistrationSession(phoneNumber,
|
||||||
accountsManager.getByE164(request.getNumber()).isPresent(),
|
accountsManager.getByE164(request.getNumber()).isPresent(),
|
||||||
REGISTRATION_RPC_TIMEOUT).join();
|
REGISTRATION_RPC_TIMEOUT).join();
|
||||||
} catch (final CancellationException e) {
|
} catch (final CancellationException e) {
|
||||||
|
@ -541,7 +541,7 @@ public class VerificationController {
|
||||||
|
|
||||||
final RegistrationServiceSession resultSession;
|
final RegistrationServiceSession resultSession;
|
||||||
try {
|
try {
|
||||||
resultSession = registrationServiceClient.checkVerificationCodeSession(registrationServiceSession.id(),
|
resultSession = registrationServiceClient.checkVerificationCode(registrationServiceSession.id(),
|
||||||
submitVerificationCodeRequest.code(),
|
submitVerificationCodeRequest.code(),
|
||||||
REGISTRATION_RPC_TIMEOUT)
|
REGISTRATION_RPC_TIMEOUT)
|
||||||
.join();
|
.join();
|
||||||
|
|
|
@ -78,9 +78,7 @@ public class RegistrationServiceClient implements Managed {
|
||||||
this.callbackExecutor = callbackExecutor;
|
this.callbackExecutor = callbackExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The …Session suffix methods distinguish the new methods, which return Sessions, from the old.
|
public CompletableFuture<RegistrationServiceSession> createRegistrationSession(
|
||||||
// Once the deprecated methods are removed, the names can be streamlined.
|
|
||||||
public CompletableFuture<RegistrationServiceSession> createRegistrationSessionSession(
|
|
||||||
final Phonenumber.PhoneNumber phoneNumber, final boolean accountExistsWithPhoneNumber, final Duration timeout) {
|
final Phonenumber.PhoneNumber phoneNumber, final boolean accountExistsWithPhoneNumber, final Duration timeout) {
|
||||||
final long e164 = Long.parseLong(
|
final long e164 = Long.parseLong(
|
||||||
PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164).substring(1));
|
PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164).substring(1));
|
||||||
|
@ -110,13 +108,6 @@ public class RegistrationServiceClient implements Managed {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public CompletableFuture<byte[]> createRegistrationSession(final Phonenumber.PhoneNumber phoneNumber,
|
|
||||||
final boolean accountExistsWithPhoneNumber, final Duration timeout) {
|
|
||||||
return createRegistrationSessionSession(phoneNumber, accountExistsWithPhoneNumber, timeout)
|
|
||||||
.thenApply(RegistrationServiceSession::id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<RegistrationServiceSession> sendVerificationCode(final byte[] sessionId,
|
public CompletableFuture<RegistrationServiceSession> sendVerificationCode(final byte[] sessionId,
|
||||||
final MessageTransport messageTransport,
|
final MessageTransport messageTransport,
|
||||||
final ClientType clientType,
|
final ClientType clientType,
|
||||||
|
@ -169,49 +160,7 @@ public class RegistrationServiceClient implements Managed {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
public CompletableFuture<RegistrationServiceSession> checkVerificationCode(final byte[] sessionId,
|
||||||
public CompletableFuture<byte[]> sendRegistrationCode(final byte[] sessionId,
|
|
||||||
final MessageTransport messageTransport,
|
|
||||||
final ClientType clientType,
|
|
||||||
@Nullable final String acceptLanguage,
|
|
||||||
final Duration timeout) {
|
|
||||||
return sendVerificationCode(sessionId, messageTransport, clientType, acceptLanguage, timeout)
|
|
||||||
.thenApply(RegistrationServiceSession::id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public CompletableFuture<Boolean> checkVerificationCode(final byte[] sessionId,
|
|
||||||
final String verificationCode,
|
|
||||||
final Duration timeout) {
|
|
||||||
|
|
||||||
return toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
|
||||||
.legacyCheckVerificationCode(CheckVerificationCodeRequest.newBuilder()
|
|
||||||
.setSessionId(ByteString.copyFrom(sessionId))
|
|
||||||
.setVerificationCode(verificationCode)
|
|
||||||
.build()))
|
|
||||||
.thenApply(response -> {
|
|
||||||
if (response.hasError()) {
|
|
||||||
switch (response.getError().getErrorType()) {
|
|
||||||
case CHECK_VERIFICATION_CODE_ERROR_TYPE_RATE_LIMITED ->
|
|
||||||
throw new CompletionException(new RateLimitExceededException(response.getError().getMayRetry()
|
|
||||||
? Duration.ofSeconds(response.getError().getRetryAfterSeconds())
|
|
||||||
: null, true));
|
|
||||||
|
|
||||||
case CHECK_VERIFICATION_CODE_ERROR_TYPE_NO_CODE_SENT,
|
|
||||||
CHECK_VERIFICATION_CODE_ERROR_TYPE_ATTEMPT_EXPIRED,
|
|
||||||
CHECK_VERIFICATION_CODE_ERROR_TYPE_SESSION_NOT_FOUND ->
|
|
||||||
throw new CompletionException(new RegistrationServiceException(null));
|
|
||||||
|
|
||||||
default -> throw new CompletionException(
|
|
||||||
new RuntimeException("Failed to check verification code: " + response.getError().getErrorType()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return response.getVerified();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<RegistrationServiceSession> checkVerificationCodeSession(final byte[] sessionId,
|
|
||||||
final String verificationCode,
|
final String verificationCode,
|
||||||
final Duration timeout) {
|
final Duration timeout) {
|
||||||
return toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
return toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
||||||
|
|
|
@ -26,8 +26,6 @@ service RegistrationService {
|
||||||
* session.
|
* session.
|
||||||
*/
|
*/
|
||||||
rpc check_verification_code (CheckVerificationCodeRequest) returns (CheckVerificationCodeResponse) {}
|
rpc check_verification_code (CheckVerificationCodeRequest) returns (CheckVerificationCodeResponse) {}
|
||||||
|
|
||||||
rpc legacy_check_verification_code (CheckVerificationCodeRequest) returns (LegacyCheckVerificationCodeResponse) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateRegistrationSessionRequest {
|
message CreateRegistrationSessionRequest {
|
||||||
|
@ -358,20 +356,6 @@ message CheckVerificationCodeResponse {
|
||||||
CheckVerificationCodeError error = 3;
|
CheckVerificationCodeError error = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LegacyCheckVerificationCodeResponse {
|
|
||||||
/**
|
|
||||||
* Indicates whether the verification code given in the request that produced
|
|
||||||
* this response was correct.
|
|
||||||
*/
|
|
||||||
bool verified = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If a code could not be checked, explains the underlying error. Will be
|
|
||||||
* absent if no error occurred.
|
|
||||||
*/
|
|
||||||
CheckVerificationCodeError error = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CheckVerificationCodeError {
|
message CheckVerificationCodeError {
|
||||||
/**
|
/**
|
||||||
* The type of error that prevented a verification code from being checked.
|
* The type of error that prevented a verification code from being checked.
|
||||||
|
|
|
@ -168,7 +168,7 @@ class VerificationControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSessionRateLimited() {
|
void createSessionRateLimited() {
|
||||||
when(registrationServiceClient.createRegistrationSessionSession(any(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyBoolean(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null, true)));
|
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null, true)));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
|
@ -182,7 +182,7 @@ class VerificationControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSessionRegistrationServiceError() {
|
void createSessionRegistrationServiceError() {
|
||||||
when(registrationServiceClient.createRegistrationSessionSession(any(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyBoolean(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new RuntimeException("expected service error")));
|
.thenReturn(CompletableFuture.failedFuture(new RuntimeException("expected service error")));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
|
@ -198,7 +198,7 @@ class VerificationControllerTest {
|
||||||
@MethodSource
|
@MethodSource
|
||||||
void createSessionSuccess(final String pushToken, final String pushTokenType,
|
void createSessionSuccess(final String pushToken, final String pushTokenType,
|
||||||
final List<VerificationSession.Information> expectedRequestedInformation) {
|
final List<VerificationSession.Information> expectedRequestedInformation) {
|
||||||
when(registrationServiceClient.createRegistrationSessionSession(any(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyBoolean(), any()))
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
CompletableFuture.completedFuture(
|
CompletableFuture.completedFuture(
|
||||||
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
||||||
|
@ -232,7 +232,7 @@ class VerificationControllerTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(booleans = {true, false})
|
@ValueSource(booleans = {true, false})
|
||||||
void createSessionReregistration(final boolean isReregistration) throws NumberParseException {
|
void createSessionReregistration(final boolean isReregistration) throws NumberParseException {
|
||||||
when(registrationServiceClient.createRegistrationSessionSession(any(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyBoolean(), any()))
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
CompletableFuture.completedFuture(
|
CompletableFuture.completedFuture(
|
||||||
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
||||||
|
@ -252,7 +252,7 @@ class VerificationControllerTest {
|
||||||
try (final Response response = request.post(Entity.json(createSessionJson(NUMBER, null, null)))) {
|
try (final Response response = request.post(Entity.json(createSessionJson(NUMBER, null, null)))) {
|
||||||
assertEquals(HttpStatus.SC_OK, response.getStatus());
|
assertEquals(HttpStatus.SC_OK, response.getStatus());
|
||||||
|
|
||||||
verify(registrationServiceClient).createRegistrationSessionSession(
|
verify(registrationServiceClient).createRegistrationSession(
|
||||||
eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)),
|
eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)),
|
||||||
eq(isReregistration),
|
eq(isReregistration),
|
||||||
any()
|
any()
|
||||||
|
@ -1102,7 +1102,7 @@ class VerificationControllerTest {
|
||||||
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
||||||
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
||||||
|
|
||||||
when(registrationServiceClient.checkVerificationCodeSession(any(), any(), any()))
|
when(registrationServiceClient.checkVerificationCode(any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new CompletionException(new RuntimeException())));
|
.thenReturn(CompletableFuture.failedFuture(new CompletionException(new RuntimeException())));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
|
@ -1166,7 +1166,7 @@ class VerificationControllerTest {
|
||||||
|
|
||||||
// There is no explicit indication in the exception that no code has been sent, but we treat all RegistrationServiceExceptions
|
// There is no explicit indication in the exception that no code has been sent, but we treat all RegistrationServiceExceptions
|
||||||
// in which the response has a session object as conflicted state
|
// in which the response has a session object as conflicted state
|
||||||
when(registrationServiceClient.checkVerificationCodeSession(any(), any(), any()))
|
when(registrationServiceClient.checkVerificationCode(any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new CompletionException(
|
.thenReturn(CompletableFuture.failedFuture(new CompletionException(
|
||||||
new RegistrationServiceException(new RegistrationServiceSession(SESSION_ID, NUMBER, false, 0L, null, null,
|
new RegistrationServiceException(new RegistrationServiceSession(SESSION_ID, NUMBER, false, 0L, null, null,
|
||||||
SESSION_EXPIRATION_SECONDS)))));
|
SESSION_EXPIRATION_SECONDS)))));
|
||||||
|
@ -1201,7 +1201,7 @@ class VerificationControllerTest {
|
||||||
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
||||||
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
||||||
|
|
||||||
when(registrationServiceClient.checkVerificationCodeSession(any(), any(), any()))
|
when(registrationServiceClient.checkVerificationCode(any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new CompletionException(new RegistrationServiceException(null))));
|
.thenReturn(CompletableFuture.failedFuture(new CompletionException(new RegistrationServiceException(null))));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
|
@ -1226,7 +1226,7 @@ class VerificationControllerTest {
|
||||||
.thenReturn(CompletableFuture.completedFuture(
|
.thenReturn(CompletableFuture.completedFuture(
|
||||||
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
Optional.of(new VerificationSession(null, Collections.emptyList(), Collections.emptyList(), true,
|
||||||
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
clock.millis(), clock.millis(), registrationServiceSession.expiration()))));
|
||||||
when(registrationServiceClient.checkVerificationCodeSession(any(), any(), any()))
|
when(registrationServiceClient.checkVerificationCode(any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(
|
.thenReturn(CompletableFuture.failedFuture(
|
||||||
new CompletionException(new VerificationSessionRateLimitExceededException(registrationServiceSession,
|
new CompletionException(new VerificationSessionRateLimitExceededException(registrationServiceSession,
|
||||||
Duration.ofMinutes(1), true))));
|
Duration.ofMinutes(1), true))));
|
||||||
|
@ -1262,7 +1262,7 @@ class VerificationControllerTest {
|
||||||
final RegistrationServiceSession verifiedSession = new RegistrationServiceSession(SESSION_ID, NUMBER, true, null,
|
final RegistrationServiceSession verifiedSession = new RegistrationServiceSession(SESSION_ID, NUMBER, true, null,
|
||||||
null, 0L,
|
null, 0L,
|
||||||
SESSION_EXPIRATION_SECONDS);
|
SESSION_EXPIRATION_SECONDS);
|
||||||
when(registrationServiceClient.checkVerificationCodeSession(any(), any(), any()))
|
when(registrationServiceClient.checkVerificationCode(any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.completedFuture(verifiedSession));
|
.thenReturn(CompletableFuture.completedFuture(verifiedSession));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
|
|
Loading…
Reference in New Issue