Fix unexpected SSE's.

Fixes #13115
This commit is contained in:
Greyson Parrelli
2023-08-18 11:07:12 -04:00
parent e93c6957ac
commit 587cb5de16
3 changed files with 81 additions and 16 deletions

View File

@@ -444,6 +444,64 @@ class RecipientTableTest_getAndPossiblyMerge {
expectChangeNumberEvent() expectChangeNumberEvent()
} }
test("steal, e164+aci & aci, no pni provided, existing aci session") {
given(E164_A, null, ACI_A, aciSession = true)
given(null, null, ACI_B)
process(E164_A, null, ACI_B)
expect(null, null, ACI_A)
expect(E164_A, null, ACI_B)
expectNoSessionSwitchoverEvent()
}
test("steal, e164+pni+aci & aci, no pni provided, existing aci session") {
given(E164_A, PNI_A, ACI_A, aciSession = true)
given(null, null, ACI_B)
process(E164_A, null, ACI_B)
expect(null, PNI_A, ACI_A)
expect(E164_A, null, ACI_B)
expectNoSessionSwitchoverEvent()
}
test("steal, e164+pni+aci & aci, no pni provided, existing pni session") {
given(E164_A, PNI_A, ACI_A, pniSession = true)
given(null, null, ACI_B)
process(E164_A, null, ACI_B)
expect(null, PNI_A, ACI_A)
expect(E164_A, null, ACI_B)
expectNoSessionSwitchoverEvent()
}
test("steal, e164+pni & aci, no pni provided, no pni session") {
given(E164_A, PNI_A, null)
given(null, null, ACI_A)
process(E164_A, null, ACI_A)
expect(null, PNI_A, null)
expect(E164_A, null, ACI_A)
}
test("steal, e164+pni & aci, no pni provided, pni session") {
given(E164_A, PNI_A, null, pniSession = true)
given(null, null, ACI_A)
process(E164_A, null, ACI_A)
expect(null, PNI_A, null)
expect(E164_A, null, ACI_A)
expectNoSessionSwitchoverEvent()
}
test("merge, e164 & pni & aci, all provided") { test("merge, e164 & pni & aci, all provided") {
given(E164_A, null, null) given(E164_A, null, null)
given(null, PNI_A, null) given(null, PNI_A, null)
@@ -967,7 +1025,8 @@ class RecipientTableTest_getAndPossiblyMerge {
pni: PNI?, pni: PNI?,
aci: ACI?, aci: ACI?,
createThread: Boolean = true, createThread: Boolean = true,
pniSession: Boolean = false pniSession: Boolean = false,
aciSession: Boolean = false
): RecipientId { ): RecipientId {
val id = insert(e164, pni, aci) val id = insert(e164, pni, aci)
generatedIds += id generatedIds += id
@@ -985,6 +1044,14 @@ class RecipientTableTest_getAndPossiblyMerge {
SignalDatabase.sessions.store(pni, SignalProtocolAddress(pni.toString(), 1), SessionRecord()) SignalDatabase.sessions.store(pni, SignalProtocolAddress(pni.toString(), 1), SessionRecord())
} }
if (aciSession) {
if (aci == null) {
throw IllegalArgumentException("aciSession = true but aci is null!")
}
SignalDatabase.sessions.store(aci, SignalProtocolAddress(aci.toString(), 1), SessionRecord())
}
if (aci != null) { if (aci != null) {
SignalDatabase.identities.saveIdentity( SignalDatabase.identities.saveIdentity(
addressName = aci.toString(), addressName = aci.toString(),

View File

@@ -2611,14 +2611,14 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
) )
} }
val preSseOperationCount = operations.size sessionSwitchoverEventIfNeeded(pniVerified, preMergeData.pniRecord, postMergeData.pniRecord)?.let {
breadCrumbs += "FinalUpdateSSEPniRecord"
operations += it
}
operations += sessionSwitchoverEventIfNeeded(pniVerified, preMergeData.e164Record, postMergeData.e164Record) sessionSwitchoverEventIfNeeded(pniVerified, preMergeData.aciRecord, postMergeData.aciRecord)?.let {
operations += sessionSwitchoverEventIfNeeded(pniVerified, preMergeData.pniRecord, postMergeData.pniRecord) breadCrumbs += "FinalUpdateSSEPniAciRecord"
operations += sessionSwitchoverEventIfNeeded(pniVerified, preMergeData.aciRecord, postMergeData.aciRecord) operations += it
if (operations.size > preSseOperationCount) {
breadCrumbs += "FinalUpdateSSE"
} }
return PnpChangeSet( return PnpChangeSet(
@@ -2646,16 +2646,14 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
* For details on SSE's, see [needsSessionSwitchoverEvent]. This method is just a helper around comparing service ID's from two * For details on SSE's, see [needsSessionSwitchoverEvent]. This method is just a helper around comparing service ID's from two
* records and turning it into a possible event. * records and turning it into a possible event.
*/ */
private fun sessionSwitchoverEventIfNeeded(pniVerified: Boolean, oldRecord: RecipientRecord?, newRecord: RecipientRecord?): List<PnpOperation> { private fun sessionSwitchoverEventIfNeeded(pniVerified: Boolean, oldRecord: RecipientRecord?, newRecord: RecipientRecord?): PnpOperation? {
return if (oldRecord != null && newRecord != null && needsSessionSwitchoverEvent(pniVerified, oldRecord.serviceId, newRecord.serviceId)) { return if (oldRecord != null && newRecord != null && needsSessionSwitchoverEvent(pniVerified, oldRecord.serviceId, newRecord.serviceId)) {
listOf(
PnpOperation.SessionSwitchoverInsert( PnpOperation.SessionSwitchoverInsert(
recipientId = newRecord.id, recipientId = newRecord.id,
e164 = newRecord.e164 e164 = newRecord.e164
) )
)
} else { } else {
emptyList() null
} }
} }

View File

@@ -80,7 +80,7 @@ data class RecipientRecord(
) { ) {
fun e164Only(): Boolean { fun e164Only(): Boolean {
return this.e164 != null && this.aci == null return this.e164 != null && this.aci == null && this.pni == null
} }
fun pniOnly(): Boolean { fun pniOnly(): Boolean {