mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 18:38:32 +03:00
Temporary fix tests (wait for rust)
This commit is contained in:
parent
58a1c80334
commit
1809d02541
2 changed files with 43 additions and 32 deletions
|
@ -640,6 +640,7 @@ class E2eeSanityTests : InstrumentedTest {
|
||||||
// for the test we just accept?
|
// for the test we just accept?
|
||||||
oldCode = sasTx.getDecimalCodeRepresentation()
|
oldCode = sasTx.getDecimalCodeRepresentation()
|
||||||
testHelper.runBlockingTest {
|
testHelper.runBlockingTest {
|
||||||
|
delay(500)
|
||||||
sasTx.userHasVerifiedShortCode()
|
sasTx.userHasVerifiedShortCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,11 +667,12 @@ class E2eeSanityTests : InstrumentedTest {
|
||||||
val sasTx = tx as SasVerificationTransaction
|
val sasTx = tx as SasVerificationTransaction
|
||||||
when (sasTx.state) {
|
when (sasTx.state) {
|
||||||
VerificationTxState.ShortCodeReady -> {
|
VerificationTxState.ShortCodeReady -> {
|
||||||
|
newCode = sasTx.getDecimalCodeRepresentation()
|
||||||
if (matchOnce) {
|
if (matchOnce) {
|
||||||
testHelper.runBlockingTest {
|
testHelper.runBlockingTest {
|
||||||
|
delay(500)
|
||||||
sasTx.userHasVerifiedShortCode()
|
sasTx.userHasVerifiedShortCode()
|
||||||
}
|
}
|
||||||
newCode = sasTx.getDecimalCodeRepresentation()
|
|
||||||
matchOnce = false
|
matchOnce = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,6 +714,7 @@ class E2eeSanityTests : InstrumentedTest {
|
||||||
aliceNewSession.cryptoService().keysBackupService().getKeyBackupRecoveryKeyInfo() != null
|
aliceNewSession.cryptoService().keysBackupService().getKeyBackupRecoveryKeyInfo() != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper.runBlockingTest {
|
testHelper.runBlockingTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"MSK Private parts should be the same",
|
"MSK Private parts should be the same",
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.verification
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
|
@ -40,10 +41,9 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationServic
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.getRoom
|
||||||
import org.matrix.android.sdk.common.CommonTestHelper
|
import org.matrix.android.sdk.common.CommonTestHelper
|
||||||
import org.matrix.android.sdk.common.CryptoTestHelper
|
import org.matrix.android.sdk.common.CryptoTestHelper
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.toValue
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
|
|
||||||
|
@ -322,8 +322,6 @@ class SASTest : InstrumentedTest {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// any two devices may only have at most one key verification in flight at a time.
|
// any two devices may only have at most one key verification in flight at a time.
|
||||||
// If a device has two verifications in progress with the same device, then it should cancel both verifications.
|
// If a device has two verifications in progress with the same device, then it should cancel both verifications.
|
||||||
@Test
|
@Test
|
||||||
|
@ -449,7 +447,8 @@ class SASTest : InstrumentedTest {
|
||||||
aliceSession.cryptoService().verificationService().beginKeyVerification(VerificationMethod.SAS, bobSession.myUserId, transactionId)
|
aliceSession.cryptoService().verificationService().beginKeyVerification(VerificationMethod.SAS, bobSession.myUserId, transactionId)
|
||||||
}
|
}
|
||||||
testHelper.await(latch)
|
testHelper.await(latch)
|
||||||
val aliceTx = aliceSession.cryptoService().verificationService().getExistingTransaction(bobSession.myUserId, transactionId) as SasVerificationTransaction
|
val aliceTx =
|
||||||
|
aliceSession.cryptoService().verificationService().getExistingTransaction(bobSession.myUserId, transactionId) as SasVerificationTransaction
|
||||||
val bobTx = bobSession.cryptoService().verificationService().getExistingTransaction(aliceSession.myUserId, transactionId) as SasVerificationTransaction
|
val bobTx = bobSession.cryptoService().verificationService().getExistingTransaction(aliceSession.myUserId, transactionId) as SasVerificationTransaction
|
||||||
|
|
||||||
assertEquals("Should have same SAS", aliceTx.getDecimalCodeRepresentation(), bobTx.getDecimalCodeRepresentation())
|
assertEquals("Should have same SAS", aliceTx.getDecimalCodeRepresentation(), bobTx.getDecimalCodeRepresentation())
|
||||||
|
@ -470,62 +469,71 @@ class SASTest : InstrumentedTest {
|
||||||
val aliceVerificationService = aliceSession.cryptoService().verificationService()
|
val aliceVerificationService = aliceSession.cryptoService().verificationService()
|
||||||
val bobVerificationService = bobSession!!.cryptoService().verificationService()
|
val bobVerificationService = bobSession!!.cryptoService().verificationService()
|
||||||
|
|
||||||
val aliceSASLatch = CountDownLatch(1)
|
val verifiedLatch = CountDownLatch(2)
|
||||||
val aliceListener = object : VerificationService.Listener {
|
val aliceListener = object : VerificationService.Listener {
|
||||||
|
|
||||||
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
|
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
|
||||||
Timber.v("RequestUpdated pr=$pr")
|
Timber.v("RequestUpdated pr=$pr")
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchOnce = true
|
var matched = false
|
||||||
|
var verified = false
|
||||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||||
Timber.v("Alice transactionUpdated: ${tx.state}")
|
Timber.v("Alice transactionUpdated: ${tx.state} on thread:${Thread.currentThread()}")
|
||||||
if (tx !is SasVerificationTransaction) return
|
if (tx !is SasVerificationTransaction) return
|
||||||
when (tx.state) {
|
when (tx.state) {
|
||||||
VerificationTxState.ShortCodeReady -> testHelper.runBlockingTest {
|
VerificationTxState.ShortCodeReady -> testHelper.runBlockingTest {
|
||||||
tx.userHasVerifiedShortCode()
|
if (!matched) {
|
||||||
}
|
matched = true
|
||||||
VerificationTxState.Verified -> {
|
delay(500)
|
||||||
if (matchOnce) {
|
tx.userHasVerifiedShortCode()
|
||||||
matchOnce = false
|
|
||||||
aliceSASLatch.countDown()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> Unit
|
VerificationTxState.Verified -> {
|
||||||
|
if (!verified) {
|
||||||
|
verified = true
|
||||||
|
verifiedLatch.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aliceVerificationService.addListener(aliceListener)
|
aliceVerificationService.addListener(aliceListener)
|
||||||
|
|
||||||
val bobSASLatch = CountDownLatch(1)
|
|
||||||
val bobListener = object : VerificationService.Listener {
|
val bobListener = object : VerificationService.Listener {
|
||||||
var acceptOnce = true
|
var accepted = false
|
||||||
var matchOnce = true
|
var matched = false
|
||||||
|
var verified = false
|
||||||
|
|
||||||
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
|
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
|
||||||
Timber.v("RequestUpdated: pr=$pr")
|
Timber.v("RequestUpdated: pr=$pr")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||||
Timber.v("Bob transactionUpdated: ${tx.state}")
|
Timber.v("Bob transactionUpdated: ${tx.state} on thread: ${Thread.currentThread()}")
|
||||||
if (tx !is SasVerificationTransaction) return
|
if (tx !is SasVerificationTransaction) return
|
||||||
when (tx.state) {
|
when (tx.state) {
|
||||||
VerificationTxState.OnStarted -> testHelper.runBlockingTest {
|
VerificationTxState.OnStarted -> testHelper.runBlockingTest {
|
||||||
if (acceptOnce) {
|
if (!accepted) {
|
||||||
acceptOnce = false
|
accepted = true
|
||||||
tx.acceptVerification()
|
tx.acceptVerification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VerificationTxState.ShortCodeReady -> testHelper.runBlockingTest {
|
VerificationTxState.ShortCodeReady -> testHelper.runBlockingTest {
|
||||||
if (matchOnce) {
|
if (!matched) {
|
||||||
matchOnce = false
|
matched = true
|
||||||
|
delay(500)
|
||||||
tx.userHasVerifiedShortCode()
|
tx.userHasVerifiedShortCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VerificationTxState.ShortCodeAccepted -> {
|
VerificationTxState.Verified -> {
|
||||||
bobSASLatch.countDown()
|
if (!verified) {
|
||||||
|
verified = true
|
||||||
|
verifiedLatch.countDown()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,8 +546,8 @@ class SASTest : InstrumentedTest {
|
||||||
testHelper.runBlockingTest {
|
testHelper.runBlockingTest {
|
||||||
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, transactionId)
|
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, transactionId)
|
||||||
}
|
}
|
||||||
testHelper.await(aliceSASLatch)
|
Timber.v("Await after beginKey ${Thread.currentThread()}")
|
||||||
testHelper.await(bobSASLatch)
|
testHelper.await(verifiedLatch)
|
||||||
|
|
||||||
// Assert that devices are verified
|
// Assert that devices are verified
|
||||||
val bobDeviceInfoFromAlicePOV: CryptoDeviceInfo? = testHelper.runBlockingTest {
|
val bobDeviceInfoFromAlicePOV: CryptoDeviceInfo? = testHelper.runBlockingTest {
|
||||||
|
|
Loading…
Reference in a new issue