mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 17:37:57 +00:00
fixup! Clean up any invalid group V1 ids in database.
This commit is contained in:
@@ -31,7 +31,7 @@ public class RecipientIdFollowUpJobMigrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void migrate_requestGroupInfoJob_good() throws Exception {
|
public void migrate_requestGroupInfoJob_good() throws Exception {
|
||||||
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "1")
|
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "1")
|
||||||
.putString("group_id", "__textsecure_group__!abcd")
|
.putString("group_id", "__textsecure_group__!abcdef0123456789abcdef0123456789")
|
||||||
.build());
|
.build());
|
||||||
RecipientIdFollowUpJobMigration subject = new RecipientIdFollowUpJobMigration();
|
RecipientIdFollowUpJobMigration subject = new RecipientIdFollowUpJobMigration();
|
||||||
JobData converted = subject.migrate(testData);
|
JobData converted = subject.migrate(testData);
|
||||||
@@ -39,7 +39,7 @@ public class RecipientIdFollowUpJobMigrationTest {
|
|||||||
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
|
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
|
||||||
assertNull(converted.getQueueKey());
|
assertNull(converted.getQueueKey());
|
||||||
assertEquals("1", converted.getData().getString("source"));
|
assertEquals("1", converted.getData().getString("source"));
|
||||||
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
|
assertEquals("__textsecure_group__!abcdef0123456789abcdef0123456789", converted.getData().getString("group_id"));
|
||||||
|
|
||||||
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,6 @@ import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
|||||||
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
||||||
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
||||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
||||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
|
||||||
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
|
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
|
||||||
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
@@ -88,7 +87,7 @@ public class RecipientIdJobMigrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void migrate_requestGroupInfoJob() throws Exception {
|
public void migrate_requestGroupInfoJob() throws Exception {
|
||||||
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "+16101234567")
|
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "+16101234567")
|
||||||
.putString("group_id", "__textsecure_group__!abcd")
|
.putString("group_id", "__textsecure_group__!abcdef0123456789abcdef0123456789")
|
||||||
.build());
|
.build());
|
||||||
mockRecipientResolve("+16101234567", 1);
|
mockRecipientResolve("+16101234567", 1);
|
||||||
|
|
||||||
@@ -98,7 +97,7 @@ public class RecipientIdJobMigrationTest {
|
|||||||
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
|
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
|
||||||
assertNull(converted.getQueueKey());
|
assertNull(converted.getQueueKey());
|
||||||
assertEquals("1", converted.getData().getString("source"));
|
assertEquals("1", converted.getData().getString("source"));
|
||||||
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
|
assertEquals("__textsecure_group__!abcdef0123456789abcdef0123456789", converted.getData().getString("group_id"));
|
||||||
|
|
||||||
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||||
}
|
}
|
||||||
@@ -185,7 +184,7 @@ public class RecipientIdJobMigrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void migrate_pushGroupUpdateJob() throws Exception {
|
public void migrate_pushGroupUpdateJob() throws Exception {
|
||||||
JobData testData = new JobData("PushGroupUpdateJob", null, new Data.Builder().putString("source", "+16101234567")
|
JobData testData = new JobData("PushGroupUpdateJob", null, new Data.Builder().putString("source", "+16101234567")
|
||||||
.putString("group_id", "__textsecure_group__!abcd")
|
.putString("group_id", "__textsecure_group__!abcdef0123456789abcdef0123456789")
|
||||||
.build());
|
.build());
|
||||||
mockRecipientResolve("+16101234567", 1);
|
mockRecipientResolve("+16101234567", 1);
|
||||||
|
|
||||||
@@ -195,7 +194,7 @@ public class RecipientIdJobMigrationTest {
|
|||||||
assertEquals("PushGroupUpdateJob", converted.getFactoryKey());
|
assertEquals("PushGroupUpdateJob", converted.getFactoryKey());
|
||||||
assertNull(converted.getQueueKey());
|
assertNull(converted.getQueueKey());
|
||||||
assertEquals("1", converted.getData().getString("source"));
|
assertEquals("1", converted.getData().getString("source"));
|
||||||
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
|
assertEquals("__textsecure_group__!abcdef0123456789abcdef0123456789", converted.getData().getString("group_id"));
|
||||||
|
|
||||||
new PushGroupUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
new PushGroupUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
import static org.powermock.api.mockito.PowerMockito.mock;
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
import static org.thoughtcrime.securesms.testutil.TestHelpers.byteArray;
|
import static org.thoughtcrime.securesms.testutil.TestHelpers.byteArray;
|
||||||
|
import static org.thoughtcrime.securesms.testutil.ZkGroupLibraryUtil.assumeZkGroupSupportedOnOS;
|
||||||
|
|
||||||
public final class GroupV1ConflictMergerTest {
|
public final class GroupV1ConflictMergerTest {
|
||||||
|
|
||||||
@@ -27,13 +28,13 @@ public final class GroupV1ConflictMergerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void merge_alwaysPreferRemote() {
|
public void merge_alwaysPreferRemote() {
|
||||||
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100))
|
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100, 16))
|
||||||
.setBlocked(false)
|
.setBlocked(false)
|
||||||
.setProfileSharingEnabled(false)
|
.setProfileSharingEnabled(false)
|
||||||
.setArchived(false)
|
.setArchived(false)
|
||||||
.setForcedUnread(false)
|
.setForcedUnread(false)
|
||||||
.build();
|
.build();
|
||||||
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100))
|
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100, 16))
|
||||||
.setBlocked(true)
|
.setBlocked(true)
|
||||||
.setProfileSharingEnabled(true)
|
.setProfileSharingEnabled(true)
|
||||||
.setArchived(true)
|
.setArchived(true)
|
||||||
@@ -43,7 +44,7 @@ public final class GroupV1ConflictMergerTest {
|
|||||||
SignalGroupV1Record merged = new GroupV1ConflictMerger(Collections.singletonList(local), id -> false).merge(remote, local, KEY_GENERATOR);
|
SignalGroupV1Record merged = new GroupV1ConflictMerger(Collections.singletonList(local), id -> false).merge(remote, local, KEY_GENERATOR);
|
||||||
|
|
||||||
assertArrayEquals(remote.getId().getRaw(), merged.getId().getRaw());
|
assertArrayEquals(remote.getId().getRaw(), merged.getId().getRaw());
|
||||||
assertArrayEquals(byteArray(100), merged.getGroupId());
|
assertArrayEquals(byteArray(100, 16), merged.getGroupId());
|
||||||
assertFalse(merged.isProfileSharingEnabled());
|
assertFalse(merged.isProfileSharingEnabled());
|
||||||
assertFalse(merged.isBlocked());
|
assertFalse(merged.isBlocked());
|
||||||
assertFalse(merged.isArchived());
|
assertFalse(merged.isArchived());
|
||||||
@@ -52,12 +53,12 @@ public final class GroupV1ConflictMergerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void merge_returnRemoteIfEndResultMatchesRemote() {
|
public void merge_returnRemoteIfEndResultMatchesRemote() {
|
||||||
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100))
|
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100, 16))
|
||||||
.setBlocked(false)
|
.setBlocked(false)
|
||||||
.setProfileSharingEnabled(true)
|
.setProfileSharingEnabled(true)
|
||||||
.setArchived(true)
|
.setArchived(true)
|
||||||
.build();
|
.build();
|
||||||
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100))
|
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100, 16))
|
||||||
.setBlocked(true)
|
.setBlocked(true)
|
||||||
.setProfileSharingEnabled(false)
|
.setProfileSharingEnabled(false)
|
||||||
.setArchived(false)
|
.setArchived(false)
|
||||||
@@ -70,6 +71,8 @@ public final class GroupV1ConflictMergerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void merge_excludeBadGroupId() {
|
public void merge_excludeBadGroupId() {
|
||||||
|
assumeZkGroupSupportedOnOS();
|
||||||
|
|
||||||
SignalGroupV1Record badRemote = new SignalGroupV1Record.Builder(byteArray(1), badGroupKey(99))
|
SignalGroupV1Record badRemote = new SignalGroupV1Record.Builder(byteArray(1), badGroupKey(99))
|
||||||
.setBlocked(false)
|
.setBlocked(false)
|
||||||
.setProfileSharingEnabled(true)
|
.setProfileSharingEnabled(true)
|
||||||
@@ -89,6 +92,8 @@ public final class GroupV1ConflictMergerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void merge_excludeMigratedGroupId() {
|
public void merge_excludeMigratedGroupId() {
|
||||||
|
assumeZkGroupSupportedOnOS();
|
||||||
|
|
||||||
GroupId.V1 v1Id = GroupId.v1orThrow(groupKey(1));
|
GroupId.V1 v1Id = GroupId.v1orThrow(groupKey(1));
|
||||||
GroupId.V2 v2Id = v1Id.deriveV2MigrationGroupId();
|
GroupId.V2 v2Id = v1Id.deriveV2MigrationGroupId();
|
||||||
|
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package org.thoughtcrime.securesms.testutil;
|
||||||
|
|
||||||
|
import org.signal.zkgroup.internal.Native;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeNoException;
|
||||||
|
|
||||||
|
public final class ZkGroupLibraryUtil {
|
||||||
|
|
||||||
|
private ZkGroupLibraryUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to initialize the ZkGroup Native class, which will load the native binaries.
|
||||||
|
* <p>
|
||||||
|
* If that fails to link, then on Unix, it will fail as we rely on that for CI.
|
||||||
|
* <p>
|
||||||
|
* If that fails to link, and it's not Unix, it will skip the test via assumption violation.
|
||||||
|
*/
|
||||||
|
public static void assumeZkGroupSupportedOnOS() {
|
||||||
|
try {
|
||||||
|
Class.forName(Native.class.getName());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
fail();
|
||||||
|
} catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
|
||||||
|
String osName = System.getProperty("os.name");
|
||||||
|
|
||||||
|
if (isUnix(osName)) {
|
||||||
|
fail("Not able to link native ZkGroup on a key OS: " + osName);
|
||||||
|
} else {
|
||||||
|
assumeNoException("Not able to link native ZkGroup on this operating system: " + osName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isUnix(String osName) {
|
||||||
|
assertNotNull(osName);
|
||||||
|
osName = osName.toLowerCase();
|
||||||
|
return osName.contains("nix") || osName.contains("nux") || osName.contains("aix");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user