Add support for Group V2 description field.

This commit is contained in:
Cody Henthorne
2021-05-07 13:43:31 -04:00
committed by Greyson Parrelli
parent b3aec58e69
commit 8c9df8d3be
56 changed files with 892 additions and 117 deletions

View File

@@ -45,7 +45,7 @@ public final class DecryptedGroupUtil_apply_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroupChange.class);
assertEquals("DecryptedGroupUtil and its tests need updating to account for new fields on " + DecryptedGroupChange.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
@Test
@@ -576,6 +576,24 @@ public final class DecryptedGroupUtil_apply_Test {
newGroup);
}
@Test
public void description() throws NotAbleToApplyGroupV2ChangeException {
DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder()
.setRevision(10)
.setDescription("Old description")
.build(),
DecryptedGroupChange.newBuilder()
.setRevision(11)
.setNewDescription(DecryptedString.newBuilder().setValue("New Description").build())
.build());
assertEquals(DecryptedGroup.newBuilder()
.setRevision(11)
.setDescription("New Description")
.build(),
newGroup);
}
@Test
public void avatar() throws NotAbleToApplyGroupV2ChangeException {
DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder()

View File

@@ -35,7 +35,7 @@ public final class DecryptedGroupUtil_empty_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroupChange.class);
assertEquals("DecryptedGroupUtil and its tests need updating to account for new fields on " + DecryptedGroupChange.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
@Test
@@ -203,7 +203,7 @@ public final class DecryptedGroupUtil_empty_Test {
assertFalse(DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(change));
}
@Test
@Test
public void not_empty_with_a_new_invite_link_password_19() {
DecryptedGroupChange change = DecryptedGroupChange.newBuilder()
.setNewInviteLinkPassword(ByteString.copyFrom(new byte[16]))
@@ -212,4 +212,14 @@ public final class DecryptedGroupUtil_empty_Test {
assertFalse(DecryptedGroupUtil.changeIsEmpty(change));
assertFalse(DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(change));
}
@Test
public void not_empty_with_modify_description_field_20() {
DecryptedGroupChange change = DecryptedGroupChange.newBuilder()
.setNewDescription(DecryptedString.newBuilder().setValue("New description"))
.build();
assertFalse(DecryptedGroupUtil.changeIsEmpty(change));
assertFalse(DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(change));
}
}

View File

@@ -41,7 +41,7 @@ public final class GroupChangeReconstructTest {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroup.class);
assertEquals("GroupChangeReconstruct and its tests need updating to account for new fields on " + DecryptedGroup.class.getName(),
10, maxFieldFound);
11, maxFieldFound);
}
@Test
@@ -74,6 +74,16 @@ public final class GroupChangeReconstructTest {
assertEquals(DecryptedGroupChange.newBuilder().setNewTitle(DecryptedString.newBuilder().setValue("B")).build(), decryptedGroupChange);
}
@Test
public void description_change() {
DecryptedGroup from = DecryptedGroup.newBuilder().setDescription("A").build();
DecryptedGroup to = DecryptedGroup.newBuilder().setDescription("B").build();
DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
assertEquals(DecryptedGroupChange.newBuilder().setNewDescription(DecryptedString.newBuilder().setValue("B")).build(), decryptedGroupChange);
}
@Test
public void avatar_change() {
DecryptedGroup from = DecryptedGroup.newBuilder().setAvatar("A").build();

View File

@@ -20,7 +20,7 @@ public final class GroupChangeUtil_changeIsEmpty_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(GroupChange.Actions.class);
assertEquals("GroupChangeUtil and its tests need updating to account for new fields on " + GroupChange.Actions.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
@Test
@@ -180,4 +180,13 @@ public final class GroupChangeUtil_changeIsEmpty_Test {
assertFalse(GroupChangeUtil.changeIsEmpty(actions));
}
@Test
public void not_empty_with_modify_description_field_20() {
GroupChange.Actions actions = GroupChange.Actions.newBuilder()
.setModifyDescription(GroupChange.Actions.ModifyDescriptionAction.getDefaultInstance())
.build();
assertFalse(GroupChangeUtil.changeIsEmpty(actions));
}
}

View File

@@ -46,7 +46,7 @@ public final class GroupChangeUtil_resolveConflict_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroupChange.class);
assertEquals("GroupChangeUtil#resolveConflict and its tests need updating to account for new fields on " + DecryptedGroupChange.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
/**
@@ -59,7 +59,7 @@ public final class GroupChangeUtil_resolveConflict_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroupChange.class);
assertEquals("GroupChangeUtil#resolveConflict and its tests need updating to account for new fields on " + GroupChange.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
/**
@@ -72,7 +72,7 @@ public final class GroupChangeUtil_resolveConflict_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroup.class);
assertEquals("GroupChangeUtil#resolveConflict and its tests need updating to account for new fields on " + DecryptedGroup.class.getName(),
10, maxFieldFound);
11, maxFieldFound);
}
@@ -672,4 +672,38 @@ public final class GroupChangeUtil_resolveConflict_Test {
.build();
assertEquals(expected, resolvedActions);
}
@Test
public void field_20__description_change_is_preserved() {
DecryptedGroup groupState = DecryptedGroup.newBuilder()
.setDescription("Existing title")
.build();
DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder()
.setNewDescription(DecryptedString.newBuilder().setValue("New title").build())
.build();
GroupChange.Actions change = GroupChange.Actions.newBuilder()
.setModifyDescription(GroupChange.Actions.ModifyDescriptionAction.newBuilder().setDescription(ByteString.copyFrom("New title encrypted".getBytes())))
.build();
GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
assertEquals(change, resolvedActions);
}
@Test
public void field_20__no_description_change_is_removed() {
DecryptedGroup groupState = DecryptedGroup.newBuilder()
.setDescription("Existing title")
.build();
DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder()
.setNewDescription(DecryptedString.newBuilder().setValue("Existing title").build())
.build();
GroupChange.Actions change = GroupChange.Actions.newBuilder()
.setModifyDescription(GroupChange.Actions.ModifyDescriptionAction.newBuilder().setDescription(ByteString.copyFrom("Existing title encrypted".getBytes())))
.build();
GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
assertTrue(GroupChangeUtil.changeIsEmpty(resolvedActions));
}
}

View File

@@ -39,7 +39,7 @@ public final class GroupChangeUtil_resolveConflict_decryptedOnly_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroupChange.class);
assertEquals("GroupChangeUtil#resolveConflict and its tests need updating to account for new fields on " + DecryptedGroupChange.class.getName(),
19, maxFieldFound);
20, maxFieldFound);
}
/**
@@ -52,7 +52,7 @@ public final class GroupChangeUtil_resolveConflict_decryptedOnly_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(DecryptedGroup.class);
assertEquals("GroupChangeUtil#resolveConflict and its tests need updating to account for new fields on " + DecryptedGroup.class.getName(),
10, maxFieldFound);
11, maxFieldFound);
}
@@ -543,4 +543,32 @@ public final class GroupChangeUtil_resolveConflict_decryptedOnly_Test {
assertEquals(decryptedChange, resolvedChanges);
}
@Test
public void field_20__description_change_is_preserved() {
DecryptedGroup groupState = DecryptedGroup.newBuilder()
.setDescription("Existing description")
.build();
DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder()
.setNewDescription(DecryptedString.newBuilder().setValue("New description").build())
.build();
DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
assertEquals(decryptedChange, resolvedChanges);
}
@Test
public void field_20__no_description_change_is_removed() {
DecryptedGroup groupState = DecryptedGroup.newBuilder()
.setDescription("Existing description")
.build();
DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder()
.setNewDescription(DecryptedString.newBuilder().setValue("Existing description").build())
.build();
DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
assertTrue(DecryptedGroupUtil.changeIsEmpty(resolvedChanges));
}
}

View File

@@ -41,7 +41,7 @@ public final class GroupsV2Operations_decrypt_groupJoinInfo_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(GroupJoinInfo.class);
assertEquals("GroupOperations and its tests need updating to account for new fields on " + GroupJoinInfo.class.getName(),
7, maxFieldFound);
8, maxFieldFound);
}
@Test
@@ -131,4 +131,15 @@ public final class GroupsV2Operations_decrypt_groupJoinInfo_Test {
assertFalse(decryptedGroupJoinInfo.getPendingAdminApproval());
}
@Test
public void decrypt_description_field_8() {
GroupJoinInfo groupJoinInfo = GroupJoinInfo.newBuilder()
.setDescription(groupOperations.encryptDescription("Description!"))
.build();
DecryptedGroupJoinInfo decryptedGroupJoinInfo = groupOperations.decryptGroupJoinInfo(groupJoinInfo);
assertEquals("Description!", decryptedGroupJoinInfo.getDescription());
}
}

View File

@@ -74,7 +74,7 @@ public final class GroupsV2Operations_decrypt_group_Test {
int maxFieldFound = getMaxDeclaredFieldNumber(Group.class);
assertEquals("GroupOperations and its tests need updating to account for new fields on " + Group.class.getName(),
10, maxFieldFound);
11, maxFieldFound);
}
@Test
@@ -272,6 +272,17 @@ public final class GroupsV2Operations_decrypt_group_Test {
assertEquals(password, decryptedGroup.getInviteLinkPassword());
}
@Test
public void decrypt_description_field_11() throws VerificationFailedException, InvalidGroupStateException {
Group group = Group.newBuilder()
.setDescription(groupOperations.encryptDescription("Description!"))
.build();
DecryptedGroup decryptedGroup = groupOperations.decryptGroup(group);
assertEquals("Description!", decryptedGroup.getDescription());
}
private ByteString encryptProfileKey(UUID uuid, ProfileKey profileKey) {
return ByteString.copyFrom(new ClientZkGroupCipher(groupSecretParams).encryptProfileKey(profileKey, uuid).serialize());
}