mirror of
https://github.com/signalapp/Signal-Server.git
synced 2025-12-05 01:10:13 +00:00
Compare commits
3 Commits
08f6ec639c
...
7445225906
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7445225906 | ||
|
|
0d2bee7599 | ||
|
|
78aa81dd56 |
@@ -193,6 +193,8 @@ public class VerificationController {
|
||||
|
||||
registrationServiceSession = registrationServiceClient.createRegistrationSession(phoneNumber, sourceHost,
|
||||
accountsManager.getByE164(request.number()).isPresent(),
|
||||
request.updateVerificationSessionRequest().mcc(),
|
||||
request.updateVerificationSessionRequest().mnc(),
|
||||
REGISTRATION_RPC_TIMEOUT).join();
|
||||
} catch (final CancellationException e) {
|
||||
|
||||
|
||||
@@ -94,7 +94,12 @@ public class RegistrationServiceClient implements Managed {
|
||||
}
|
||||
|
||||
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(
|
||||
PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164).substring(1));
|
||||
@@ -105,6 +110,8 @@ public class RegistrationServiceClient implements Managed {
|
||||
.setE164(e164)
|
||||
.setAccountExistsWithE164(accountExistsWithPhoneNumber)
|
||||
.setRateLimitCollationKey(rateLimitCollationKey)
|
||||
.setMcc(clientMcc != null ? clientMcc : "")
|
||||
.setMnc(clientMnc != null ? clientMnc : "")
|
||||
.build()), callbackExecutor)
|
||||
.thenApply(response -> switch (response.getResponseCase()) {
|
||||
case SESSION_METADATA -> buildSessionResponseFromMetadata(response.getSessionMetadata());
|
||||
|
||||
@@ -45,6 +45,16 @@ message CreateRegistrationSessionRequest {
|
||||
* collated by this key.
|
||||
*/
|
||||
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 {
|
||||
|
||||
@@ -61,7 +61,12 @@ public class StubRegistrationServiceClientFactory implements RegistrationService
|
||||
|
||||
@Override
|
||||
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()
|
||||
.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
|
||||
@@ -192,7 +192,7 @@ class VerificationControllerTest {
|
||||
|
||||
@Test
|
||||
void createSessionRateLimited() {
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null)));
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -206,7 +206,7 @@ class VerificationControllerTest {
|
||||
|
||||
@Test
|
||||
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")));
|
||||
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
@@ -221,7 +221,7 @@ class VerificationControllerTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
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(
|
||||
CompletableFuture.completedFuture(
|
||||
new RegistrationServiceSession(SESSION_ID, requestedNumber, false, null, null, null,
|
||||
@@ -238,7 +238,7 @@ class VerificationControllerTest {
|
||||
|
||||
final ArgumentCaptor<Phonenumber.PhoneNumber> phoneNumberArgumentCaptor = ArgumentCaptor.forClass(
|
||||
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();
|
||||
|
||||
assertEquals(expectedNumber, PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164));
|
||||
@@ -262,7 +262,7 @@ class VerificationControllerTest {
|
||||
.format(PhoneNumberUtil.getInstance().getExampleNumber("BJ"), PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
final String oldFormatBeninE164 = newFormatBeninE164.replaceFirst("01", "");
|
||||
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||
.thenReturn(
|
||||
CompletableFuture.completedFuture(
|
||||
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
||||
@@ -283,7 +283,7 @@ class VerificationControllerTest {
|
||||
@MethodSource
|
||||
void createSessionSuccess(final String pushToken, final String pushTokenType,
|
||||
final List<VerificationSession.Information> expectedRequestedInformation) {
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||
.thenReturn(
|
||||
CompletableFuture.completedFuture(
|
||||
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
||||
@@ -317,7 +317,7 @@ class VerificationControllerTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void createSessionReregistration(final boolean isReregistration) throws NumberParseException {
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any()))
|
||||
when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any()))
|
||||
.thenReturn(
|
||||
CompletableFuture.completedFuture(
|
||||
new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null,
|
||||
@@ -341,6 +341,8 @@ class VerificationControllerTest {
|
||||
eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)),
|
||||
anyString(),
|
||||
eq(isReregistration),
|
||||
any(),
|
||||
any(),
|
||||
any()
|
||||
);
|
||||
}
|
||||
|
||||
Submodule spam-filter updated: d3e132292f...3fab41e570
Reference in New Issue
Block a user