mirror of
https://github.com/signalapp/Signal-Server.git
synced 2025-12-05 01:10:13 +00:00
Pass client-provided route optimization data to registration service
This commit is contained in:
committed by
Jon Chambers
parent
08f6ec639c
commit
78aa81dd56
@@ -193,6 +193,8 @@ public class VerificationController {
|
|||||||
|
|
||||||
registrationServiceSession = registrationServiceClient.createRegistrationSession(phoneNumber, sourceHost,
|
registrationServiceSession = registrationServiceClient.createRegistrationSession(phoneNumber, sourceHost,
|
||||||
accountsManager.getByE164(request.number()).isPresent(),
|
accountsManager.getByE164(request.number()).isPresent(),
|
||||||
|
request.updateVerificationSessionRequest().mcc(),
|
||||||
|
request.updateVerificationSessionRequest().mnc(),
|
||||||
REGISTRATION_RPC_TIMEOUT).join();
|
REGISTRATION_RPC_TIMEOUT).join();
|
||||||
} catch (final CancellationException e) {
|
} catch (final CancellationException e) {
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,12 @@ public class RegistrationServiceClient implements Managed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<RegistrationServiceSession> createRegistrationSession(
|
public CompletableFuture<RegistrationServiceSession> createRegistrationSession(
|
||||||
final Phonenumber.PhoneNumber phoneNumber, final String sourceHost, final boolean accountExistsWithPhoneNumber, final Duration timeout) {
|
final Phonenumber.PhoneNumber phoneNumber,
|
||||||
|
final String sourceHost,
|
||||||
|
final boolean accountExistsWithPhoneNumber,
|
||||||
|
@javax.annotation.Nullable final String clientMcc,
|
||||||
|
@javax.annotation.Nullable final String clientMnc,
|
||||||
|
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));
|
||||||
@@ -105,6 +110,8 @@ public class RegistrationServiceClient implements Managed {
|
|||||||
.setE164(e164)
|
.setE164(e164)
|
||||||
.setAccountExistsWithE164(accountExistsWithPhoneNumber)
|
.setAccountExistsWithE164(accountExistsWithPhoneNumber)
|
||||||
.setRateLimitCollationKey(rateLimitCollationKey)
|
.setRateLimitCollationKey(rateLimitCollationKey)
|
||||||
|
.setMcc(clientMcc != null ? clientMcc : "")
|
||||||
|
.setMnc(clientMnc != null ? clientMnc : "")
|
||||||
.build()), callbackExecutor)
|
.build()), callbackExecutor)
|
||||||
.thenApply(response -> switch (response.getResponseCase()) {
|
.thenApply(response -> switch (response.getResponseCase()) {
|
||||||
case SESSION_METADATA -> buildSessionResponseFromMetadata(response.getSessionMetadata());
|
case SESSION_METADATA -> buildSessionResponseFromMetadata(response.getSessionMetadata());
|
||||||
|
|||||||
@@ -45,6 +45,16 @@ message CreateRegistrationSessionRequest {
|
|||||||
* collated by this key.
|
* collated by this key.
|
||||||
*/
|
*/
|
||||||
string rate_limit_collation_key = 3;
|
string rate_limit_collation_key = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MCC for the given `e164` as reported by the client.
|
||||||
|
*/
|
||||||
|
string mcc = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MNC for the given `e164` as reported by the client.
|
||||||
|
*/
|
||||||
|
string mnc = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateRegistrationSessionResponse {
|
message CreateRegistrationSessionResponse {
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ public class StubRegistrationServiceClientFactory implements RegistrationService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<RegistrationServiceSession> createRegistrationSession(
|
public CompletableFuture<RegistrationServiceSession> createRegistrationSession(
|
||||||
final Phonenumber.PhoneNumber phoneNumber, final String sourceHost, final boolean accountExistsWithPhoneNumber, final Duration timeout) {
|
final Phonenumber.PhoneNumber phoneNumber,
|
||||||
|
final String sourceHost,
|
||||||
|
final boolean accountExistsWithPhoneNumber,
|
||||||
|
@javax.annotation.Nullable final String clientMcc,
|
||||||
|
@javax.annotation.Nullable final String clientMnc,
|
||||||
|
final Duration timeout) {
|
||||||
|
|
||||||
final String e164 = PhoneNumberUtil.getInstance()
|
final String e164 = PhoneNumberUtil.getInstance()
|
||||||
.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
|
.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ class VerificationControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSessionRateLimited() {
|
void createSessionRateLimited() {
|
||||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||||
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null)));
|
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null)));
|
||||||
|
|
||||||
final Invocation.Builder request = resources.getJerseyTest()
|
final Invocation.Builder request = resources.getJerseyTest()
|
||||||
@@ -206,7 +206,7 @@ class VerificationControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSessionRegistrationServiceError() {
|
void createSessionRegistrationServiceError() {
|
||||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), 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()
|
||||||
@@ -221,7 +221,7 @@ class VerificationControllerTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource
|
@MethodSource
|
||||||
void createBeninSessionSuccess(final String requestedNumber, final String expectedNumber) {
|
void createBeninSessionSuccess(final String requestedNumber, final String expectedNumber) {
|
||||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
CompletableFuture.completedFuture(
|
CompletableFuture.completedFuture(
|
||||||
new RegistrationServiceSession(SESSION_ID, requestedNumber, false, null, null, null,
|
new RegistrationServiceSession(SESSION_ID, requestedNumber, false, null, null, null,
|
||||||
@@ -238,7 +238,7 @@ class VerificationControllerTest {
|
|||||||
|
|
||||||
final ArgumentCaptor<Phonenumber.PhoneNumber> phoneNumberArgumentCaptor = ArgumentCaptor.forClass(
|
final ArgumentCaptor<Phonenumber.PhoneNumber> phoneNumberArgumentCaptor = ArgumentCaptor.forClass(
|
||||||
Phonenumber.PhoneNumber.class);
|
Phonenumber.PhoneNumber.class);
|
||||||
verify(registrationServiceClient).createRegistrationSession(phoneNumberArgumentCaptor.capture(), anyString(), anyBoolean(), any());
|
verify(registrationServiceClient).createRegistrationSession(phoneNumberArgumentCaptor.capture(), anyString(), anyBoolean(), any(), any(), any());
|
||||||
final Phonenumber.PhoneNumber phoneNumber = phoneNumberArgumentCaptor.getValue();
|
final Phonenumber.PhoneNumber phoneNumber = phoneNumberArgumentCaptor.getValue();
|
||||||
|
|
||||||
assertEquals(expectedNumber, PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164));
|
assertEquals(expectedNumber, PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164));
|
||||||
@@ -262,7 +262,7 @@ class VerificationControllerTest {
|
|||||||
.format(PhoneNumberUtil.getInstance().getExampleNumber("BJ"), PhoneNumberUtil.PhoneNumberFormat.E164);
|
.format(PhoneNumberUtil.getInstance().getExampleNumber("BJ"), PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||||
final String oldFormatBeninE164 = newFormatBeninE164.replaceFirst("01", "");
|
final String oldFormatBeninE164 = newFormatBeninE164.replaceFirst("01", "");
|
||||||
|
|
||||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), 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,
|
||||||
@@ -283,7 +283,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.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), 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,
|
||||||
@@ -317,7 +317,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.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), 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,
|
||||||
@@ -341,6 +341,8 @@ class VerificationControllerTest {
|
|||||||
eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)),
|
eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)),
|
||||||
anyString(),
|
anyString(),
|
||||||
eq(isReregistration),
|
eq(isReregistration),
|
||||||
|
any(),
|
||||||
|
any(),
|
||||||
any()
|
any()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user