From 0cdd0a7521eb7039b2b43f102ee4c88f8d300c44 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 31 Mar 2023 10:17:44 +0200 Subject: [PATCH] Fix testCantDecryptIfGlobalUnverified --- .../android/sdk/common/CryptoTestHelper.kt | 33 +++++++++++++++---- .../sdk/internal/crypto/E2eeConfigTest.kt | 4 +++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt index b47c3cbbd5..5adc324ca0 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt @@ -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.securestorage.EmptyKeySigner import org.matrix.android.sdk.api.session.securestorage.KeyRef -import timber.log.Timber import java.util.UUID import kotlin.coroutines.Continuation import kotlin.coroutines.resume @@ -441,13 +440,15 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) { .cancellable() .collect { 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 if (tx?.state() == SasTransactionState.SasShortCodeReady) { + Log.v("#E2E TEST", "COMPLETE BOB CODE") bobCode.complete(tx) return@collect cancel() } if (it.getRequest()?.state == EVerificationState.Cancelled) { + Log.v("#E2E TEST", "EXCEPTION BOB CODE") bobCode.completeExceptionally(AssertionError("Request as been cancelled")) return@collect cancel() } @@ -461,29 +462,33 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) { .cancellable() .collect { 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 if (tx?.state() == SasTransactionState.SasShortCodeReady) { + Log.v("#E2E TEST", "COMPLETE ALICE CODE") aliceCode.complete(tx) return@collect cancel() } if (it.getRequest()?.state == EVerificationState.Cancelled) { + Log.v("#E2E TEST", "EXCEPTION ALICE CODE") aliceCode.completeExceptionally(AssertionError("Request as been cancelled")) 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( VerificationMethod.SAS, bob.myUserId, requestID, ) - Timber.v("#TEST alice started: $id") + Log.v("#E2E TEST", "#TEST alice started: $id") val bobTx = bobCode.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()) val aliceDone = CompletableDeferred() @@ -491,8 +496,12 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) { aliceVerificationService.requestEventFlow() .cancellable() .collect { + val transaction = it.getTransaction() + Log.v("#E2E TEST", "#TEST flow ${alice.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}") + 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) return@collect cancel() } @@ -503,18 +512,28 @@ class CryptoTestHelper(val testHelper: CommonTestHelper) { bobVerificationService.requestEventFlow() .cancellable() .collect { + val transaction = it.getTransaction() + Log.v("#E2E TEST", "#TEST flow ${bob.myUserId.take(5)} ${transaction?.transactionId}|${transaction?.dbgState()}") + 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) return@collect cancel() } } } + + Log.v("#E2E TEST", "#TEST Bob confirm sas code") bobTx.userHasVerifiedShortCode() + Log.v("#E2E TEST", "#TEST Alice confirm sas code") aliceTx.userHasVerifiedShortCode() + Log.v("#E2E TEST", "#TEST Waiting for Done..") bobDone.await() aliceDone.await() + Log.v("#E2E TEST", "#TEST .. ok") alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId) bob.cryptoService().crossSigningService().isUserTrusted(alice.myUserId) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeConfigTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeConfigTest.kt index 67ea90fb97..7979a1258d 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeConfigTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeConfigTest.kt @@ -66,15 +66,19 @@ class E2eeConfigTest : InstrumentedTest { fun testCanDecryptIfGlobalUnverifiedAndUserTrusted() = runCryptoTest(context()) { cryptoTestHelper, testHelper -> val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom(true) + Log.v("#E2E TEST", "Initializing cross signing for alice and bob...") cryptoTestHelper.initializeCrossSigning(cryptoTestData.firstSession) cryptoTestHelper.initializeCrossSigning(cryptoTestData.secondSession!!) + Log.v("#E2E TEST", "... Initialized") + Log.v("#E2E TEST", "Start User Verification") cryptoTestHelper.verifySASCrossSign(cryptoTestData.firstSession, cryptoTestData.secondSession!!, cryptoTestData.roomId) cryptoTestData.firstSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true) 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 roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!