From bfcd57881e2aeb419bf2cc2680a38c70bc73cff6 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 11 Jul 2023 10:36:00 -0400 Subject: [PATCH] Add test to verify sync behavior during VERIFIED to DEFAULT change. --- ...TableTest_applyStorageSyncContactUpdate.kt | 60 +++++++++++++++++++ .../storage/StorageRecordUpdate.java | 4 +- build.gradle | 3 +- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 app/src/androidTest/java/org/thoughtcrime/securesms/database/RecipientTableTest_applyStorageSyncContactUpdate.kt diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/database/RecipientTableTest_applyStorageSyncContactUpdate.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/database/RecipientTableTest_applyStorageSyncContactUpdate.kt new file mode 100644 index 0000000000..9052393f02 --- /dev/null +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/database/RecipientTableTest_applyStorageSyncContactUpdate.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2023 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.thoughtcrime.securesms.database + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.thoughtcrime.securesms.dependencies.ApplicationDependencies +import org.thoughtcrime.securesms.recipients.Recipient +import org.thoughtcrime.securesms.storage.StorageRecordUpdate +import org.thoughtcrime.securesms.storage.StorageSyncModels +import org.thoughtcrime.securesms.testing.SignalActivityRule +import org.thoughtcrime.securesms.testing.assertIs +import org.thoughtcrime.securesms.util.MessageTableTestUtils +import org.whispersystems.signalservice.api.storage.SignalContactRecord +import org.whispersystems.signalservice.internal.storage.protos.ContactRecord + +@Suppress("ClassName") +@RunWith(AndroidJUnit4::class) +class RecipientTableTest_applyStorageSyncContactUpdate { + @get:Rule + val harness = SignalActivityRule() + + @Test + fun insertMessageOnVerifiedToDefault() { + // GIVEN + val identities = ApplicationDependencies.getProtocolStore().aci().identities() + val other = Recipient.resolved(harness.others[0]) + + MmsHelper.insert(recipient = other) + identities.setVerified(other.id, harness.othersKeys[0].publicKey, IdentityTable.VerifiedStatus.VERIFIED) + + val oldRecord: SignalContactRecord = StorageSyncModels.localToRemoteRecord(SignalDatabase.recipients.getRecordForSync(harness.others[0])!!).contact.get() + + val newProto = oldRecord + .toProto() + .toBuilder() + .setIdentityState(ContactRecord.IdentityState.DEFAULT) + .build() + val newRecord = SignalContactRecord(oldRecord.id, newProto) + + val update = StorageRecordUpdate(oldRecord, newRecord) + + // WHEN + val oldVerifiedStatus: IdentityTable.VerifiedStatus = identities.getIdentityRecord(other.id).get().verifiedStatus + SignalDatabase.recipients.applyStorageSyncContactUpdate(update) + val newVerifiedStatus: IdentityTable.VerifiedStatus = identities.getIdentityRecord(other.id).get().verifiedStatus + + // THEN + oldVerifiedStatus assertIs IdentityTable.VerifiedStatus.VERIFIED + newVerifiedStatus assertIs IdentityTable.VerifiedStatus.DEFAULT + + val messages = MessageTableTestUtils.getMessages(SignalDatabase.threads.getThreadIdFor(other.id)!!) + messages.first().isIdentityDefault assertIs true + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageRecordUpdate.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageRecordUpdate.java index 8deb401b59..b66da90d5e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageRecordUpdate.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageRecordUpdate.java @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.storage; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import org.whispersystems.signalservice.api.storage.SignalRecord; @@ -13,7 +14,8 @@ public class StorageRecordUpdate { private final E oldRecord; private final E newRecord; - StorageRecordUpdate(@NonNull E oldRecord, @NonNull E newRecord) { + @VisibleForTesting + public StorageRecordUpdate(@NonNull E oldRecord, @NonNull E newRecord) { this.oldRecord = oldRecord; this.newRecord = newRecord; } diff --git a/build.gradle b/build.gradle index 45f3e2b88a..404c858c3f 100644 --- a/build.gradle +++ b/build.gradle @@ -89,7 +89,8 @@ task qa { 'Signal-Android:ktlintCheck', ':libsignal-service:test', ':libsignal-service:ktlintCheck', - ':Signal-Android:assemblePlayProdRelease' + ':Signal-Android:assemblePlayProdRelease', + ':Signal-Android:compilePlayProdInstrumentationAndroidTestSources' } task clean(type: Delete) {