Revert "Ensure GV1 length is exactly the length expected."

This reverts commit 8e962bf992.
master
Greyson Parrelli 2020-07-22 22:45:19 -04:00
parent dadb2f9d37
commit fc4e690996
6 changed files with 18 additions and 29 deletions

View File

@ -40,7 +40,7 @@ public abstract class GroupId {
}
public static @NonNull GroupId.V1 v1(byte[] gv1GroupIdBytes) throws BadGroupIdException {
if (gv1GroupIdBytes.length != MMS_BYTE_LENGTH) {
if (gv1GroupIdBytes.length == V2_BYTE_LENGTH) {
throw new BadGroupIdException();
}
return new GroupId.V1(gv1GroupIdBytes);

View File

@ -276,16 +276,6 @@ public final class GroupIdTest {
GroupId.v2orThrow(Hex.fromStringCondensed("000102030405060708090a0b0c0d0e0f"));
}
@Test(expected = BadGroupIdException.class)
public void cannot_create_v1_with_a_bad_length() throws IOException, BadGroupIdException {
GroupId.v1(Hex.fromStringCondensed("000102030405060708090a0b0c0d0e0fff"));
}
@Test(expected = AssertionError.class)
public void cannot_create_v1_with_a_bad_length_assert() throws IOException {
GroupId.v1orThrow(Hex.fromStringCondensed("000102030405060708090a0b0c0d0e0fff"));
}
@Test
public void create_mms() {
GroupId.Mms mms = GroupId.createMms(mockRandom(new byte[]{ 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8 }));

View File

@ -31,7 +31,7 @@ public class RecipientIdFollowUpJobMigrationTest {
@Test
public void migrate_requestGroupInfoJob_good() throws Exception {
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "1")
.putString("group_id", "__textsecure_group__!abcdef01234567899876543210fedcba")
.putString("group_id", "__textsecure_group__!abcd")
.build());
RecipientIdFollowUpJobMigration subject = new RecipientIdFollowUpJobMigration();
JobData converted = subject.migrate(testData);
@ -39,7 +39,7 @@ public class RecipientIdFollowUpJobMigrationTest {
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
assertEquals("1", converted.getData().getString("source"));
assertEquals("__textsecure_group__!abcdef01234567899876543210fedcba", converted.getData().getString("group_id"));
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}

View File

@ -88,7 +88,7 @@ public class RecipientIdJobMigrationTest {
@Test
public void migrate_requestGroupInfoJob() throws Exception {
JobData testData = new JobData("RequestGroupInfoJob", null, new Data.Builder().putString("source", "+16101234567")
.putString("group_id", "__textsecure_group__!abcdef01234567899876543210fedcba")
.putString("group_id", "__textsecure_group__!abcd")
.build());
mockRecipientResolve("+16101234567", 1);
@ -98,7 +98,7 @@ public class RecipientIdJobMigrationTest {
assertEquals("RequestGroupInfoJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
assertEquals("1", converted.getData().getString("source"));
assertEquals("__textsecure_group__!abcdef01234567899876543210fedcba", converted.getData().getString("group_id"));
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
new RequestGroupInfoJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
@ -185,7 +185,7 @@ public class RecipientIdJobMigrationTest {
@Test
public void migrate_pushGroupUpdateJob() throws Exception {
JobData testData = new JobData("PushGroupUpdateJob", null, new Data.Builder().putString("source", "+16101234567")
.putString("group_id", "__textsecure_group__!abcdef01234567899876543210fedcba")
.putString("group_id", "__textsecure_group__!abcd")
.build());
mockRecipientResolve("+16101234567", 1);
@ -195,7 +195,7 @@ public class RecipientIdJobMigrationTest {
assertEquals("PushGroupUpdateJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
assertEquals("1", converted.getData().getString("source"));
assertEquals("__textsecure_group__!abcdef01234567899876543210fedcba", converted.getData().getString("group_id"));
assertEquals("__textsecure_group__!abcd", converted.getData().getString("group_id"));
new PushGroupUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}

View File

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.storage;
import org.junit.Test;
import org.thoughtcrime.securesms.storage.GroupV1ConflictMerger;
import org.thoughtcrime.securesms.storage.StorageSyncHelper.KeyGenerator;
import org.whispersystems.signalservice.api.storage.SignalGroupV1Record;
@ -15,22 +16,20 @@ import static org.thoughtcrime.securesms.testutil.TestHelpers.byteArray;
public class GroupV1ConflictMergerTest {
private static final byte[] GENERATED_KEY = byteArray(8675309);
private static final KeyGenerator KEY_GENERATOR = mock(KeyGenerator.class);
private static final byte[] V1_GROUP_ID = byteArray(100, 16);
private static byte[] GENERATED_KEY = byteArray(8675309);
private static KeyGenerator KEY_GENERATOR = mock(KeyGenerator.class);
static {
when(KEY_GENERATOR.generate()).thenReturn(GENERATED_KEY);
}
@Test
public void merge_alwaysPreferRemote_exceptProfileSharingIsEitherOr() {
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), V1_GROUP_ID)
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100))
.setBlocked(false)
.setProfileSharingEnabled(false)
.setArchived(false)
.build();
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), V1_GROUP_ID)
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100))
.setBlocked(true)
.setProfileSharingEnabled(true)
.setArchived(true)
@ -39,19 +38,19 @@ public class GroupV1ConflictMergerTest {
SignalGroupV1Record merged = new GroupV1ConflictMerger(Collections.singletonList(local)).merge(remote, local, KEY_GENERATOR);
assertArrayEquals(GENERATED_KEY, merged.getId().getRaw());
assertArrayEquals(V1_GROUP_ID, merged.getGroupId());
assertArrayEquals(byteArray(100), merged.getGroupId());
assertFalse(merged.isBlocked());
assertFalse(merged.isArchived());
}
@Test
public void merge_returnRemoteIfEndResultMatchesRemote() {
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), V1_GROUP_ID)
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100))
.setBlocked(false)
.setProfileSharingEnabled(true)
.setArchived(true)
.build();
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), V1_GROUP_ID)
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100))
.setBlocked(true)
.setProfileSharingEnabled(false)
.setArchived(false)
@ -64,12 +63,12 @@ public class GroupV1ConflictMergerTest {
@Test
public void merge_returnLocalIfEndResultMatchesLocal() {
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), V1_GROUP_ID)
SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100))
.setBlocked(false)
.setProfileSharingEnabled(false)
.setArchived(false)
.build();
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), V1_GROUP_ID)
SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100))
.setBlocked(false)
.setProfileSharingEnabled(true)
.setArchived(false)

View File

@ -417,7 +417,7 @@ public final class StorageSyncHelperTest {
boolean blocked,
boolean profileSharing)
{
return new SignalGroupV1Record.Builder(byteArray(key), byteArray(groupId, 16)).setBlocked(blocked).setProfileSharingEnabled(profileSharing).build();
return new SignalGroupV1Record.Builder(byteArray(key), byteArray(groupId)).setBlocked(blocked).setProfileSharingEnabled(profileSharing).build();
}
private static SignalGroupV2Record groupV2(int key,