Search in sources :

Example 16 with DecryptedGroupChange

use of org.signal.storageservice.protos.groups.local.DecryptedGroupChange in project Signal-Android by WhisperSystems.

the class GroupChangeReconstructTest method to_member.

@Test
public void to_member() {
    UUID uuid = UUID.randomUUID();
    ProfileKey profileKey = randomProfileKey();
    DecryptedGroup from = DecryptedGroup.newBuilder().addMembers(withProfileKey(admin(uuid), profileKey)).build();
    DecryptedGroup to = DecryptedGroup.newBuilder().addMembers(withProfileKey(member(uuid), profileKey)).build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().addModifyMemberRoles(demoteAdmin(uuid)).build(), decryptedGroupChange);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) ProtoTestUtils.withProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) ProtoTestUtils.newProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 17 with DecryptedGroupChange

use of org.signal.storageservice.protos.groups.local.DecryptedGroupChange in project Signal-Android by WhisperSystems.

the class GroupChangeReconstructTest method new_invite_link_password.

@Test
public void new_invite_link_password() {
    ByteString password1 = ByteString.copyFrom(Util.getSecretBytes(16));
    ByteString password2 = ByteString.copyFrom(Util.getSecretBytes(16));
    DecryptedGroup from = DecryptedGroup.newBuilder().setInviteLinkPassword(password1).build();
    DecryptedGroup to = DecryptedGroup.newBuilder().setInviteLinkPassword(password2).build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().setNewInviteLinkPassword(password2).build(), decryptedGroupChange);
}
Also used : ByteString(com.google.protobuf.ByteString) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 18 with DecryptedGroupChange

use of org.signal.storageservice.protos.groups.local.DecryptedGroupChange in project Signal-Android by WhisperSystems.

the class GroupChangeReconstructTest method new_member.

@Test
public void new_member() {
    UUID uuidNew = UUID.randomUUID();
    DecryptedGroup from = DecryptedGroup.newBuilder().build();
    DecryptedGroup to = DecryptedGroup.newBuilder().addMembers(member(uuidNew)).build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().addNewMembers(member(uuidNew)).build(), decryptedGroupChange);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 19 with DecryptedGroupChange

use of org.signal.storageservice.protos.groups.local.DecryptedGroupChange in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_Test method field_17__changes_to_remove_missing_requesting_members_are_excluded.

@Test
public void field_17__changes_to_remove_missing_requesting_members_are_excluded() {
    UUID member1 = UUID.randomUUID();
    UUID member2 = UUID.randomUUID();
    UUID member3 = UUID.randomUUID();
    DecryptedGroup groupState = DecryptedGroup.newBuilder().addRequestingMembers(requestingMember(member2)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addDeleteRequestingMembers(UuidUtil.toByteString(member1)).addDeleteRequestingMembers(UuidUtil.toByteString(member2)).addDeleteRequestingMembers(UuidUtil.toByteString(member3)).build();
    GroupChange.Actions change = GroupChange.Actions.newBuilder().addDeleteRequestingMembers(GroupChange.Actions.DeleteRequestingMemberAction.newBuilder().setDeletedUserId(encrypt(member1))).addDeleteRequestingMembers(GroupChange.Actions.DeleteRequestingMemberAction.newBuilder().setDeletedUserId(encrypt(member2))).addDeleteRequestingMembers(GroupChange.Actions.DeleteRequestingMemberAction.newBuilder().setDeletedUserId(encrypt(member3))).build();
    GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
    GroupChange.Actions expected = GroupChange.Actions.newBuilder().addDeleteRequestingMembers(GroupChange.Actions.DeleteRequestingMemberAction.newBuilder().setDeletedUserId(encrypt(member2))).build();
    assertEquals(expected, resolvedActions);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) GroupChange(org.signal.storageservice.protos.groups.GroupChange) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 20 with DecryptedGroupChange

use of org.signal.storageservice.protos.groups.local.DecryptedGroupChange in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_Test method field_11__no_avatar_change_is_removed.

@Test
public void field_11__no_avatar_change_is_removed() {
    DecryptedGroup groupState = DecryptedGroup.newBuilder().setAvatar("Existing avatar").build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().setNewAvatar(DecryptedString.newBuilder().setValue("Existing avatar").build()).build();
    GroupChange.Actions change = GroupChange.Actions.newBuilder().setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder().setAvatar("Existing avatar possibly encrypted")).build();
    GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
    assertTrue(GroupChangeUtil.changeIsEmpty(resolvedActions));
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) GroupChange(org.signal.storageservice.protos.groups.GroupChange) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Aggregations

DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)486 Test (org.junit.Test)460 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)190 UUID (java.util.UUID)110 GroupChange (org.signal.storageservice.protos.groups.GroupChange)62 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)34 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)34 ByteString (com.google.protobuf.ByteString)18 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)14 NonNull (androidx.annotation.NonNull)12 DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)12 DecryptedGroupV2Context (org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context)12 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)12 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)12 DecryptedPendingMemberRemoval (org.signal.storageservice.protos.groups.local.DecryptedPendingMemberRemoval)10 DecryptedRequestingMember (org.signal.storageservice.protos.groups.local.DecryptedRequestingMember)10 Context (android.content.Context)8 DrawableRes (androidx.annotation.DrawableRes)8 Nullable (androidx.annotation.Nullable)8