From 5587b7d469b6f94a653a3223492d42da413ca444 Mon Sep 17 00:00:00 2001 From: Ehren Kret Date: Wed, 28 Oct 2020 11:50:08 -0500 Subject: [PATCH] Expose gv1-migration on profile endpoint --- .../textsecuregcm/controllers/ProfileController.java | 6 +++--- .../textsecuregcm/entities/UserCapabilities.java | 10 +++++++++- .../tests/controllers/ProfileControllerTest.java | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java index 27b5a5c6d..f948954c8 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -197,7 +197,7 @@ public class ProfileController { accountProfile.get().getIdentityKey(), UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()), accountProfile.get().isUnrestrictedUnidentifiedAccess(), - new UserCapabilities(accountProfile.get().isGroupsV2Supported()), + new UserCapabilities(accountProfile.get().isGroupsV2Supported(), accountProfile.get().isGv1MigrationSupported()), username.orElse(null), null, credential.orElse(null), @@ -235,7 +235,7 @@ public class ProfileController { accountProfile.get().getIdentityKey(), UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()), accountProfile.get().isUnrestrictedUnidentifiedAccess(), - new UserCapabilities(accountProfile.get().isGroupsV2Supported()), + new UserCapabilities(accountProfile.get().isGroupsV2Supported(), accountProfile.get().isGv1MigrationSupported()), username, accountProfile.get().getUuid(), null, @@ -308,7 +308,7 @@ public class ProfileController { accountProfile.get().getIdentityKey(), UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()), accountProfile.get().isUnrestrictedUnidentifiedAccess(), - new UserCapabilities(accountProfile.get().isGroupsV2Supported()), + new UserCapabilities(accountProfile.get().isGroupsV2Supported(), accountProfile.get().isGv1MigrationSupported()), username.orElse(null), null, null, diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java index 60bce877b..0a8555e11 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java @@ -6,13 +6,21 @@ public class UserCapabilities { @JsonProperty private boolean gv2; + @JsonProperty("gv1-migration") + private boolean gv1Migration; + public UserCapabilities() {} - public UserCapabilities(boolean gv2) { + public UserCapabilities(boolean gv2, boolean gv1Migration) { this.gv2 = gv2; + this.gv1Migration = gv1Migration; } public boolean isGv2() { return gv2; } + + public boolean isGv1Migration() { + return gv1Migration; + } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java index 977d6d02f..72e12de52 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java @@ -97,6 +97,7 @@ public class ProfileControllerTest { when(profileAccount.getUuid()).thenReturn(AuthHelper.VALID_UUID_TWO); when(profileAccount.isEnabled()).thenReturn(true); when(profileAccount.isGroupsV2Supported()).thenReturn(false); + when(profileAccount.isGv1MigrationSupported()).thenReturn(false); when(profileAccount.getPayments()).thenReturn(List.of(new PaymentAddress("mc", "12345678901234567890123456789012"))); Account capabilitiesAccount = mock(Account.class); @@ -106,6 +107,7 @@ public class ProfileControllerTest { when(capabilitiesAccount.getAvatar()).thenReturn("profiles/bangz"); when(capabilitiesAccount.isEnabled()).thenReturn(true); when(capabilitiesAccount.isGroupsV2Supported()).thenReturn(true); + when(capabilitiesAccount.isGv1MigrationSupported()).thenReturn(true); when(accountsManager.get(AuthHelper.VALID_NUMBER_TWO)).thenReturn(Optional.of(profileAccount)); when(accountsManager.get(AuthHelper.VALID_UUID_TWO)).thenReturn(Optional.of(profileAccount)); @@ -159,6 +161,7 @@ public class ProfileControllerTest { assertThat(profile.getAvatar()).isEqualTo("profiles/bang"); assertThat(profile.getPayments()).isEqualTo(List.of(new PaymentAddress("mc", "12345678901234567890123456789012"))); assertThat(profile.getCapabilities().isGv2()).isFalse(); + assertThat(profile.getCapabilities().isGv1Migration()).isFalse(); assertThat(profile.getUsername()).isNull(); assertThat(profile.getUuid()).isNull();; @@ -243,6 +246,7 @@ public class ProfileControllerTest { .get(Profile.class); assertThat(profile.getCapabilities().isGv2()).isTrue(); + assertThat(profile.getCapabilities().isGv1Migration()).isTrue(); } @Test @@ -386,6 +390,7 @@ public class ProfileControllerTest { assertThat(profile.getName()).isEqualTo("validname"); assertThat(profile.getAvatar()).isEqualTo("profiles/validavatar"); assertThat(profile.getCapabilities().isGv2()).isFalse(); + assertThat(profile.getCapabilities().isGv1Migration()).isFalse(); assertThat(profile.getUsername()).isEqualTo("n00bkiller"); assertThat(profile.getUuid()).isNull();;