From 8f94ed68a3ab2d0c2ab320ee4ec66efb50ede2ce Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 29 Jan 2021 17:24:51 -0500 Subject: [PATCH] Ignore expired devices when checking for GV1->GV2 migration capability. --- .../org/whispersystems/textsecuregcm/storage/Account.java | 4 +++- .../textsecuregcm/tests/storage/AccountTest.java | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index 989959d1e..7692afdb0 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -139,7 +139,9 @@ public class Account implements Principal { } public boolean isGv1MigrationSupported() { - return devices.stream().allMatch(device -> device.getCapabilities() != null && device.getCapabilities().isGv1Migration()); + return devices.stream() + .filter(Device::isEnabled) + .allMatch(device -> device.getCapabilities() != null && device.getCapabilities().isGv1Migration()); } public boolean isEnabled() { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java index c7fbb8364..778428cff 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java @@ -73,8 +73,13 @@ public class AccountTest { when(gv2IncapableExpiredDevice.isEnabled()).thenReturn(false); when(gv1MigrationCapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(true, true, true, true, true, true)); + when(gv1MigrationCapableDevice.isEnabled()).thenReturn(true); + when(gv1MigrationIncapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(true, true, true, true, true, false)); + when(gv1MigrationIncapableDevice.isEnabled()).thenReturn(true); + when(gv1MigrationIncapableExpiredDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(true, true, true, true, true, false)); + when(gv1MigrationIncapableExpiredDevice.isEnabled()).thenReturn(false); } @Test @@ -195,6 +200,6 @@ public class AccountTest { public void isGv1MigrationSupported() { assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported()); assertFalse(new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported()); - assertFalse(new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableExpiredDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported()); + assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv1MigrationCapableDevice, gv1MigrationIncapableExpiredDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGv1MigrationSupported()); } }