diff --git a/integration-tests/src/main/java/org/signal/integration/Operations.java b/integration-tests/src/main/java/org/signal/integration/Operations.java index 47b8774df..5a7b99f5f 100644 --- a/integration-tests/src/main/java/org/signal/integration/Operations.java +++ b/integration-tests/src/main/java/org/signal/integration/Operations.java @@ -112,7 +112,7 @@ public final class Operations { .executeExpectSuccess(AccountIdentityResponse.class); user.setAciUuid(registrationResponse.uuid()); - user.setPniUuid(registrationResponse.pni()); + registrationResponse.pni().ifPresent(user::setPniUuid); return user; } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountIdentityResponseBuilder.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountIdentityResponseBuilder.java index 05dca30d1..fd59a9ccb 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountIdentityResponseBuilder.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountIdentityResponseBuilder.java @@ -18,18 +18,18 @@ public class AccountIdentityResponseBuilder { private boolean storageCapable; private Clock clock; - public AccountIdentityResponseBuilder(Account account) { + public AccountIdentityResponseBuilder(final Account account) { this.account = account; this.storageCapable = account.hasCapability(DeviceCapability.STORAGE); this.clock = Clock.systemUTC(); } - public AccountIdentityResponseBuilder storageCapable(boolean storageCapable) { + public AccountIdentityResponseBuilder storageCapable(final boolean storageCapable) { this.storageCapable = storageCapable; return this; } - public AccountIdentityResponseBuilder clock(Clock clock) { + public AccountIdentityResponseBuilder clock(final Clock clock) { this.clock = clock; return this; } @@ -48,8 +48,8 @@ public class AccountIdentityResponseBuilder { .orElse(null); return new AccountIdentityResponse(account.getAccountIdentifier(), - account.getNumber(), - account.getPhoneNumberIdentifier(), + account.getNumberOptional(), + account.getPhoneNumberIdentifierOptional(), account.getUsernameHash().filter(h -> h.length > 0).orElse(null), account.getUsernameLinkHandle(), storageCapable, diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountIdentityResponse.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountIdentityResponse.java index 7bb72cb71..08a1cbb7e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountIdentityResponse.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountIdentityResponse.java @@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.entities; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.Optional; import java.util.UUID; import javax.annotation.Nullable; import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter; @@ -16,11 +17,11 @@ public record AccountIdentityResponse( @Schema(description = "the account identifier for this account") UUID uuid, - @Schema(description = "the phone number associated with this account") - String number, + @Schema(description = "the phone number associated with this account; may be null if this account does not have a phone number") + Optional number, - @Schema(description = "the account identifier for this account's phone-number identity") - UUID pni, + @Schema(description = "the account identifier for this account's phone-number identity; may be null if this account does not have a phone number") + Optional pni, @Schema(description = "a hash of this account's username, if set") @JsonSerialize(using = ByteArrayBase64UrlAdapter.Serializing.class) 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 18f11baab..82d9814a7 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java @@ -516,9 +516,13 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { private static AccountIdentifiers buildAccountIdentifiers(final Account account) { final AccountIdentifiers.Builder accountIdentifiersBuilder = AccountIdentifiers.newBuilder() - .addServiceIdentifiers(GrpcServiceIdentifierUtil.toGrpcServiceIdentifier(new AciServiceIdentifier(account.getAccountIdentifier()))) - .addServiceIdentifiers(GrpcServiceIdentifierUtil.toGrpcServiceIdentifier(new PniServiceIdentifier(account.getPhoneNumberIdentifier()))) - .setE164(account.getNumber()); + .addServiceIdentifiers(GrpcServiceIdentifierUtil.toGrpcServiceIdentifier(new AciServiceIdentifier(account.getAccountIdentifier()))); + + account.getPhoneNumberIdentifierOptional() + .map(phoneNumberIdentifier -> GrpcServiceIdentifierUtil.toGrpcServiceIdentifier(new PniServiceIdentifier(phoneNumberIdentifier))) + .ifPresent(accountIdentifiersBuilder::addServiceIdentifiers); + + account.getNumberOptional().ifPresent(accountIdentifiersBuilder::setE164); account.getUsernameHash().ifPresent(usernameHash -> accountIdentifiersBuilder.setUsernameHash(ByteString.copyFrom(usernameHash))); diff --git a/service/src/main/proto/org/signal/chat/common.proto b/service/src/main/proto/org/signal/chat/common.proto index 40c41a15e..896b7b96d 100644 --- a/service/src/main/proto/org/signal/chat/common.proto +++ b/service/src/main/proto/org/signal/chat/common.proto @@ -28,10 +28,11 @@ message ServiceIdentifier { // All identifiers associated with an account. message AccountIdentifiers { // A list of service identifiers for the identified account. Always includes - // exactly one ACI service identifier and one PNI service identifier. + // exactly one ACI service identifier and at most one PNI service identifier. repeated ServiceIdentifier service_identifiers = 1; - // The phone number associated with the identified account. + // The phone number associated with the identified account. May be empty if + // the given account does not have a phone number. string e164 = 2 [(org.signal.chat.require.e164) = true]; // The username hash (if any) associated with the identified account. May be 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 084724aaf..1e601279e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java @@ -128,11 +128,16 @@ class AccountControllerV2Test { final Account updatedAccount = mock(Account.class); when(updatedAccount.getAccountIdentifier()).thenReturn(uuid); when(updatedAccount.getNumber()).thenReturn(number); + when(updatedAccount.getNumberOptional()).thenReturn(Optional.of(number)); when(updatedAccount.getIdentityKey(IdentityType.PNI)).thenReturn(pniIdentityKey); if (number.equals(account.getNumber())) { when(updatedAccount.getPhoneNumberIdentifier()).thenReturn(AuthHelper.VALID_PNI); + when(updatedAccount.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(AuthHelper.VALID_PNI)); } else { - when(updatedAccount.getPhoneNumberIdentifier()).thenReturn(UUID.randomUUID()); + final UUID pni = UUID.randomUUID(); + + when(updatedAccount.getPhoneNumberIdentifier()).thenReturn(pni); + when(updatedAccount.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(pni)); } when(updatedAccount.getDevices()).thenReturn(devices); @@ -169,8 +174,8 @@ class AccountControllerV2Test { any(), any(), any(), any(), any(), any(), any()); assertEquals(AuthHelper.VALID_UUID, accountIdentityResponse.uuid()); - assertEquals(NEW_NUMBER, accountIdentityResponse.number()); - assertNotEquals(AuthHelper.VALID_PNI, accountIdentityResponse.pni()); + assertEquals(Optional.of(NEW_NUMBER), accountIdentityResponse.number()); + assertNotEquals(Optional.of(AuthHelper.VALID_PNI), accountIdentityResponse.pni()); } @Test 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 632617648..fb4830bb3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java @@ -172,7 +172,9 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest