mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-27 03:18:33 +03:00
Start fixing crypto tests compilation
This commit is contained in:
parent
9cb43ce4c8
commit
48793f531c
8 changed files with 108 additions and 50 deletions
|
@ -378,7 +378,7 @@ class CommonTestHelper(context: Context) {
|
||||||
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: (() -> Boolean)) {
|
suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: suspend (() -> Boolean)) {
|
||||||
while (true) {
|
while (true) {
|
||||||
delay(1000)
|
delay(1000)
|
||||||
if (condition()) {
|
if (condition()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.common
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertNotNull
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Assert.assertNull
|
import org.junit.Assert.assertNull
|
||||||
|
@ -275,7 +276,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initializeCrossSigning(session: Session) {
|
fun initializeCrossSigning(session: Session) {
|
||||||
testHelper.doSync<Unit> {
|
testHelper.runBlockingTest {
|
||||||
session.cryptoService().crossSigningService()
|
session.cryptoService().crossSigningService()
|
||||||
.initializeCrossSigning(
|
.initializeCrossSigning(
|
||||||
object : UserInteractiveAuthInterceptor {
|
object : UserInteractiveAuthInterceptor {
|
||||||
|
@ -288,7 +289,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, it)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,12 +301,14 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||||
val aliceVerificationService = alice.cryptoService().verificationService()
|
val aliceVerificationService = alice.cryptoService().verificationService()
|
||||||
val bobVerificationService = bob.cryptoService().verificationService()
|
val bobVerificationService = bob.cryptoService().verificationService()
|
||||||
|
|
||||||
aliceVerificationService.beginKeyVerificationInDMs(
|
runBlocking {
|
||||||
VerificationMethod.SAS,
|
aliceVerificationService.beginKeyVerificationInDMs(
|
||||||
requestID,
|
VerificationMethod.SAS,
|
||||||
roomId,
|
requestID,
|
||||||
bob.myUserId,
|
roomId,
|
||||||
bob.sessionParams.credentials.deviceId!!)
|
bob.myUserId,
|
||||||
|
bob.sessionParams.credentials.deviceId!!)
|
||||||
|
}
|
||||||
|
|
||||||
// we should reach SHOW SAS on both
|
// we should reach SHOW SAS on both
|
||||||
var alicePovTx: OutgoingSasVerificationTransaction? = null
|
var alicePovTx: OutgoingSasVerificationTransaction? = null
|
||||||
|
@ -346,8 +349,10 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||||
|
|
||||||
assertEquals("SAS code do not match", alicePovTx!!.getDecimalCodeRepresentation(), bobPovTx!!.getDecimalCodeRepresentation())
|
assertEquals("SAS code do not match", alicePovTx!!.getDecimalCodeRepresentation(), bobPovTx!!.getDecimalCodeRepresentation())
|
||||||
|
|
||||||
bobPovTx!!.userHasVerifiedShortCode()
|
runBlocking {
|
||||||
alicePovTx!!.userHasVerifiedShortCode()
|
bobPovTx!!.userHasVerifiedShortCode()
|
||||||
|
alicePovTx!!.userHasVerifiedShortCode()
|
||||||
|
}
|
||||||
|
|
||||||
testHelper.waitWithLatch {
|
testHelper.waitWithLatch {
|
||||||
testHelper.retryPeriodicallyWithLatch(it) {
|
testHelper.retryPeriodicallyWithLatch(it) {
|
||||||
|
|
|
@ -60,8 +60,8 @@ class PreShareKeysTest : InstrumentedTest {
|
||||||
Log.d("#Test", "Room Key Received from alice $preShareCount")
|
Log.d("#Test", "Room Key Received from alice $preShareCount")
|
||||||
|
|
||||||
// Force presharing of new outbound key
|
// Force presharing of new outbound key
|
||||||
testHelper.doSync<Unit> {
|
testHelper.runBlockingTest {
|
||||||
aliceSession.cryptoService().prepareToEncrypt(e2eRoomID, it)
|
aliceSession.cryptoService().prepareToEncrypt(e2eRoomID)
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper.waitWithLatch { latch ->
|
testHelper.waitWithLatch { latch ->
|
||||||
|
|
|
@ -144,9 +144,12 @@ class UnwedgingTest : InstrumentedTest {
|
||||||
// - Store the olm session between A&B devices
|
// - Store the olm session between A&B devices
|
||||||
// Let us pickle our session with bob here so we can later unpickle it
|
// Let us pickle our session with bob here so we can later unpickle it
|
||||||
// and wedge our session.
|
// and wedge our session.
|
||||||
val sessionIdsForBob = aliceCryptoStore.getDeviceSessionIds(bobSession.cryptoService().getMyDevice().identityKey()!!)
|
var myDevice = testHelper.runBlockingTest {
|
||||||
|
bobSession.cryptoService().getMyDevice()
|
||||||
|
}
|
||||||
|
val sessionIdsForBob = aliceCryptoStore.getDeviceSessionIds(myDevice.identityKey()!!)
|
||||||
sessionIdsForBob!!.size shouldBe 1
|
sessionIdsForBob!!.size shouldBe 1
|
||||||
val olmSession = aliceCryptoStore.getDeviceSession(sessionIdsForBob.first(), bobSession.cryptoService().getMyDevice().identityKey()!!)!!
|
val olmSession = aliceCryptoStore.getDeviceSession(sessionIdsForBob.first(),myDevice.identityKey()!!)!!
|
||||||
|
|
||||||
val oldSession = serializeForRealm(olmSession.olmSession)
|
val oldSession = serializeForRealm(olmSession.olmSession)
|
||||||
|
|
||||||
|
@ -174,7 +177,10 @@ class UnwedgingTest : InstrumentedTest {
|
||||||
// Let us wedge the session now. Set crypto state like after the first message
|
// Let us wedge the session now. Set crypto state like after the first message
|
||||||
Timber.i("## CRYPTO | testUnwedging: wedge the session now. Set crypto state like after the first message")
|
Timber.i("## CRYPTO | testUnwedging: wedge the session now. Set crypto state like after the first message")
|
||||||
|
|
||||||
aliceCryptoStore.storeSession(OlmSessionWrapper(deserializeFromRealm<OlmSession>(oldSession)!!), bobSession.cryptoService().getMyDevice().identityKey()!!)
|
myDevice = testHelper.runBlockingTest {
|
||||||
|
bobSession.cryptoService().getMyDevice()
|
||||||
|
}
|
||||||
|
aliceCryptoStore.storeSession(OlmSessionWrapper(deserializeFromRealm<OlmSession>(oldSession)!!), myDevice.identityKey()!!)
|
||||||
Thread.sleep(6_000)
|
Thread.sleep(6_000)
|
||||||
|
|
||||||
// Force new session, and key share
|
// Force new session, and key share
|
||||||
|
@ -207,7 +213,7 @@ class UnwedgingTest : InstrumentedTest {
|
||||||
bobTimeline.removeListener(bobHasThreeDecryptedEventsListener)
|
bobTimeline.removeListener(bobHasThreeDecryptedEventsListener)
|
||||||
|
|
||||||
// It's a trick to force key request on fail to decrypt
|
// It's a trick to force key request on fail to decrypt
|
||||||
testHelper.doSync<Unit> {
|
testHelper.runBlockingTest {
|
||||||
bobSession.cryptoService().crossSigningService()
|
bobSession.cryptoService().crossSigningService()
|
||||||
.initializeCrossSigning(
|
.initializeCrossSigning(
|
||||||
object : UserInteractiveAuthInterceptor {
|
object : UserInteractiveAuthInterceptor {
|
||||||
|
@ -220,7 +226,7 @@ class UnwedgingTest : InstrumentedTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, it)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until we received back the key
|
// Wait until we received back the key
|
||||||
|
|
|
@ -23,6 +23,8 @@ import junit.framework.TestCase.assertEquals
|
||||||
import junit.framework.TestCase.assertNotNull
|
import junit.framework.TestCase.assertNotNull
|
||||||
import junit.framework.TestCase.assertTrue
|
import junit.framework.TestCase.assertTrue
|
||||||
import junit.framework.TestCase.fail
|
import junit.framework.TestCase.fail
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.FixMethodOrder
|
import org.junit.FixMethodOrder
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
|
@ -93,7 +95,9 @@ class KeyShareTests : InstrumentedTest {
|
||||||
assert(receivedEvent!!.isEncrypted())
|
assert(receivedEvent!!.isEncrypted())
|
||||||
|
|
||||||
try {
|
try {
|
||||||
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
commonTestHelper.runBlockingTest {
|
||||||
|
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
||||||
|
}
|
||||||
fail("should fail")
|
fail("should fail")
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
}
|
}
|
||||||
|
@ -106,7 +110,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
|
|
||||||
var outGoingRequestId: String? = null
|
var outGoingRequestId: String? = null
|
||||||
|
|
||||||
commonTestHelper.waitWithLatch { latch ->
|
commonTestHelper.waitWithLatch { latch ->
|
||||||
commonTestHelper.retryPeriodicallyWithLatch(latch) {
|
commonTestHelper.retryPeriodicallyWithLatch(latch) {
|
||||||
aliceSession2.cryptoService().getOutgoingRoomKeyRequests()
|
aliceSession2.cryptoService().getOutgoingRoomKeyRequests()
|
||||||
.filter { req ->
|
.filter { req ->
|
||||||
|
@ -148,7 +152,9 @@ class KeyShareTests : InstrumentedTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
commonTestHelper.runBlockingTest {
|
||||||
|
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
||||||
|
}
|
||||||
fail("should fail")
|
fail("should fail")
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
}
|
}
|
||||||
|
@ -185,7 +191,9 @@ class KeyShareTests : InstrumentedTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
commonTestHelper.runBlockingTest {
|
||||||
|
aliceSession2.cryptoService().decryptEvent(receivedEvent.root, "foo")
|
||||||
|
}
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
fail("should have been able to decrypt")
|
fail("should have been able to decrypt")
|
||||||
}
|
}
|
||||||
|
@ -199,7 +207,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
fun test_ShareSSSSSecret() {
|
fun test_ShareSSSSSecret() {
|
||||||
val aliceSession1 = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
|
val aliceSession1 = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
|
||||||
|
|
||||||
commonTestHelper.doSync<Unit> {
|
commonTestHelper.runBlockingTest {
|
||||||
aliceSession1.cryptoService().crossSigningService()
|
aliceSession1.cryptoService().crossSigningService()
|
||||||
.initializeCrossSigning(
|
.initializeCrossSigning(
|
||||||
object : UserInteractiveAuthInterceptor {
|
object : UserInteractiveAuthInterceptor {
|
||||||
|
@ -211,7 +219,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, it)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also bootstrap keybackup on first session
|
// Also bootstrap keybackup on first session
|
||||||
|
@ -249,8 +257,10 @@ class KeyShareTests : InstrumentedTest {
|
||||||
}
|
}
|
||||||
if (tx.state == VerificationTxState.ShortCodeReady) {
|
if (tx.state == VerificationTxState.ShortCodeReady) {
|
||||||
session1ShortCode = tx.getDecimalCodeRepresentation()
|
session1ShortCode = tx.getDecimalCodeRepresentation()
|
||||||
Thread.sleep(500)
|
commonTestHelper.runBlockingTest {
|
||||||
tx.userHasVerifiedShortCode()
|
delay(500)
|
||||||
|
tx.userHasVerifiedShortCode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,16 +272,20 @@ class KeyShareTests : InstrumentedTest {
|
||||||
if (tx is SasVerificationTransaction) {
|
if (tx is SasVerificationTransaction) {
|
||||||
if (tx.state == VerificationTxState.ShortCodeReady) {
|
if (tx.state == VerificationTxState.ShortCodeReady) {
|
||||||
session2ShortCode = tx.getDecimalCodeRepresentation()
|
session2ShortCode = tx.getDecimalCodeRepresentation()
|
||||||
Thread.sleep(500)
|
commonTestHelper.runBlockingTest {
|
||||||
tx.userHasVerifiedShortCode()
|
delay(500)
|
||||||
|
tx.userHasVerifiedShortCode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val txId = "m.testVerif12"
|
val txId = "m.testVerif12"
|
||||||
aliceVerificationService2.beginKeyVerification(VerificationMethod.SAS, aliceSession1.myUserId, aliceSession1.sessionParams.deviceId
|
commonTestHelper.runBlockingTest {
|
||||||
?: "", txId)
|
aliceVerificationService2.beginKeyVerification(VerificationMethod.SAS, aliceSession1.myUserId, aliceSession1.sessionParams.deviceId
|
||||||
|
?: "", txId)
|
||||||
|
}
|
||||||
|
|
||||||
commonTestHelper.waitWithLatch { latch ->
|
commonTestHelper.waitWithLatch { latch ->
|
||||||
commonTestHelper.retryPeriodicallyWithLatch(latch) {
|
commonTestHelper.retryPeriodicallyWithLatch(latch) {
|
||||||
|
@ -312,7 +326,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
fun test_ImproperKeyShareBug() {
|
fun test_ImproperKeyShareBug() {
|
||||||
val aliceSession = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
|
val aliceSession = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
|
||||||
|
|
||||||
commonTestHelper.doSync<Unit> {
|
commonTestHelper.runBlockingTest {
|
||||||
aliceSession.cryptoService().crossSigningService()
|
aliceSession.cryptoService().crossSigningService()
|
||||||
.initializeCrossSigning(
|
.initializeCrossSigning(
|
||||||
object : UserInteractiveAuthInterceptor {
|
object : UserInteractiveAuthInterceptor {
|
||||||
|
@ -325,7 +339,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, it)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an encrypted room and send a couple of messages
|
// Create an encrypted room and send a couple of messages
|
||||||
|
@ -346,7 +360,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
// Create bob session
|
// Create bob session
|
||||||
|
|
||||||
val bobSession = commonTestHelper.createAccount(TestConstants.USER_BOB, SessionTestParams(true))
|
val bobSession = commonTestHelper.createAccount(TestConstants.USER_BOB, SessionTestParams(true))
|
||||||
commonTestHelper.doSync<Unit> {
|
commonTestHelper.runBlockingTest {
|
||||||
bobSession.cryptoService().crossSigningService()
|
bobSession.cryptoService().crossSigningService()
|
||||||
.initializeCrossSigning(
|
.initializeCrossSigning(
|
||||||
object : UserInteractiveAuthInterceptor {
|
object : UserInteractiveAuthInterceptor {
|
||||||
|
@ -359,7 +373,7 @@ class KeyShareTests : InstrumentedTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, it)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let alice invite bob
|
// Let alice invite bob
|
||||||
|
@ -380,7 +394,10 @@ class KeyShareTests : InstrumentedTest {
|
||||||
val roomRoomBobPov = aliceSession.getRoom(roomId)
|
val roomRoomBobPov = aliceSession.getRoom(roomId)
|
||||||
val beforeJoin = roomRoomBobPov!!.getTimelineEvent(secondEventId)
|
val beforeJoin = roomRoomBobPov!!.getTimelineEvent(secondEventId)
|
||||||
|
|
||||||
var dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin!!.root, "") }
|
var dRes =
|
||||||
|
commonTestHelper.runBlockingTest {
|
||||||
|
tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin!!.root, "") }
|
||||||
|
}
|
||||||
|
|
||||||
assert(dRes == null)
|
assert(dRes == null)
|
||||||
|
|
||||||
|
@ -391,7 +408,9 @@ class KeyShareTests : InstrumentedTest {
|
||||||
Thread.sleep(3_000)
|
Thread.sleep(3_000)
|
||||||
|
|
||||||
// With the bug the first session would have improperly reshare that key :/
|
// With the bug the first session would have improperly reshare that key :/
|
||||||
dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin.root, "") }
|
dRes = commonTestHelper.runBlockingTest {
|
||||||
|
tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin.root, "") }
|
||||||
|
}
|
||||||
Log.d("#TEST", "KS: sgould not decrypt that ${beforeJoin.root.getClearContent().toModel<MessageContent>()?.body}")
|
Log.d("#TEST", "KS: sgould not decrypt that ${beforeJoin.root.getClearContent().toModel<MessageContent>()?.body}")
|
||||||
assert(dRes?.clearEvent == null)
|
assert(dRes?.clearEvent == null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.crypto.gossiping
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.filters.LargeTest
|
import androidx.test.filters.LargeTest
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.FixMethodOrder
|
import org.junit.FixMethodOrder
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
|
@ -92,7 +93,9 @@ class WithHeldTests : InstrumentedTest {
|
||||||
// Bob should not be able to decrypt because the keys is withheld
|
// Bob should not be able to decrypt because the keys is withheld
|
||||||
try {
|
try {
|
||||||
// .. might need to wait a bit for stability?
|
// .. might need to wait a bit for stability?
|
||||||
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "")
|
runBlocking {
|
||||||
|
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "")
|
||||||
|
}
|
||||||
Assert.fail("This session should not be able to decrypt")
|
Assert.fail("This session should not be able to decrypt")
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
val type = (failure as MXCryptoError.Base).errorType
|
val type = (failure as MXCryptoError.Base).errorType
|
||||||
|
@ -117,7 +120,9 @@ class WithHeldTests : InstrumentedTest {
|
||||||
// Previous message should still be undecryptable (partially withheld session)
|
// Previous message should still be undecryptable (partially withheld session)
|
||||||
try {
|
try {
|
||||||
// .. might need to wait a bit for stability?
|
// .. might need to wait a bit for stability?
|
||||||
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "")
|
runBlocking {
|
||||||
|
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "")
|
||||||
|
}
|
||||||
Assert.fail("This session should not be able to decrypt")
|
Assert.fail("This session should not be able to decrypt")
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
val type = (failure as MXCryptoError.Base).errorType
|
val type = (failure as MXCryptoError.Base).errorType
|
||||||
|
@ -164,7 +169,9 @@ class WithHeldTests : InstrumentedTest {
|
||||||
val eventBobPOV = bobSession.getRoom(testData.roomId)?.getTimelineEvent(eventId)
|
val eventBobPOV = bobSession.getRoom(testData.roomId)?.getTimelineEvent(eventId)
|
||||||
try {
|
try {
|
||||||
// .. might need to wait a bit for stability?
|
// .. might need to wait a bit for stability?
|
||||||
bobSession.cryptoService().decryptEvent(eventBobPOV!!.root, "")
|
runBlocking {
|
||||||
|
bobSession.cryptoService().decryptEvent(eventBobPOV!!.root, "")
|
||||||
|
}
|
||||||
Assert.fail("This session should not be able to decrypt")
|
Assert.fail("This session should not be able to decrypt")
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
val type = (failure as MXCryptoError.Base).errorType
|
val type = (failure as MXCryptoError.Base).errorType
|
||||||
|
@ -222,7 +229,7 @@ class WithHeldTests : InstrumentedTest {
|
||||||
cryptoTestHelper.initializeCrossSigning(bobSecondSession)
|
cryptoTestHelper.initializeCrossSigning(bobSecondSession)
|
||||||
|
|
||||||
// Trust bob second device from Alice POV
|
// Trust bob second device from Alice POV
|
||||||
mTestHelper.runBlockingTest {
|
testHelper.runBlockingTest {
|
||||||
aliceSession.cryptoService().crossSigningService().trustDevice(bobSecondSession.sessionParams.deviceId!!)
|
aliceSession.cryptoService().crossSigningService().trustDevice(bobSecondSession.sessionParams.deviceId!!)
|
||||||
bobSecondSession.cryptoService().crossSigningService().trustDevice(aliceSession.sessionParams.deviceId!!)
|
bobSecondSession.cryptoService().crossSigningService().trustDevice(aliceSession.sessionParams.deviceId!!)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.crypto.keysbackup
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.filters.LargeTest
|
import androidx.test.filters.LargeTest
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertNotNull
|
import org.junit.Assert.assertNotNull
|
||||||
|
@ -164,17 +165,22 @@ class KeysBackupTest : InstrumentedTest {
|
||||||
|
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
|
|
||||||
assertEquals(2, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
|
runBlocking {
|
||||||
assertEquals(0, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
|
assertEquals(2, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
|
||||||
|
assertEquals(0, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
|
||||||
|
}
|
||||||
val stateObserver = StateObserver(keysBackup, latch, 5)
|
val stateObserver = StateObserver(keysBackup, latch, 5)
|
||||||
|
|
||||||
keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
|
||||||
|
|
||||||
testHelper.await(latch)
|
testHelper.await(latch)
|
||||||
|
|
||||||
val nbOfKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false)
|
val nbOfKeys = runBlocking {
|
||||||
val backedUpKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true)
|
cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false)
|
||||||
|
}
|
||||||
|
val backedUpKeys = runBlocking {
|
||||||
|
cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true)
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(2, nbOfKeys)
|
assertEquals(2, nbOfKeys)
|
||||||
assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
|
assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
|
||||||
|
@ -833,9 +839,12 @@ class KeysBackupTest : InstrumentedTest {
|
||||||
assertEquals(1, keysBackupVersionTrust.signatures.size)
|
assertEquals(1, keysBackupVersionTrust.signatures.size)
|
||||||
|
|
||||||
val signature = keysBackupVersionTrust.signatures[0]
|
val signature = keysBackupVersionTrust.signatures[0]
|
||||||
|
val device = runBlocking {
|
||||||
|
cryptoTestData.firstSession.cryptoService().getMyDevice()
|
||||||
|
}
|
||||||
assertTrue(signature.valid)
|
assertTrue(signature.valid)
|
||||||
assertNotNull(signature.device)
|
assertNotNull(signature.device)
|
||||||
assertEquals(cryptoTestData.firstSession.cryptoService().getMyDevice().deviceId, signature.deviceId)
|
assertEquals(device.deviceId, signature.deviceId)
|
||||||
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.deviceId)
|
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.deviceId)
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
|
|
|
@ -80,7 +80,10 @@ class KeysBackupTestHelper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(2, cryptoTestData.firstSession.cryptoService().keysBackupService().getTotalNumbersOfBackedUpKeys())
|
val totalNumbersOfBackedUpKeys = testHelper.runBlockingTest {
|
||||||
|
cryptoTestData.firstSession.cryptoService().keysBackupService().getTotalNumbersOfBackedUpKeys()
|
||||||
|
}
|
||||||
|
Assert.assertEquals(2, totalNumbersOfBackedUpKeys)
|
||||||
|
|
||||||
val aliceUserId = cryptoTestData.firstSession.myUserId
|
val aliceUserId = cryptoTestData.firstSession.myUserId
|
||||||
|
|
||||||
|
@ -88,15 +91,21 @@ class KeysBackupTestHelper(
|
||||||
val aliceSession2 = testHelper.logIntoAccount(aliceUserId, KeysBackupTestConstants.defaultSessionParamsWithInitialSync)
|
val aliceSession2 = testHelper.logIntoAccount(aliceUserId, KeysBackupTestConstants.defaultSessionParamsWithInitialSync)
|
||||||
|
|
||||||
// Test check: aliceSession2 has no keys at login
|
// Test check: aliceSession2 has no keys at login
|
||||||
Assert.assertEquals(0, aliceSession2.cryptoService().inboundGroupSessionsCount(false))
|
val inboundGroupSessionCount = testHelper.runBlockingTest {
|
||||||
|
aliceSession2.cryptoService().inboundGroupSessionsCount(false)
|
||||||
|
}
|
||||||
|
Assert.assertEquals(0, inboundGroupSessionCount)
|
||||||
|
|
||||||
// Wait for backup state to be NotTrusted
|
// Wait for backup state to be NotTrusted
|
||||||
waitForKeysBackupToBeInState(aliceSession2, KeysBackupState.NotTrusted)
|
waitForKeysBackupToBeInState(aliceSession2, KeysBackupState.NotTrusted)
|
||||||
|
|
||||||
stateObserver.stopAndCheckStates(null)
|
stateObserver.stopAndCheckStates(null)
|
||||||
|
|
||||||
|
val totalNumbersOfBackedUpKeysFromNewSession = testHelper.runBlockingTest {
|
||||||
|
aliceSession2.cryptoService().keysBackupService().getTotalNumbersOfBackedUpKeys()
|
||||||
|
}
|
||||||
return KeysBackupScenarioData(cryptoTestData,
|
return KeysBackupScenarioData(cryptoTestData,
|
||||||
aliceSession2.cryptoService().keysBackupService().getTotalNumbersOfBackedUpKeys(),
|
totalNumbersOfBackedUpKeysFromNewSession,
|
||||||
prepareKeysBackupDataResult,
|
prepareKeysBackupDataResult,
|
||||||
aliceSession2)
|
aliceSession2)
|
||||||
}
|
}
|
||||||
|
@ -182,7 +191,10 @@ class KeysBackupTestHelper(
|
||||||
Assert.assertEquals(total, imported)
|
Assert.assertEquals(total, imported)
|
||||||
|
|
||||||
// - The new device must have the same count of megolm keys
|
// - The new device must have the same count of megolm keys
|
||||||
Assert.assertEquals(testData.aliceKeys, testData.aliceSession2.cryptoService().inboundGroupSessionsCount(false))
|
val inboundGroupSessionCount = testHelper.runBlockingTest {
|
||||||
|
testData.aliceSession2.cryptoService().inboundGroupSessionsCount(false)
|
||||||
|
}
|
||||||
|
Assert.assertEquals(testData.aliceKeys, inboundGroupSessionCount)
|
||||||
|
|
||||||
// - Alice must have the same keys on both devices
|
// - Alice must have the same keys on both devices
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue