Search in sources :

Example 6 with DecryptedGroup

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

the class DecryptedGroupUtil_apply_Test method apply_remove_requesting_member.

@Test
public void apply_remove_requesting_member() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedRequestingMember member1 = requestingMember(UUID.randomUUID());
    DecryptedRequestingMember member2 = requestingMember(UUID.randomUUID());
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(13).addRequestingMembers(member1).addRequestingMembers(member2).build(), DecryptedGroupChange.newBuilder().setRevision(14).addDeleteRequestingMembers(member1.getUuid()).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(14).addRequestingMembers(member2).build(), newGroup);
}
Also used : DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 7 with DecryptedGroup

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

the class DecryptedGroupUtil_apply_Test method promote_requesting_member.

@Test
public void promote_requesting_member() throws NotAbleToApplyGroupV2ChangeException {
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    UUID uuid3 = UUID.randomUUID();
    ProfileKey profileKey1 = newProfileKey();
    ProfileKey profileKey2 = newProfileKey();
    ProfileKey profileKey3 = newProfileKey();
    DecryptedRequestingMember member1 = requestingMember(uuid1, profileKey1);
    DecryptedRequestingMember member2 = requestingMember(uuid2, profileKey2);
    DecryptedRequestingMember member3 = requestingMember(uuid3, profileKey3);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(13).addRequestingMembers(member1).addRequestingMembers(member2).addRequestingMembers(member3).build(), DecryptedGroupChange.newBuilder().setRevision(14).addPromoteRequestingMembers(DecryptedApproveMember.newBuilder().setRole(Member.Role.DEFAULT).setUuid(member1.getUuid())).addPromoteRequestingMembers(DecryptedApproveMember.newBuilder().setRole(Member.Role.ADMINISTRATOR).setUuid(member2.getUuid())).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(14).addMembers(member(uuid1, profileKey1)).addMembers(admin(uuid2, profileKey2)).addRequestingMembers(member3).build(), newGroup);
}
Also used : DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) 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 8 with DecryptedGroup

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

the class DecryptedGroupUtil_apply_Test method apply_new_pending_member_already_pending.

@Test
public void apply_new_pending_member_already_pending() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    DecryptedPendingMember pending = pendingMember(UUID.randomUUID());
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending).build(), DecryptedGroupChange.newBuilder().setRevision(11).addNewPendingMembers(pending).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addPendingMembers(pending).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 9 with DecryptedGroup

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

the class GroupChangeUtil_resolveConflict_Test method field_9__promote_pending_members.

@Test
public void field_9__promote_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(member2)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addPromotePendingMembers(member(member1)).addPromotePendingMembers(member(member2)).addPromotePendingMembers(member(member3)).build();
    GroupChange.Actions change = GroupChange.Actions.newBuilder().addPromotePendingMembers(GroupChange.Actions.PromotePendingMemberAction.newBuilder().setPresentation(presentation(member1, randomProfileKey()))).addPromotePendingMembers(GroupChange.Actions.PromotePendingMemberAction.newBuilder().setPresentation(presentation(member2, profileKey2))).addPromotePendingMembers(GroupChange.Actions.PromotePendingMemberAction.newBuilder().setPresentation(presentation(member3, randomProfileKey()))).build();
    GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();
    GroupChange.Actions expected = GroupChange.Actions.newBuilder().addPromotePendingMembers(GroupChange.Actions.PromotePendingMemberAction.newBuilder().setPresentation(presentation(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 10 with DecryptedGroup

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

the class GroupChangeUtil_resolveConflict_Test method field_20__no_description_change_is_removed.

@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));
}
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

DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)328 Test (org.junit.Test)306 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)182 UUID (java.util.UUID)110 GroupChange (org.signal.storageservice.protos.groups.GroupChange)58 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)50 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)46 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)44 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)24 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)24 Group (org.signal.storageservice.protos.groups.Group)22 ByteString (com.google.protobuf.ByteString)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)12 DecryptedRequestingMember (org.signal.storageservice.protos.groups.local.DecryptedRequestingMember)8 NonNull (androidx.annotation.NonNull)6 ArrayList (java.util.ArrayList)6 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)6 Nullable (androidx.annotation.Nullable)4 WorkerThread (androidx.annotation.WorkerThread)4