Fix all warnings in file E2eeSanityTests.kt

This commit is contained in:
Benoit Marty 2022-03-11 15:35:21 +01:00
parent 25cfc7e05f
commit fa104adefc
2 changed files with 22 additions and 19 deletions

View File

@ -11,6 +11,7 @@
<w>emoji</w> <w>emoji</w>
<w>emojis</w> <w>emojis</w>
<w>fdroid</w> <w>fdroid</w>
<w>ganfra</w>
<w>gplay</w> <w>gplay</w>
<w>hmac</w> <w>hmac</w>
<w>homeserver</w> <w>homeserver</w>
@ -18,6 +19,7 @@
<w>ktlint</w> <w>ktlint</w>
<w>linkified</w> <w>linkified</w>
<w>linkify</w> <w>linkify</w>
<w>manu</w>
<w>megolm</w> <w>megolm</w>
<w>msisdn</w> <w>msisdn</w>
<w>msisdns</w> <w>msisdns</w>

View File

@ -41,6 +41,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
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.common.SessionTestParams import org.matrix.android.sdk.common.SessionTestParams
import org.matrix.android.sdk.common.TestConstants
import org.matrix.android.sdk.common.TestMatrixCallback import org.matrix.android.sdk.common.TestMatrixCallback
import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.MegolmBackupCreationInfo import org.matrix.android.sdk.internal.crypto.keysbackup.model.MegolmBackupCreationInfo
@ -99,7 +100,6 @@ class E2eeSanityTests : InstrumentedTest {
ensureMembersHaveJoined(aliceSession, otherAccounts, e2eRoomID) ensureMembersHaveJoined(aliceSession, otherAccounts, e2eRoomID)
Log.v("#E2E TEST", "All users have joined the room") Log.v("#E2E TEST", "All users have joined the room")
Log.v("#E2E TEST", "Alice is sending the message") Log.v("#E2E TEST", "Alice is sending the message")
val text = "This is my message" val text = "This is my message"
@ -172,7 +172,7 @@ class E2eeSanityTests : InstrumentedTest {
} }
timelineEvent != null && timelineEvent != null &&
timelineEvent.root.getClearType() == EventType.MESSAGE && timelineEvent.root.getClearType() == EventType.MESSAGE &&
secondMessage.equals(timelineEvent.root.getClearContent().toModel<MessageContent>()?.body) secondMessage == timelineEvent.root.getClearContent().toModel<MessageContent>()?.body
} }
} }
} }
@ -190,7 +190,7 @@ class E2eeSanityTests : InstrumentedTest {
* 1. Create e2e between Alice and Bob * 1. Create e2e between Alice and Bob
* 2. Alice sends 3 messages, using 3 different sessions * 2. Alice sends 3 messages, using 3 different sessions
* 3. Ensure bob can decrypt * 3. Ensure bob can decrypt
* 4. Create backup for bob and uplaod keys * 4. Create backup for bob and upload keys
* *
* 5. Sign out alice and bob to ensure no gossiping will happen * 5. Sign out alice and bob to ensure no gossiping will happen
* *
@ -207,13 +207,13 @@ class E2eeSanityTests : InstrumentedTest {
val e2eRoomID = cryptoTestData.roomId val e2eRoomID = cryptoTestData.roomId
Log.v("#E2E TEST", "Create and start key backup for bob ...") Log.v("#E2E TEST", "Create and start key backup for bob ...")
val keysBackupService = bobSession.cryptoService().keysBackupService() val bobKeysBackupService = bobSession.cryptoService().keysBackupService()
val keyBackupPassword = "FooBarBaz" val keyBackupPassword = "FooBarBaz"
val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> { val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
keysBackupService.prepareKeysBackupVersion(keyBackupPassword, null, it) bobKeysBackupService.prepareKeysBackupVersion(keyBackupPassword, null, it)
} }
val version = testHelper.doSync<KeysVersion> { val version = testHelper.doSync<KeysVersion> {
keysBackupService.createKeysBackupVersion(megolmBackupCreationInfo, it) bobKeysBackupService.createKeysBackupVersion(megolmBackupCreationInfo, it)
} }
Log.v("#E2E TEST", "... Key backup started and enabled for bob") Log.v("#E2E TEST", "... Key backup started and enabled for bob")
// Bob session should now have // Bob session should now have
@ -249,7 +249,7 @@ class E2eeSanityTests : InstrumentedTest {
Log.v("#E2E TEST", "Force key backup for Bob...") Log.v("#E2E TEST", "Force key backup for Bob...")
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch { latch ->
keysBackupService.backupAllGroupSessions( bobKeysBackupService.backupAllGroupSessions(
null, null,
TestMatrixCallback(latch, true) TestMatrixCallback(latch, true)
) )
@ -397,7 +397,7 @@ class E2eeSanityTests : InstrumentedTest {
} }
/** /**
* Test that if a better key is forwared (lower index, it is then used) * Test that if a better key is forwarded (lower index, it is then used)
*/ */
@Test @Test
fun testForwardBetterKey() { fun testForwardBetterKey() {
@ -525,15 +525,16 @@ class E2eeSanityTests : InstrumentedTest {
private fun sendMessageInRoom(aliceRoomPOV: Room, text: String): String? { private fun sendMessageInRoom(aliceRoomPOV: Room, text: String): String? {
aliceRoomPOV.sendTextMessage(text) aliceRoomPOV.sendTextMessage(text)
var sentEventId: String? = null var sentEventId: String? = null
testHelper.waitWithLatch(4 * 60_000) { testHelper.waitWithLatch(4 * TestConstants.timeOutMillis) { latch ->
val timeline = aliceRoomPOV.createTimeline(null, TimelineSettings(60)) val timeline = aliceRoomPOV.createTimeline(null, TimelineSettings(60))
timeline.start() timeline.start()
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(latch) {
val decryptedMsg = timeline.getSnapshot() val decryptedMsg = timeline.getSnapshot()
.filter { it.root.getClearType() == EventType.MESSAGE } .filter { it.root.getClearType() == EventType.MESSAGE }
.also { .also { list ->
Log.v("#E2E TEST", "Timeline snapshot is ${it.map { "${it.root.type}|${it.root.sendState}" }.joinToString(",", "[", "]")}") val message = list.joinToString(",", "[", "]") { "${it.root.type}|${it.root.sendState}" }
Log.v("#E2E TEST", "Timeline snapshot is $message")
} }
.filter { it.root.sendState == SendState.SYNCED } .filter { it.root.sendState == SendState.SYNCED }
.firstOrNull { it.root.getClearContent().toModel<MessageContent>()?.body?.startsWith(text) == true } .firstOrNull { it.root.getClearContent().toModel<MessageContent>()?.body?.startsWith(text) == true }
@ -547,8 +548,8 @@ class E2eeSanityTests : InstrumentedTest {
} }
private fun ensureMembersHaveJoined(aliceSession: Session, otherAccounts: List<Session>, e2eRoomID: String) { private fun ensureMembersHaveJoined(aliceSession: Session, otherAccounts: List<Session>, e2eRoomID: String) {
testHelper.waitWithLatch { testHelper.waitWithLatch { latch ->
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(latch) {
otherAccounts.map { otherAccounts.map {
aliceSession.getRoomMember(it.myUserId, e2eRoomID)?.membership aliceSession.getRoomMember(it.myUserId, e2eRoomID)?.membership
}.all { }.all {
@ -559,8 +560,8 @@ class E2eeSanityTests : InstrumentedTest {
} }
private fun waitForAndAcceptInviteInRoom(otherSession: Session, e2eRoomID: String) { private fun waitForAndAcceptInviteInRoom(otherSession: Session, e2eRoomID: String) {
testHelper.waitWithLatch { testHelper.waitWithLatch { latch ->
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(latch) {
val roomSummary = otherSession.getRoomSummary(e2eRoomID) val roomSummary = otherSession.getRoomSummary(e2eRoomID)
(roomSummary != null && roomSummary.membership == Membership.INVITE).also { (roomSummary != null && roomSummary.membership == Membership.INVITE).also {
if (it) { if (it) {