mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 11:45:28 +00:00
Add Group Send Endorsements support.
This commit is contained in:
@@ -67,7 +67,7 @@ class ChangeSet {
|
||||
}
|
||||
|
||||
fun toApiResponse(): GroupHistoryPage {
|
||||
return GroupHistoryPage(changeSet.map { DecryptedGroupChangeLog(it.groupSnapshot, it.groupChange) }, GroupHistoryPage.PagingData.NONE)
|
||||
return GroupHistoryPage(changeSet.map { DecryptedGroupChangeLog(it.groupSnapshot, it.groupChange) }, null, GroupHistoryPage.PagingData.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,8 @@ fun groupRecord(
|
||||
decryptedGroup.revision,
|
||||
decryptedGroup.encode(),
|
||||
distributionId,
|
||||
System.currentTimeMillis()
|
||||
System.currentTimeMillis(),
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ object RecipientDatabaseTestUtils {
|
||||
profileSharing: Boolean = false,
|
||||
lastProfileFetch: Long = 0L,
|
||||
notificationChannel: String? = null,
|
||||
unidentifiedAccessMode: RecipientTable.UnidentifiedAccessMode = RecipientTable.UnidentifiedAccessMode.UNKNOWN,
|
||||
sealedSenderAccessMode: RecipientTable.SealedSenderAccessMode = RecipientTable.SealedSenderAccessMode.UNKNOWN,
|
||||
capabilities: Long = 0L,
|
||||
storageId: ByteArray? = null,
|
||||
mentionSetting: RecipientTable.MentionSetting = RecipientTable.MentionSetting.ALWAYS_NOTIFY,
|
||||
@@ -121,7 +121,7 @@ object RecipientDatabaseTestUtils {
|
||||
profileSharing = profileSharing,
|
||||
lastProfileFetch = lastProfileFetch,
|
||||
notificationChannel = notificationChannel,
|
||||
unidentifiedAccessMode = unidentifiedAccessMode,
|
||||
sealedSenderAccessMode = sealedSenderAccessMode,
|
||||
capabilities = RecipientRecord.Capabilities(
|
||||
rawBits = capabilities,
|
||||
deleteSync = Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientTable.Capabilities.DELETE_SYNC, RecipientTable.Capabilities.BIT_LENGTH).toInt())
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.signal.libsignal.protocol.logging.SignalProtocolLogger
|
||||
import org.signal.libsignal.protocol.logging.SignalProtocolLoggerProvider
|
||||
import org.signal.libsignal.zkgroup.groups.GroupMasterKey
|
||||
import org.signal.libsignal.zkgroup.groups.GroupSecretParams
|
||||
import org.signal.storageservice.protos.groups.GroupChangeResponse
|
||||
import org.signal.storageservice.protos.groups.Member
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedGroup
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedMember
|
||||
@@ -111,9 +112,9 @@ class GroupManagerV2Test_edit {
|
||||
|
||||
every { groupTable.getGroup(groupId) } returns data.groupRecord
|
||||
every { groupTable.requireGroup(groupId) } returns data.groupRecord.get()
|
||||
every { groupTable.update(any<GroupId.V2>(), any()) } returns Unit
|
||||
every { groupTable.update(any<GroupId.V2>(), any(), any()) } returns Unit
|
||||
every { sendGroupUpdateHelper.sendGroupUpdate(masterKey, any(), any(), any()) } returns GroupManagerV2.RecipientAndThread(Recipient.UNKNOWN, 1)
|
||||
every { groupsV2API.patchGroup(any(), any(), any()) } returns data.groupChange!!
|
||||
every { groupsV2API.patchGroup(any(), any(), any()) } returns GroupChangeResponse(groupChange = data.groupChange!!)
|
||||
}
|
||||
|
||||
private fun editGroup(perform: GroupManagerV2.GroupEditor.() -> Unit) {
|
||||
@@ -122,7 +123,7 @@ class GroupManagerV2Test_edit {
|
||||
|
||||
private fun then(then: (DecryptedGroup) -> Unit) {
|
||||
val decryptedGroupArg = slot<DecryptedGroup>()
|
||||
verify { groupTable.update(groupId, capture(decryptedGroupArg)) }
|
||||
verify { groupTable.update(groupId, capture(decryptedGroupArg), any()) }
|
||||
then(decryptedGroupArg.captured)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class GroupStatePatcherTest {
|
||||
|
||||
@Test
|
||||
public void unknown_group_with_no_states_to_update() {
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, emptyList()), 10);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, emptyList(), null), 10);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -52,7 +52,7 @@ public final class GroupStatePatcherTest {
|
||||
public void known_group_with_no_states_to_update() {
|
||||
DecryptedGroup currentState = state(0);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, emptyList()), 10);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, emptyList(), null), 10);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -63,7 +63,7 @@ public final class GroupStatePatcherTest {
|
||||
public void unknown_group_single_state_to_update() {
|
||||
DecryptedGroupChangeLog log0 = serverLogEntry(0);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, singletonList(log0)), 10);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, singletonList(log0), null), 10);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(asLocal(log0))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -75,7 +75,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroup currentState = state(0);
|
||||
DecryptedGroupChangeLog log1 = serverLogEntry(1);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log1)), 1);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log1), null), 1);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(asLocal(log1))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -88,7 +88,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log1 = serverLogEntry(1);
|
||||
DecryptedGroupChangeLog log2 = serverLogEntry(2);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2)), 2);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2), null), 2);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log2))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -101,7 +101,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log1 = serverLogEntry(1);
|
||||
DecryptedGroupChangeLog log2 = serverLogEntry(2);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2)), 2);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2), null), 2);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(asLocal(log2))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -115,7 +115,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log2 = serverLogEntry(2);
|
||||
DecryptedGroupChangeLog log3 = serverLogEntry(3);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3)), 2);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3), null), 2);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log2))));
|
||||
assertNewState(log2.getGroup(), singletonList(log3), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -129,7 +129,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log2 = serverLogEntry(2);
|
||||
DecryptedGroupChangeLog log3 = serverLogEntry(3);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log2), asLocal(log3))));
|
||||
assertNewState(log3.getGroup(), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -142,7 +142,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log1 = serverLogEntry(Integer.MAX_VALUE - 1);
|
||||
DecryptedGroupChangeLog log2 = serverLogEntry(Integer.MAX_VALUE);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log2))));
|
||||
assertNewState(log2.getGroup(), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -153,7 +153,7 @@ public final class GroupStatePatcherTest {
|
||||
public void unknown_group_single_state_to_update_with_missing_change() {
|
||||
DecryptedGroupChangeLog log0 = serverLogEntryWholeStateOnly(0);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, singletonList(log0)), 10);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(null, singletonList(log0), null), 10);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(asLocal(log0))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -165,7 +165,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroup currentState = state(0);
|
||||
DecryptedGroupChangeLog log1 = serverLogEntryWholeStateOnly(1);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log1)), 1);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log1), null), 1);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(localLogEntryNoEditor(1))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -179,7 +179,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log2 = serverLogEntryWholeStateOnly(2);
|
||||
DecryptedGroupChangeLog log3 = serverLogEntry(3);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2, log3), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), localLogEntryNoEditor(2), asLocal(log3))));
|
||||
assertNewState(log3.getGroup(), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -192,7 +192,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log1 = serverLogEntry(1);
|
||||
DecryptedGroupChangeLog log3 = serverLogEntry(3);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log3)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log3), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1), asLocal(log3))));
|
||||
assertNewState(log3.getGroup(), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -220,7 +220,7 @@ public final class GroupStatePatcherTest {
|
||||
.build();
|
||||
DecryptedGroupChangeLog log4 = new DecryptedGroupChangeLog(state4, change(4));
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log3, log4)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log3, log4), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1),
|
||||
new AppliedGroupChangeLog(state3a, log3.getChange()),
|
||||
@@ -241,7 +241,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log7 = serverLogEntryWholeStateOnly(7);
|
||||
DecryptedGroupChangeLog log8 = serverLogEntryWholeStateOnly(8);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log6, log7, log8)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log6, log7, log8), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(localLogEntryNoEditor(6), localLogEntryNoEditor(7), localLogEntryNoEditor(8))));
|
||||
assertNewState(log8.getGroup(), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -255,7 +255,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroupChangeLog log8 = logEntryMissingState(8);
|
||||
DecryptedGroupChangeLog log9 = logEntryMissingState(9);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log7, log8, log9)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log7, log8, log9), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(serverLogEntry(7)), asLocal(serverLogEntry(8)), asLocal(serverLogEntry(9)))));
|
||||
assertNewState(state(9), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -287,7 +287,7 @@ public final class GroupStatePatcherTest {
|
||||
.build(),
|
||||
change(9));
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log7, log8, log9)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log7, log8, log9), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log7),
|
||||
new AppliedGroupChangeLog(state7b, log8.getChange()),
|
||||
@@ -305,7 +305,7 @@ public final class GroupStatePatcherTest {
|
||||
DecryptedGroup currentState = state(6);
|
||||
DecryptedGroupChangeLog log6 = serverLogEntryWholeStateOnly(6);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log6)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log6), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
|
||||
assertNewState(state(6), emptyList(), advanceGroupStateResult.getUpdatedGroupState(), advanceGroupStateResult.getRemainingRemoteGroupChanges());
|
||||
@@ -320,7 +320,7 @@ public final class GroupStatePatcherTest {
|
||||
.build();
|
||||
DecryptedGroupChangeLog log6 = serverLogEntry(6);
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log6)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log6), null), LATEST);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(asLocal(log6))));
|
||||
assertTrue(advanceGroupStateResult.getRemainingRemoteGroupChanges().isEmpty());
|
||||
@@ -352,7 +352,7 @@ public final class GroupStatePatcherTest {
|
||||
.newMembers(Collections.singletonList(newMember))
|
||||
.build());
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8), null), LATEST);
|
||||
|
||||
assertNotNull(log8.getGroup());
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(emptyList()));
|
||||
@@ -392,7 +392,7 @@ public final class GroupStatePatcherTest {
|
||||
.newMembers(Collections.singletonList(newMember))
|
||||
.build();
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8), null), LATEST);
|
||||
|
||||
assertNotNull(log8.getGroup());
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(new AppliedGroupChangeLog(log8.getGroup(), expectedChange))));
|
||||
@@ -433,7 +433,7 @@ public final class GroupStatePatcherTest {
|
||||
.newAvatar(new DecryptedString.Builder().value_("Group Avatar " + 8).build())
|
||||
.build();
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8)), LATEST);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, singletonList(log8), null), LATEST);
|
||||
|
||||
assertNotNull(log8.getGroup());
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(singletonList(new AppliedGroupChangeLog(log8.getGroup(), expectedChange))));
|
||||
@@ -454,7 +454,7 @@ public final class GroupStatePatcherTest {
|
||||
.newTitle(new DecryptedString.Builder().value_(log1.getGroup().title).build())
|
||||
.build());
|
||||
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2)), 2);
|
||||
AdvanceGroupStateResult advanceGroupStateResult = GroupStatePatcher.applyGroupStateDiff(new GroupStateDiff(currentState, asList(log1, log2), null), 2);
|
||||
|
||||
assertThat(advanceGroupStateResult.getProcessedLogEntries(), is(asList(asLocal(log1),
|
||||
new AppliedGroupChangeLog(log2.getGroup(), new DecryptedGroupChange.Builder()
|
||||
|
||||
@@ -56,9 +56,12 @@ import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob
|
||||
import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger
|
||||
import org.thoughtcrime.securesms.testutil.SystemOutLogger
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupResponse
|
||||
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations
|
||||
import org.whispersystems.signalservice.api.groupsv2.NotAbleToApplyGroupV2ChangeException
|
||||
import org.whispersystems.signalservice.api.groupsv2.ReceivedGroupSendEndorsements
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceIds
|
||||
@@ -88,6 +91,7 @@ class GroupsV2StateProcessorTest {
|
||||
private lateinit var recipientTable: RecipientTable
|
||||
private lateinit var groupsV2API: GroupsV2Api
|
||||
private lateinit var groupsV2Authorization: GroupsV2Authorization
|
||||
private lateinit var groupsV2Operations: GroupsV2Operations
|
||||
private lateinit var profileAndMessageHelper: ProfileAndMessageHelper
|
||||
private lateinit var jobManager: JobManager
|
||||
|
||||
@@ -104,6 +108,7 @@ class GroupsV2StateProcessorTest {
|
||||
groupTable = mockk()
|
||||
recipientTable = mockk()
|
||||
groupsV2API = mockk()
|
||||
groupsV2Operations = mockk()
|
||||
groupsV2Authorization = mockk()
|
||||
profileAndMessageHelper = spyk(ProfileAndMessageHelper(serviceIds.aci, masterKey, groupId))
|
||||
jobManager = mockk()
|
||||
@@ -112,6 +117,7 @@ class GroupsV2StateProcessorTest {
|
||||
every { AppDependencies.jobManager } returns jobManager
|
||||
every { AppDependencies.signalServiceAccountManager.getGroupsV2Api() } returns groupsV2API
|
||||
every { AppDependencies.groupsV2Authorization } returns groupsV2Authorization
|
||||
every { AppDependencies.groupsV2Operations } returns groupsV2Operations
|
||||
|
||||
mockkObject(SignalDatabase)
|
||||
every { SignalDatabase.groups } returns groupTable
|
||||
@@ -120,6 +126,8 @@ class GroupsV2StateProcessorTest {
|
||||
mockkObject(ProfileAndMessageHelper)
|
||||
every { ProfileAndMessageHelper.create(any(), any(), any()) } returns profileAndMessageHelper
|
||||
|
||||
every { groupsV2Operations.forGroup(secretParams) } answers { callOriginal() }
|
||||
|
||||
processor = GroupsV2StateProcessor.forGroup(serviceIds, masterKey, secretParams)
|
||||
}
|
||||
|
||||
@@ -142,11 +150,11 @@ class GroupsV2StateProcessorTest {
|
||||
every { groupsV2Authorization.getAuthorizationForToday(serviceIds, secretParams) } returns null
|
||||
|
||||
if (data.expectTableUpdate) {
|
||||
justRun { groupTable.update(any<GroupMasterKey>(), any<DecryptedGroup>()) }
|
||||
justRun { groupTable.update(any<GroupMasterKey>(), any<DecryptedGroup>(), any<ReceivedGroupSendEndorsements>()) }
|
||||
}
|
||||
|
||||
if (data.expectTableCreate) {
|
||||
every { groupTable.create(any<GroupMasterKey>(), any<DecryptedGroup>()) } returns groupId
|
||||
every { groupTable.create(any<GroupMasterKey>(), any<DecryptedGroup>(), any<ReceivedGroupSendEndorsements>()) } returns groupId
|
||||
}
|
||||
|
||||
if (data.expectTableUpdate || data.expectTableCreate) {
|
||||
@@ -155,11 +163,11 @@ class GroupsV2StateProcessorTest {
|
||||
}
|
||||
|
||||
data.serverState?.let { serverState ->
|
||||
every { groupsV2API.getGroup(any(), any()) } returns serverState
|
||||
every { groupsV2API.getGroup(any(), any()) } returns DecryptedGroupResponse(serverState, null)
|
||||
}
|
||||
|
||||
data.changeSet?.let { changeSet ->
|
||||
every { groupsV2API.getGroupHistoryPage(any(), data.requestedRevision, any(), data.includeFirst) } returns changeSet.toApiResponse()
|
||||
every { groupsV2API.getGroupHistoryPage(any(), data.requestedRevision, any(), data.includeFirst, 0) } returns changeSet.toApiResponse()
|
||||
}
|
||||
|
||||
every { groupsV2API.getGroupAsResult(any(), any()) } answers { callOriginal() }
|
||||
@@ -241,7 +249,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("title changed to match server", result.latestServer!!.title, `is`("Asdf"))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -279,7 +287,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(7))
|
||||
assertThat("title changed on server to final result", result.latestServer!!.title, `is`("Asdf!"))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -323,7 +331,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("title changed on server to final result", result.latestServer!!.title, `is`("And beyond"))
|
||||
assertThat("Description updated in change after full snapshot", result.latestServer!!.description, `is`("Description"))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -351,7 +359,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("revision matches peer change", result.latestServer!!.revision, `is`(6))
|
||||
assertThat("timer changed by peer change", result.latestServer!!.disappearingMessagesTimer!!.duration, `is`(5000))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -383,7 +391,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("member promoted by peer change", result.latestServer!!.members.map { it.aciBytes }, hasItem(selfAci.toByteString()))
|
||||
|
||||
verify { jobManager.add(ofType(DirectoryRefreshJob::class)) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -426,7 +434,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(2))
|
||||
|
||||
verify { groupsV2API.getGroupHistoryPage(secretParams, 1, any(), false) }
|
||||
verify { groupsV2API.getGroupHistoryPage(secretParams, 1, any(), false, 0) }
|
||||
|
||||
unmockkStatic(DecryptedGroupUtil::class)
|
||||
}
|
||||
@@ -485,7 +493,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(3))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -513,7 +521,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(2))
|
||||
|
||||
verify { groupTable.create(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.create(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -551,7 +559,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("title matches that as it was in revision added", result.latestServer!!.title, `is`("Baking Signal for Science"))
|
||||
|
||||
verify { jobManager.add(ofType(RequestGroupV2InfoJob::class)) }
|
||||
verify { groupTable.create(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.create(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -577,7 +585,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches latest server", result.latestServer!!.revision, `is`(10))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -613,7 +621,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(3))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -662,7 +670,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("title matches revision approved at", result.latestServer!!.title, `is`("Beam me up"))
|
||||
|
||||
verify { jobManager.add(ofType(RequestGroupV2InfoJob::class)) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -705,7 +713,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("local should update to server", result.updateStatus, `is`(GroupUpdateResult.UpdateStatus.GROUP_UPDATED))
|
||||
assertThat("revision matches latest revision on server", result.latestServer!!.revision, `is`(101))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -756,7 +764,7 @@ class GroupsV2StateProcessorTest {
|
||||
|
||||
assertThat("group update messages contains new member add", updateMessageContextArgs.map { it.change!!.newMembers }, hasItem(hasItem(secondOther)))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -792,7 +800,7 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("group update messages contains new member add", updateMessageContextArgs.map { it.change!!.newMembers }, hasItem(hasItem(secondOther)))
|
||||
assertThat("group update messages contains title change", updateMessageContextArgs.mapNotNull { it.change!!.newTitle }.any { it.value_ == "Changed" })
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -874,6 +882,6 @@ class GroupsV2StateProcessorTest {
|
||||
assertThat("revision matches server", result.latestServer!!.revision, `is`(10))
|
||||
assertThat("title changed on server to final result", result.latestServer!!.title, `is`("Asdf!"))
|
||||
|
||||
verify { groupTable.update(masterKey, result.latestServer!!) }
|
||||
verify { groupTable.update(masterKey, result.latestServer!!, null) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user