Test message decryption in a room with 3 members.

This commit is contained in:
Onuray Sahin 2020-12-14 17:32:54 +03:00 committed by Benoit Marty
parent 2b780a8b76
commit 9b332f7a32

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.session.room.timeline
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.CryptoTestHelper
import java.util.concurrent.CountDownLatch
@RunWith(JUnit4::class)
@FixMethodOrder(MethodSorters.JVM)
class TimelineWithManyMembersTest : InstrumentedTest {
private val commonTestHelper = CommonTestHelper(context())
private val cryptoTestHelper = CryptoTestHelper(commonTestHelper)
/**
* Ensures when someone sends a message to a crowded room, everyone can decrypt the message.
*/
@Test
fun everyoneShouldDecryptMessage3Members() {
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobAndSamInARoom()
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession!!
val samSession = cryptoTestData.thirdSession!!
val aliceRoomId = cryptoTestData.roomId
aliceSession.cryptoService().setWarnOnUnknownDevices(false)
bobSession.cryptoService().setWarnOnUnknownDevices(false)
samSession.cryptoService().setWarnOnUnknownDevices(false)
val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!
val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!!
val roomFromSamPOV = samSession.getRoom(aliceRoomId)!!
val bobTimeline = roomFromBobPOV.createTimeline(null, TimelineSettings(30))
val samTimeline = roomFromSamPOV.createTimeline(null, TimelineSettings(30))
bobTimeline.start()
samTimeline.start()
val firstMessage = "First messages from Alice"
commonTestHelper.sendTextMessage(
roomFromAlicePOV,
firstMessage,
1)
bobSession.startSync(true)
run {
val lock = CountDownLatch(1)
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
snapshot.firstOrNull()?.root?.getClearContent()?.toModel<MessageContent>()?.body?.startsWith(firstMessage).orFalse()
}
bobTimeline.addListener(eventsListener)
commonTestHelper.await(lock)
}
bobSession.stopSync()
samSession.startSync(true)
run {
val lock = CountDownLatch(1)
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
snapshot.firstOrNull()?.root?.getClearContent()?.toModel<MessageContent>()?.body?.startsWith(firstMessage).orFalse()
}
samTimeline.addListener(eventsListener)
commonTestHelper.await(lock)
}
samSession.stopSync()
}
}