Fix crash when registering with an existing recipient with the same PNI.
This commit is contained in:
parent
8648c74221
commit
15254ee720
2 changed files with 10 additions and 0 deletions
|
@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertNotEquals
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -20,6 +21,7 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||||
import org.whispersystems.libsignal.util.guava.Optional
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
import org.whispersystems.signalservice.api.push.ACI
|
import org.whispersystems.signalservice.api.push.ACI
|
||||||
|
import org.whispersystems.signalservice.api.push.PNI
|
||||||
import java.lang.IllegalArgumentException
|
import java.lang.IllegalArgumentException
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
|
@ -192,17 +194,21 @@ class RecipientDatabaseTest {
|
||||||
@Test
|
@Test
|
||||||
fun getAndPossiblyMerge_e164MapsToExistingUserButAciDoesNot_aciAndE164_2_highTrust() {
|
fun getAndPossiblyMerge_e164MapsToExistingUserButAciDoesNot_aciAndE164_2_highTrust() {
|
||||||
val existingId: RecipientId = recipientDatabase.getAndPossiblyMerge(ACI_A, E164_A, true)
|
val existingId: RecipientId = recipientDatabase.getAndPossiblyMerge(ACI_A, E164_A, true)
|
||||||
|
recipientDatabase.setPni(existingId, PNI_A)
|
||||||
|
|
||||||
val retrievedId: RecipientId = recipientDatabase.getAndPossiblyMerge(ACI_B, E164_A, true)
|
val retrievedId: RecipientId = recipientDatabase.getAndPossiblyMerge(ACI_B, E164_A, true)
|
||||||
|
recipientDatabase.setPni(retrievedId, PNI_A)
|
||||||
assertNotEquals(existingId, retrievedId)
|
assertNotEquals(existingId, retrievedId)
|
||||||
|
|
||||||
val retrievedRecipient = Recipient.resolved(retrievedId)
|
val retrievedRecipient = Recipient.resolved(retrievedId)
|
||||||
assertEquals(ACI_B, retrievedRecipient.requireAci())
|
assertEquals(ACI_B, retrievedRecipient.requireAci())
|
||||||
assertEquals(E164_A, retrievedRecipient.requireE164())
|
assertEquals(E164_A, retrievedRecipient.requireE164())
|
||||||
|
assertEquals(PNI_A, retrievedRecipient.pni.get())
|
||||||
|
|
||||||
val existingRecipient = Recipient.resolved(existingId)
|
val existingRecipient = Recipient.resolved(existingId)
|
||||||
assertEquals(ACI_A, existingRecipient.requireAci())
|
assertEquals(ACI_A, existingRecipient.requireAci())
|
||||||
assertFalse(existingRecipient.hasE164())
|
assertFalse(existingRecipient.hasE164())
|
||||||
|
assertNull(existingRecipient.pni.orNull())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** We never change the ACI of an existing row. New ACI = new person, regardless of trust. And low trust means we can’t take the e164. */
|
/** We never change the ACI of an existing row. New ACI = new person, regardless of trust. And low trust means we can’t take the e164. */
|
||||||
|
@ -542,6 +548,9 @@ class RecipientDatabaseTest {
|
||||||
val ACI_A = ACI.from(UUID.fromString("3436efbe-5a76-47fa-a98a-7e72c948a82e"))
|
val ACI_A = ACI.from(UUID.fromString("3436efbe-5a76-47fa-a98a-7e72c948a82e"))
|
||||||
val ACI_B = ACI.from(UUID.fromString("8de7f691-0b60-4a68-9cd9-ed2f8453f9ed"))
|
val ACI_B = ACI.from(UUID.fromString("8de7f691-0b60-4a68-9cd9-ed2f8453f9ed"))
|
||||||
|
|
||||||
|
val PNI_A = PNI.from(UUID.fromString("154b8d92-c960-4f6c-8385-671ad2ffb999"))
|
||||||
|
val PNI_B = PNI.from(UUID.fromString("ba92b1fb-cd55-40bf-adda-c35a85375533"))
|
||||||
|
|
||||||
const val E164_A = "+12221234567"
|
const val E164_A = "+12221234567"
|
||||||
const val E164_B = "+13331234567"
|
const val E164_B = "+13331234567"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1747,6 +1747,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
private fun removePhoneNumber(recipientId: RecipientId, db: SQLiteDatabase) {
|
private fun removePhoneNumber(recipientId: RecipientId, db: SQLiteDatabase) {
|
||||||
val values = ContentValues().apply {
|
val values = ContentValues().apply {
|
||||||
putNull(PHONE)
|
putNull(PHONE)
|
||||||
|
putNull(PNI_COLUMN)
|
||||||
}
|
}
|
||||||
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId))
|
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue