mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Fix testCantDecryptIfGlobalUnverified
This commit is contained in:
parent
507cd98304
commit
0cdd0a7521
2 changed files with 30 additions and 7 deletions
|
@ -64,7 +64,6 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.api.session.securestorage.EmptyKeySigner
|
import org.matrix.android.sdk.api.session.securestorage.EmptyKeySigner
|
||||||
import org.matrix.android.sdk.api.session.securestorage.KeyRef
|
import org.matrix.android.sdk.api.session.securestorage.KeyRef
|
||||||
import timber.log.Timber
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlin.coroutines.Continuation
|
import kotlin.coroutines.Continuation
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
|
@ -441,13 +440,15 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) {
|
||||||
.cancellable()
|
.cancellable()
|
||||||
.collect {
|
.collect {
|
||||||
val transaction = it.getTransaction()
|
val transaction = it.getTransaction()
|
||||||
Timber.d("#TEST flow ${bob.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
Log.v("#E2E TEST", "#TEST flow ${bob.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
||||||
val tx = transaction as? SasVerificationTransaction
|
val tx = transaction as? SasVerificationTransaction
|
||||||
if (tx?.state() == SasTransactionState.SasShortCodeReady) {
|
if (tx?.state() == SasTransactionState.SasShortCodeReady) {
|
||||||
|
Log.v("#E2E TEST", "COMPLETE BOB CODE")
|
||||||
bobCode.complete(tx)
|
bobCode.complete(tx)
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
if (it.getRequest()?.state == EVerificationState.Cancelled) {
|
if (it.getRequest()?.state == EVerificationState.Cancelled) {
|
||||||
|
Log.v("#E2E TEST", "EXCEPTION BOB CODE")
|
||||||
bobCode.completeExceptionally(AssertionError("Request as been cancelled"))
|
bobCode.completeExceptionally(AssertionError("Request as been cancelled"))
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
|
@ -461,29 +462,33 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) {
|
||||||
.cancellable()
|
.cancellable()
|
||||||
.collect {
|
.collect {
|
||||||
val transaction = it.getTransaction()
|
val transaction = it.getTransaction()
|
||||||
Timber.d("#TEST flow ${alice.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
Log.v("#E2E TEST", "#TEST flow ${alice.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
||||||
val tx = transaction as? SasVerificationTransaction
|
val tx = transaction as? SasVerificationTransaction
|
||||||
if (tx?.state() == SasTransactionState.SasShortCodeReady) {
|
if (tx?.state() == SasTransactionState.SasShortCodeReady) {
|
||||||
|
Log.v("#E2E TEST", "COMPLETE ALICE CODE")
|
||||||
aliceCode.complete(tx)
|
aliceCode.complete(tx)
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
if (it.getRequest()?.state == EVerificationState.Cancelled) {
|
if (it.getRequest()?.state == EVerificationState.Cancelled) {
|
||||||
|
Log.v("#E2E TEST", "EXCEPTION ALICE CODE")
|
||||||
aliceCode.completeExceptionally(AssertionError("Request as been cancelled"))
|
aliceCode.completeExceptionally(AssertionError("Request as been cancelled"))
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.v("#TEST let alice start the verification")
|
Log.v("#E2E TEST", "#TEST let alice start the verification")
|
||||||
val id = aliceVerificationService.startKeyVerification(
|
val id = aliceVerificationService.startKeyVerification(
|
||||||
VerificationMethod.SAS,
|
VerificationMethod.SAS,
|
||||||
bob.myUserId,
|
bob.myUserId,
|
||||||
requestID,
|
requestID,
|
||||||
)
|
)
|
||||||
Timber.v("#TEST alice started: $id")
|
Log.v("#E2E TEST", "#TEST alice started: $id")
|
||||||
|
|
||||||
val bobTx = bobCode.await()
|
val bobTx = bobCode.await()
|
||||||
val aliceTx = aliceCode.await()
|
val aliceTx = aliceCode.await()
|
||||||
|
Log.v("#E2E TEST", "#TEST Alice code ${aliceTx.getDecimalCodeRepresentation()}")
|
||||||
|
Log.v("#E2E TEST", "#TEST Bob code ${bobTx.getDecimalCodeRepresentation()}")
|
||||||
assertEquals("SAS code do not match", aliceTx.getDecimalCodeRepresentation()!!, bobTx.getDecimalCodeRepresentation())
|
assertEquals("SAS code do not match", aliceTx.getDecimalCodeRepresentation()!!, bobTx.getDecimalCodeRepresentation())
|
||||||
|
|
||||||
val aliceDone = CompletableDeferred<Unit>()
|
val aliceDone = CompletableDeferred<Unit>()
|
||||||
|
@ -491,8 +496,12 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) {
|
||||||
aliceVerificationService.requestEventFlow()
|
aliceVerificationService.requestEventFlow()
|
||||||
.cancellable()
|
.cancellable()
|
||||||
.collect {
|
.collect {
|
||||||
|
val transaction = it.getTransaction()
|
||||||
|
Log.v("#E2E TEST", "#TEST flow ${alice.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
||||||
|
|
||||||
val request = it.getRequest()
|
val request = it.getRequest()
|
||||||
if (request?.state == EVerificationState.Done) {
|
Log.v("#E2E TEST", "#TEST flow request ${alice.myUserId.take(5)} ${request?.transactionId}|${request?.state}")
|
||||||
|
if (request?.state == EVerificationState.Done || request?.state == EVerificationState.WaitingForDone) {
|
||||||
aliceDone.complete(Unit)
|
aliceDone.complete(Unit)
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
|
@ -503,18 +512,28 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) {
|
||||||
bobVerificationService.requestEventFlow()
|
bobVerificationService.requestEventFlow()
|
||||||
.cancellable()
|
.cancellable()
|
||||||
.collect {
|
.collect {
|
||||||
|
val transaction = it.getTransaction()
|
||||||
|
Log.v("#E2E TEST", "#TEST flow ${bob.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}")
|
||||||
|
|
||||||
val request = it.getRequest()
|
val request = it.getRequest()
|
||||||
if (request?.state == EVerificationState.Done) {
|
Log.v("#E2E TEST", "#TEST flow request ${bob.myUserId.take(5)} ${request?.transactionId}|${request?.state}")
|
||||||
|
|
||||||
|
if (request?.state == EVerificationState.Done || request?.state == EVerificationState.WaitingForDone) {
|
||||||
bobDone.complete(Unit)
|
bobDone.complete(Unit)
|
||||||
return@collect cancel()
|
return@collect cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.v("#E2E TEST", "#TEST Bob confirm sas code")
|
||||||
bobTx.userHasVerifiedShortCode()
|
bobTx.userHasVerifiedShortCode()
|
||||||
|
Log.v("#E2E TEST", "#TEST Alice confirm sas code")
|
||||||
aliceTx.userHasVerifiedShortCode()
|
aliceTx.userHasVerifiedShortCode()
|
||||||
|
|
||||||
|
Log.v("#E2E TEST", "#TEST Waiting for Done..")
|
||||||
bobDone.await()
|
bobDone.await()
|
||||||
aliceDone.await()
|
aliceDone.await()
|
||||||
|
Log.v("#E2E TEST", "#TEST .. ok")
|
||||||
|
|
||||||
alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId)
|
alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId)
|
||||||
bob.cryptoService().crossSigningService().isUserTrusted(alice.myUserId)
|
bob.cryptoService().crossSigningService().isUserTrusted(alice.myUserId)
|
||||||
|
|
|
@ -66,15 +66,19 @@ class E2eeConfigTest : InstrumentedTest {
|
||||||
fun testCanDecryptIfGlobalUnverifiedAndUserTrusted() = runCryptoTest(context()) { cryptoTestHelper, testHelper ->
|
fun testCanDecryptIfGlobalUnverifiedAndUserTrusted() = runCryptoTest(context()) { cryptoTestHelper, testHelper ->
|
||||||
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom(true)
|
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom(true)
|
||||||
|
|
||||||
|
Log.v("#E2E TEST", "Initializing cross signing for alice and bob...")
|
||||||
cryptoTestHelper.initializeCrossSigning(cryptoTestData.firstSession)
|
cryptoTestHelper.initializeCrossSigning(cryptoTestData.firstSession)
|
||||||
cryptoTestHelper.initializeCrossSigning(cryptoTestData.secondSession!!)
|
cryptoTestHelper.initializeCrossSigning(cryptoTestData.secondSession!!)
|
||||||
|
Log.v("#E2E TEST", "... Initialized")
|
||||||
|
|
||||||
|
Log.v("#E2E TEST", "Start User Verification")
|
||||||
cryptoTestHelper.verifySASCrossSign(cryptoTestData.firstSession, cryptoTestData.secondSession!!, cryptoTestData.roomId)
|
cryptoTestHelper.verifySASCrossSign(cryptoTestData.firstSession, cryptoTestData.secondSession!!, cryptoTestData.roomId)
|
||||||
|
|
||||||
cryptoTestData.firstSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true)
|
cryptoTestData.firstSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true)
|
||||||
|
|
||||||
val roomAlicePOV = cryptoTestData.firstSession.roomService().getRoom(cryptoTestData.roomId)!!
|
val roomAlicePOV = cryptoTestData.firstSession.roomService().getRoom(cryptoTestData.roomId)!!
|
||||||
|
|
||||||
|
Log.v("#E2E TEST", "Send message in room")
|
||||||
val sentMessage = testHelper.sendMessageInRoom(roomAlicePOV, "you can read")
|
val sentMessage = testHelper.sendMessageInRoom(roomAlicePOV, "you can read")
|
||||||
|
|
||||||
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
||||||
|
|
Loading…
Reference in a new issue