Search in sources :

Example 26 with DecryptedGroupChange

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

the class GroupChangeUtil_resolveConflict_Test method field_7__add_pending_members.

@Test
public void field_7__add_pending_members() {
    UUID member1 = UUID.randomUUID();
    UUID member2 = UUID.randomUUID();
    UUID member3 = UUID.randomUUID();
    ProfileKey profileKey2 = randomProfileKey();
    DecryptedGroup groupState = DecryptedGroup.newBuilder().addMembers(member(member1)).addPendingMembers(pendingMember(member3)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addNewPendingMembers(pendingMember(member1)).addNewPendingMembers(pendingMember(member2)).addNewPendingMembers(pendingMember(member3)).build();
    GroupChange.Actions change = GroupChange.Actions.newBuilder().addAddPendingMembers(GroupChange.Actions.AddPendingMemberAction.newBuilder().setAdded(PendingMember.newBuilder().setMember(encryptedMember(member1, randomProfileKey())))).addAddPendingMembers(GroupChange.Actions.AddPendingMemberAction.newBuilder().setAdded(PendingMember.newBuilder().setMember(encryptedMember(member2, profileKey2)))).addAddPendingMembers(GroupChange.Actions.AddPendingMemberAction.newBuilder().setAdded(PendingMember.newBuilder().setMember(encryptedMember(member3, randomProfileKey())))).build();
    GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
    GroupChange.Actions expected = GroupChange.Actions.newBuilder().addAddPendingMembers(GroupChange.Actions.AddPendingMemberAction.newBuilder().setAdded(PendingMember.newBuilder().setMember(encryptedMember(member2, profileKey2)))).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) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 27 with DecryptedGroupChange

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

the class GroupChangeReconstructTest method access_control_change_attributes.

@Test
public void access_control_change_attributes() {
    DecryptedGroup from = DecryptedGroup.newBuilder().setAccessControl(AccessControl.newBuilder().setAttributes(AccessControl.AccessRequired.MEMBER)).build();
    DecryptedGroup to = DecryptedGroup.newBuilder().setAccessControl(AccessControl.newBuilder().setAttributes(AccessControl.AccessRequired.ADMINISTRATOR)).build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().setNewAttributeAccess(AccessControl.AccessRequired.ADMINISTRATOR).build(), decryptedGroupChange);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 28 with DecryptedGroupChange

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

the class GroupChangeReconstructTest method title_change.

@Test
public void title_change() {
    DecryptedGroup from = DecryptedGroup.newBuilder().setTitle("A").build();
    DecryptedGroup to = DecryptedGroup.newBuilder().setTitle("B").build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().setNewTitle(DecryptedString.newBuilder().setValue("B")).build(), decryptedGroupChange);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 29 with DecryptedGroupChange

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

the class GroupChangeReconstructTest method empty_to_empty.

@Test
public void empty_to_empty() {
    DecryptedGroup from = DecryptedGroup.newBuilder().build();
    DecryptedGroup to = DecryptedGroup.newBuilder().build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().build(), decryptedGroupChange);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 30 with DecryptedGroupChange

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

the class GroupChangeReconstructTest method removed_member.

@Test
public void removed_member() {
    UUID uuidOld = UUID.randomUUID();
    DecryptedGroup from = DecryptedGroup.newBuilder().addMembers(member(uuidOld)).build();
    DecryptedGroup to = DecryptedGroup.newBuilder().build();
    DecryptedGroupChange decryptedGroupChange = GroupChangeReconstruct.reconstructGroupChange(from, to);
    assertEquals(DecryptedGroupChange.newBuilder().addDeleteMembers(UuidUtil.toByteString(uuidOld)).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)

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