diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java index c4c09752c..490db65fd 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java @@ -94,13 +94,6 @@ public class AccountControllerV2 { throw new ForbiddenException(); } - final Account account = accountsManager.getByAccountIdentifier(authenticatedDevice.accountIdentifier()) - .orElseThrow(() -> new WebApplicationException(Response.Status.UNAUTHORIZED)); - - if (account.getNumberOptional().isEmpty()) { - throw new ForbiddenException(); - } - if (!request.isSignatureValidOnEachSignedPreKey(userAgentString)) { throw new WebApplicationException("Invalid signature", 422); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java index fc1ed03f1..82d9814a7 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java @@ -362,12 +362,6 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedPrimaryDevice(); - if (getAuthenticatedAccount(authenticatedDevice).getNumberOptional().isEmpty()) { - return ChangeNumberResponse.newBuilder() - .setAccountDoesNotHavePhoneNumber(FailedPrecondition.getDefaultInstance()) - .build(); - } - final IdentityKey pniIdentityKey; try { pniIdentityKey = new IdentityKey(request.getPniIdentityKey().toByteArray()); diff --git a/service/src/main/proto/org/signal/chat/account.proto b/service/src/main/proto/org/signal/chat/account.proto index b45d4ffa6..4da06bd91 100644 --- a/service/src/main/proto/org/signal/chat/account.proto +++ b/service/src/main/proto/org/signal/chat/account.proto @@ -407,9 +407,6 @@ message ChangeNumberResponse { errors.FailedPrecondition invalid_registration_session = 7 [(tag.reason) = "invalid_registration_session"]; errors.FailedPrecondition recovery_password_verification_failed = 8 [(tag.reason) = "recovery_password_verification_failed"]; - - // The account does not have a phone number - errors.FailedPrecondition account_does_not_have_phone_number = 9 [(tag.reason) = "account_has_no_phone_number"]; } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java index 07dbadd71..1e601279e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java @@ -153,13 +153,6 @@ class AccountControllerV2Test { @ParameterizedTest @ValueSource(booleans = {true, false}) void changeNumberSuccess(final boolean useSessionVerification) throws Exception { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - @Nullable final String sessionId = useSessionVerification ? encodeSessionId("session") : null; @Nullable final byte[] recoveryPassword = useSessionVerification ? null : "recovery-password".getBytes(StandardCharsets.UTF_8); @@ -251,13 +244,6 @@ class AccountControllerV2Test { @ParameterizedTest @MethodSource void invalidRegistrationId(final Integer pniRegistrationId, final int expectedStatusCode) { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - final ChangeNumberRequest changeNumberRequest = new ChangeNumberRequest(encodeSessionId("session"), null, NEW_NUMBER, "123", IDENTITY_KEY, Collections.emptyList(), Map.of(Device.PRIMARY_ID, KeysHelper.signedECPreKey(1, IDENTITY_KEY_PAIR)), @@ -287,13 +273,6 @@ class AccountControllerV2Test { @Test void rateLimitedNumber() throws Exception { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - doThrow(new RateLimitExceededException(null)) .when(changeNumberManager).changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); @@ -312,13 +291,6 @@ class AccountControllerV2Test { @MethodSource void phoneVerificationException(final Exception exception, final int expectedStatus) throws Exception { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - doThrow(exception) .when(changeNumberManager).changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); @@ -344,13 +316,6 @@ class AccountControllerV2Test { @Test void deviceMessageTooLarge() throws Exception { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - doThrow(MessageTooLargeException.class) .when(changeNumberManager).changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); @@ -373,13 +338,6 @@ class AccountControllerV2Test { @Test void messageDeliveryNotAllowed() throws Exception { - final Account account = mock(Account.class); - when(account.getNumberOptional()).thenReturn(Optional.of(PhoneNumberUtil.getInstance().format( - PhoneNumberUtil.getInstance().getExampleNumber("DE"), PhoneNumberUtil.PhoneNumberFormat.E164))); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(account)); - doThrow(MessageDeliveryNotAllowedException.class) .when(changeNumberManager).changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); @@ -400,32 +358,6 @@ class AccountControllerV2Test { } } - @Test - void accountHasNoNumber() throws Exception { - final Account numberlessAccount = mock(Account.class); - when(numberlessAccount.getNumberOptional()).thenReturn(Optional.empty()); - - when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)) - .thenReturn(Optional.of(numberlessAccount)); - - try (final Response response = resources.getJerseyTest() - .target("/v2/accounts/number") - .request() - .header(HttpHeaders.AUTHORIZATION, - AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) - .put(Entity.entity( - new ChangeNumberRequest(encodeSessionId("session"), null, NEW_NUMBER, "123", IDENTITY_KEY, - Collections.emptyList(), - Map.of(Device.PRIMARY_ID, KeysHelper.signedECPreKey(1, IDENTITY_KEY_PAIR)), - Map.of(Device.PRIMARY_ID, KeysHelper.signedKEMPreKey(2, IDENTITY_KEY_PAIR)), - Map.of(Device.PRIMARY_ID, 17)), - MediaType.APPLICATION_JSON_TYPE))) { - - assertEquals(403, response.getStatus()); - verify(changeNumberManager, never()).changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); - } - } - /** * Valid request JSON with the give session ID and recovery password */ diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java index 69ae8653d..fb4830bb3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java @@ -836,12 +836,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest