Don't assume presence of phone numbers in account data reports

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-07-29 14:40:08 -04:00
1 parent 70d0bda779
commit 478a4bda7d
5 files changed
+57 -22

No files matched your search

@@ -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()),
@@ -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<BadgeDataReport> badges, boolean allowSealedSenderFromAnyone,
public record AccountDataReport(Optional<String> phoneNumber,
List<BadgeDataReport> badges,
boolean allowSealedSenderFromAnyone,
boolean findAccountByPhoneNumber) {
}
public record DeviceDataReport(byte id,
@@ -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()),
@@ -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(),
@@ -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<AccountBadge> badges, final List<DeviceData> devices) {
public static Account buildTestAccountForDataReport(final UUID aci,
@Nullable final String number,
final boolean unrestrictedUnidentifiedAccess,
final boolean discoverableByPhoneNumber,
final List<AccountBadge> badges,
final List<DeviceData> 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));