From 478a4bda7d3bf88cffa19589c33d8b01202b8734 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 29 Jul 2026 10:07:46 -0400 Subject: [PATCH] Don't assume presence of phone numbers in account data reports --- .../controllers/AccountControllerV2.java | 2 +- .../entities/AccountDataReportResponse.java | 29 +++++++----- .../grpc/AccountsGrpcService.java | 2 +- .../controllers/AccountControllerV2Test.java | 2 +- .../tests/util/AccountsTestHelper.java | 44 ++++++++++++++++--- 5 files changed, 57 insertions(+), 22 deletions(-) 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 655dbb933..490db65fd 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java @@ -174,7 +174,7 @@ public class AccountControllerV2 { return new AccountDataReportResponse(UUID.randomUUID(), Instant.now(), new AccountDataReportResponse.AccountAndDevicesDataReport( new AccountDataReportResponse.AccountDataReport( - account.getNumber(), + account.getNumberOptional(), account.getBadges().stream().map(AccountDataReportResponse.BadgeDataReport::new).toList(), account.isUnrestrictedUnidentifiedAccess(), account.isDiscoverableByPhoneNumber()), diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountDataReportResponse.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountDataReportResponse.java index 07c30e3a3..32748c026 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountDataReportResponse.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountDataReportResponse.java @@ -13,6 +13,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Optional; import java.util.UUID; import javax.annotation.Nullable; import org.whispersystems.textsecuregcm.storage.AccountBadge; @@ -36,21 +37,24 @@ public record AccountDataReportResponse(UUID reportId, builder.append(String.format(""" Report ID: %s Report timestamp: %s - + """, reportId, reportTimestamp.truncatedTo(ChronoUnit.SECONDS))); // account - builder.append(String.format(""" - # Account - Phone number: %s - Allow sealed sender from anyone: %s - Find account by phone number: %s - """, - data.account.phoneNumber(), - data.account.allowSealedSenderFromAnyone(), - data.account.findAccountByPhoneNumber())); + builder.append("# Account\n"); + + data.account.phoneNumber().ifPresent(phoneNumber -> { + builder.append(String.format(""" + Phone number: %s + Find account by phone number: %s + """, + phoneNumber, + data.account.findAccountByPhoneNumber())); + }); + + builder.append(String.format("Allow sealed sender from anyone: %s%n", data.account.allowSealedSenderFromAnyone())); // badges builder.append("Badges:"); @@ -93,9 +97,10 @@ public record AccountDataReportResponse(UUID reportId, } - public record AccountDataReport(String phoneNumber, List badges, boolean allowSealedSenderFromAnyone, + public record AccountDataReport(Optional phoneNumber, + List badges, + boolean allowSealedSenderFromAnyone, boolean findAccountByPhoneNumber) { - } public record DeviceDataReport(byte id, 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 b7c559522..18f11baab 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java @@ -485,7 +485,7 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { final AccountDataReportResponse report = new AccountDataReportResponse(UUID.randomUUID(), clock.instant(), new AccountDataReportResponse.AccountAndDevicesDataReport( new AccountDataReportResponse.AccountDataReport( - account.getNumber(), + account.getNumberOptional(), account.getBadges().stream().map(AccountDataReportResponse.BadgeDataReport::new).toList(), account.isUnrestrictedUnidentifiedAccess(), account.isDiscoverableByPhoneNumber()), 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 ddd2318d5..084724aaf 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java @@ -485,7 +485,7 @@ class AccountControllerV2Test { final AccountDataReportResponse structuredResponse = SystemMapper.jsonMapper() .readValue(stringResponse, AccountDataReportResponse.class); - assertEquals(account.getNumber(), structuredResponse.data().account().phoneNumber()); + assertEquals(account.getNumberOptional(), structuredResponse.data().account().phoneNumber()); assertEquals(account.isDiscoverableByPhoneNumber(), structuredResponse.data().account().findAccountByPhoneNumber()); assertEquals(account.isUnrestrictedUnidentifiedAccess(), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsTestHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsTestHelper.java index 07af17011..89b1c4a8b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsTestHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsTestHelper.java @@ -68,8 +68,8 @@ public class AccountsTestHelper { String.format(""" # Account Phone number: %s - Allow sealed sender from anyone: true Find account by phone number: true + Allow sealed sender from anyone: true Badges: None # Devices @@ -93,8 +93,8 @@ public class AccountsTestHelper { String.format(""" # Account Phone number: %s - Allow sealed sender from anyone: false Find account by phone number: true + Allow sealed sender from anyone: false Badges: - ID: badge_a Expiration: %s @@ -119,8 +119,8 @@ public class AccountsTestHelper { String.format(""" # Account Phone number: %s - Allow sealed sender from anyone: true Find account by phone number: false + Allow sealed sender from anyone: true Badges: - ID: badge_b Expiration: %s @@ -138,20 +138,50 @@ public class AccountsTestHelper { badgeBExpiration, badgeCExpiration, account3Device1LastSeen) + ), + Arguments.of( + buildTestAccountForDataReport(UUID.randomUUID(), null, + true, true, + Collections.emptyList(), + List.of(new DeviceData(Device.PRIMARY_ID, account1Device1LastSeen, account1Device1Created, null), + new DeviceData((byte) 2, account1Device2LastSeen, account1Device2Created, "OWP"))), + String.format(""" + # Account + Allow sealed sender from anyone: true + Badges: None + + # Devices + - ID: 1 + Created: 2022-11-24T20:52:22Z + Last seen: %s + User-agent: null + - ID: 2 + Created: 2023-03-18T15:58:42Z + Last seen: 2023-03-15T00:00:00Z + User-agent: OWP + """, + account1Device1LastSeen) ) ); } - public static Account buildTestAccountForDataReport(final UUID aci, final String number, - final boolean unrestrictedUnidentifiedAccess, final boolean discoverableByPhoneNumber, - final List badges, final List devices) { + public static Account buildTestAccountForDataReport(final UUID aci, + @Nullable final String number, + final boolean unrestrictedUnidentifiedAccess, + final boolean discoverableByPhoneNumber, + final List badges, + final List devices) { final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate(); final ECKeyPair pniIdentityKeyPair = ECKeyPair.generate(); final Account account = new Account(); account.setAccountIdentifier(aci); - account.setNumber(number, UUID.randomUUID()); + + if (number != null) { + account.setNumber(number, UUID.randomUUID()); + } + account.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedAccess); account.setDiscoverableByPhoneNumber(discoverableByPhoneNumber); account.setBadges(Clock.systemUTC(), new ArrayList<>(badges));