Search in sources :

Example 81 with DecryptedGroup

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

the class GroupStateMapperTest method clears_changes_duplicated_in_the_placeholder.

@Test
public void clears_changes_duplicated_in_the_placeholder() {
    UUID newMemberUuid = UUID.randomUUID();
    DecryptedMember newMember = DecryptedMember.newBuilder().setUuid(UuidUtil.toByteString(newMemberUuid)).build();
    DecryptedMember existingMember = DecryptedMember.newBuilder().setUuid(UuidUtil.toByteString(UUID.randomUUID())).build();
    DecryptedGroup currentState = DecryptedGroup.newBuilder().setRevision(GroupStateMapper.PLACEHOLDER_REVISION).setTitle("Group Revision " + 8).addMembers(newMember).build();
    ServerGroupLogEntry log8 = new ServerGroupLogEntry(DecryptedGroup.newBuilder().setRevision(8).addMembers(newMember).addMembers(existingMember).setTitle("Group Revision " + 8).build(), DecryptedGroupChange.newBuilder().setRevision(8).setEditor(UuidUtil.toByteString(newMemberUuid)).addNewMembers(newMember).build());
    AdvanceGroupStateResult advanceGroupStateResult = GroupStateMapper.partiallyAdvanceGroupState(new GlobalGroupState(currentState, singletonList(log8)), LATEST);
    assertNotNull(log8.getGroup());
    assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
    assertNewState(new GlobalGroupState(log8.getGroup(), emptyList()), advanceGroupStateResult.getNewGlobalGroupState());
    assertEquals(log8.getGroup(), advanceGroupStateResult.getNewGlobalGroupState().getLocalState());
}
Also used : UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 82 with DecryptedGroup

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

the class GroupStateMapperTest method known_group_three_states_to_update_update_latest_handle_gap_with_changes.

@Test
public void known_group_three_states_to_update_update_latest_handle_gap_with_changes() {
    DecryptedGroup currentState = state(0);
    ServerGroupLogEntry log1 = serverLogEntry(1);
    DecryptedGroup state3a = DecryptedGroup.newBuilder().setRevision(3).setTitle("Group Revision " + 3).build();
    DecryptedGroup state3 = DecryptedGroup.newBuilder().setRevision(3).setTitle("Group Revision " + 3).setAvatar("Lost Avatar Update").build();
    ServerGroupLogEntry log3 = new ServerGroupLogEntry(state3, change(3));
    DecryptedGroup state4 = DecryptedGroup.newBuilder().setRevision(4).setTitle("Group Revision " + 4).setAvatar("Lost Avatar Update").build();
    ServerGroupLogEntry log4 = new ServerGroupLogEntry(state4, change(4));
    AdvanceGroupStateResult advanceGroupStateResult = GroupStateMapper.partiallyAdvanceGroupState(new GlobalGroupState(currentState, asList(log1, log3, log4)), LATEST);
    assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), new LocalGroupLogEntry(state3a, log3.getChange()), new LocalGroupLogEntry(state3, DecryptedGroupChange.newBuilder().setRevision(3).setNewAvatar(DecryptedString.newBuilder().setValue("Lost Avatar Update")).build()), asLocal(log4))));
    assertNewState(new GlobalGroupState(log4.getGroup(), emptyList()), advanceGroupStateResult.getNewGlobalGroupState());
    assertEquals(log4.getGroup(), advanceGroupStateResult.getNewGlobalGroupState().getLocalState());
}
Also used : DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 83 with DecryptedGroup

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

the class GroupStateMapperTest method known_group_two_states_to_update.

@Test
public void known_group_two_states_to_update() {
    DecryptedGroup currentState = state(0);
    ServerGroupLogEntry log1 = serverLogEntry(1);
    ServerGroupLogEntry log2 = serverLogEntry(2);
    AdvanceGroupStateResult advanceGroupStateResult = GroupStateMapper.partiallyAdvanceGroupState(new GlobalGroupState(currentState, asList(log1, log2)), 2);
    assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log2))));
    assertTrue(advanceGroupStateResult.getNewGlobalGroupState().getServerHistory().isEmpty());
    assertEquals(log2.getGroup(), advanceGroupStateResult.getNewGlobalGroupState().getLocalState());
}
Also used : DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 84 with DecryptedGroup

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

the class GroupStateMapperTest method local_up_to_date_no_repair_necessary.

@Test
public void local_up_to_date_no_repair_necessary() {
    DecryptedGroup currentState = state(6);
    ServerGroupLogEntry log6 = serverLogEntryWholeStateOnly(6);
    AdvanceGroupStateResult advanceGroupStateResult = GroupStateMapper.partiallyAdvanceGroupState(new GlobalGroupState(currentState, singletonList(log6)), LATEST);
    assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
    assertNewState(new GlobalGroupState(state(6), emptyList()), advanceGroupStateResult.getNewGlobalGroupState());
    assertEquals(state(6), advanceGroupStateResult.getNewGlobalGroupState().getLocalState());
}
Also used : DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 85 with DecryptedGroup

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

the class GroupProtoUtil method createDecryptedGroupV2Context.

public static DecryptedGroupV2Context createDecryptedGroupV2Context(@NonNull GroupMasterKey masterKey, @NonNull GroupMutation groupMutation, @Nullable GroupChange signedServerChange) {
    DecryptedGroupChange plainGroupChange = groupMutation.getGroupChange();
    DecryptedGroup decryptedGroup = groupMutation.getNewGroupState();
    int revision = plainGroupChange != null ? plainGroupChange.getRevision() : decryptedGroup.getRevision();
    SignalServiceProtos.GroupContextV2.Builder contextBuilder = SignalServiceProtos.GroupContextV2.newBuilder().setMasterKey(ByteString.copyFrom(masterKey.serialize())).setRevision(revision);
    if (signedServerChange != null) {
        contextBuilder.setGroupChange(signedServerChange.toByteString());
    }
    DecryptedGroupV2Context.Builder builder = DecryptedGroupV2Context.newBuilder().setContext(contextBuilder.build()).setGroupState(decryptedGroup);
    if (groupMutation.getPreviousGroupState() != null) {
        builder.setPreviousGroupState(groupMutation.getPreviousGroupState());
    }
    if (plainGroupChange != null) {
        builder.setChange(plainGroupChange);
    }
    return builder.build();
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) PartialDecryptedGroup(org.whispersystems.signalservice.api.groupsv2.PartialDecryptedGroup) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context)

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