mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 18:38:32 +03:00
Fix some E2E tests
This commit is contained in:
parent
47bc597b99
commit
eb0faa3484
3 changed files with 82 additions and 95 deletions
|
@ -50,7 +50,9 @@ import org.matrix.android.sdk.api.session.events.model.EventType
|
|||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.Room
|
||||
import org.matrix.android.sdk.api.session.room.failure.JoinRoomFailure
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
||||
|
@ -149,6 +151,76 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
|||
return CryptoTestData(aliceRoomId, listOf(aliceSession, bobSession))
|
||||
}
|
||||
|
||||
fun inviteNewUsersAndWaitForThemToJoin(session: Session, roomId: String, usernames: List<String>): List<Session> {
|
||||
val newSessions = usernames.map { username ->
|
||||
testHelper.createAccount(username, SessionTestParams(true)).also {
|
||||
it.cryptoService().enableKeyGossiping(false)
|
||||
}
|
||||
}
|
||||
|
||||
val room = session.getRoom(roomId)!!
|
||||
|
||||
Log.v("#E2E TEST", "All accounts created")
|
||||
// we want to invite them in the room
|
||||
newSessions.forEach { newSession ->
|
||||
testHelper.runBlockingTest {
|
||||
Log.v("#E2E TEST", "${session.myUserId} invites ${newSession.myUserId}")
|
||||
room.membershipService().invite(newSession.myUserId)
|
||||
}
|
||||
}
|
||||
|
||||
// All user should accept invite
|
||||
newSessions.forEach { newSession ->
|
||||
waitForAndAcceptInviteInRoom(newSession, roomId)
|
||||
Log.v("#E2E TEST", "${newSession.myUserId} joined room $roomId")
|
||||
}
|
||||
ensureMembersHaveJoined(session, newSessions, roomId)
|
||||
return newSessions
|
||||
}
|
||||
|
||||
private fun ensureMembersHaveJoined(session: Session, invitedUserSessions: List<Session>, roomId: String) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
||||
invitedUserSessions.map { invitedUserSession ->
|
||||
session.roomService().getRoomMember(invitedUserSession.myUserId, roomId)?.membership
|
||||
}.all {
|
||||
it == Membership.JOIN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun waitForAndAcceptInviteInRoom(session: Session, roomId: String) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
||||
val roomSummary = session.getRoomSummary(roomId)
|
||||
(roomSummary != null && roomSummary.membership == Membership.INVITE).also {
|
||||
if (it) {
|
||||
Log.v("#E2E TEST", "${session.myUserId} can see the invite from ${roomSummary?.inviterId}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not sure why it's taking so long :/
|
||||
testHelper.runBlockingTest(90_000) {
|
||||
Log.v("#E2E TEST", "${session.myUserId} tries to join room $roomId")
|
||||
try {
|
||||
session.roomService().joinRoom(roomId)
|
||||
} catch (ex: JoinRoomFailure.JoinedWithTimeout) {
|
||||
// it's ok we will wait after
|
||||
}
|
||||
}
|
||||
|
||||
Log.v("#E2E TEST", "${session.myUserId} waiting for join echo ...")
|
||||
testHelper.waitWithLatch {
|
||||
testHelper.retryPeriodicallyWithLatch(it) {
|
||||
val roomSummary = session.getRoomSummary(roomId)
|
||||
roomSummary != null && roomSummary.membership == Membership.JOIN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alice, Bob and Sam session
|
||||
*/
|
||||
|
@ -320,7 +392,8 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
|||
aliceVerificationService.beginKeyVerification(
|
||||
VerificationMethod.SAS,
|
||||
roomId,
|
||||
bob.myUserId,)
|
||||
bob.myUserId,
|
||||
)
|
||||
}
|
||||
|
||||
// we should reach SHOW SAS on both
|
||||
|
|
|
@ -43,11 +43,8 @@ import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventCon
|
|||
import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.Room
|
||||
import org.matrix.android.sdk.api.session.room.failure.JoinRoomFailure
|
||||
import org.matrix.android.sdk.api.session.room.getTimelineEvent
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
||||
|
@ -88,36 +85,14 @@ class E2eeSanityTests : InstrumentedTest {
|
|||
|
||||
// add some more users and invite them
|
||||
val otherAccounts = listOf("benoit", "valere", "ganfra") // , "adam", "manu")
|
||||
.map {
|
||||
testHelper.createAccount(it, SessionTestParams(true)).also {
|
||||
it.cryptoService().enableKeyGossiping(false)
|
||||
}
|
||||
.let {
|
||||
cryptoTestHelper.inviteNewUsersAndWaitForThemToJoin(aliceSession, e2eRoomID, it)
|
||||
}
|
||||
|
||||
Log.v("#E2E TEST", "All accounts created")
|
||||
// we want to invite them in the room
|
||||
otherAccounts.forEach {
|
||||
testHelper.runBlockingTest {
|
||||
Log.v("#E2E TEST", "Alice invites ${it.myUserId}")
|
||||
aliceRoomPOV.membershipService().invite(it.myUserId)
|
||||
}
|
||||
}
|
||||
|
||||
// All user should accept invite
|
||||
otherAccounts.forEach { otherSession ->
|
||||
waitForAndAcceptInviteInRoom(testHelper, otherSession, e2eRoomID)
|
||||
Log.v("#E2E TEST", "${otherSession.myUserId} joined room $e2eRoomID")
|
||||
}
|
||||
|
||||
// check that alice see them as joined (not really necessary?)
|
||||
ensureMembersHaveJoined(testHelper, aliceSession, otherAccounts, e2eRoomID)
|
||||
|
||||
Log.v("#E2E TEST", "All users have joined the room")
|
||||
Log.v("#E2E TEST", "Alice is sending the message")
|
||||
|
||||
val text = "This is my message"
|
||||
val sentEventId: String? = sendMessageInRoom(testHelper, aliceRoomPOV, text)
|
||||
// val sentEvent = testHelper.sendTextMessage(aliceRoomPOV, "Hello all", 1).first()
|
||||
Assert.assertTrue("Message should be sent", sentEventId != null)
|
||||
|
||||
// All should be able to decrypt
|
||||
|
@ -131,29 +106,11 @@ class E2eeSanityTests : InstrumentedTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.v("#E2E TEST", "Everybody received the encrypted message and could decrypt")
|
||||
// Add a new user to the room, and check that he can't decrypt
|
||||
val newAccount = listOf("adam") // , "adam", "manu")
|
||||
.map {
|
||||
testHelper.createAccount(it, SessionTestParams(true))
|
||||
}
|
||||
|
||||
newAccount.forEach {
|
||||
testHelper.runBlockingTest {
|
||||
Log.v("#E2E TEST", "Alice invites ${it.myUserId}")
|
||||
aliceRoomPOV.membershipService().invite(it.myUserId)
|
||||
}
|
||||
}
|
||||
|
||||
newAccount.forEach {
|
||||
waitForAndAcceptInviteInRoom(testHelper, it, e2eRoomID)
|
||||
}
|
||||
|
||||
ensureMembersHaveJoined(testHelper, aliceSession, newAccount, e2eRoomID)
|
||||
|
||||
// wait a bit
|
||||
testHelper.runBlockingTest {
|
||||
delay(3_000)
|
||||
.let {
|
||||
cryptoTestHelper.inviteNewUsersAndWaitForThemToJoin(aliceSession, e2eRoomID, it)
|
||||
}
|
||||
|
||||
// check that messages are encrypted (uisi)
|
||||
|
@ -165,7 +122,7 @@ class E2eeSanityTests : InstrumentedTest {
|
|||
}
|
||||
timelineEvent != null &&
|
||||
timelineEvent.root.getClearType() == EventType.ENCRYPTED &&
|
||||
timelineEvent.root.mCryptoError == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID
|
||||
timelineEvent.root.mCryptoError == MXCryptoError.ErrorType.UNABLE_TO_DECRYPT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -747,49 +704,6 @@ class E2eeSanityTests : InstrumentedTest {
|
|||
testHelper.signOutAndClose(aliceNewSession)
|
||||
}
|
||||
|
||||
private fun ensureMembersHaveJoined(testHelper: CommonTestHelper, aliceSession: Session, otherAccounts: List<Session>, e2eRoomID: String) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
||||
otherAccounts.map {
|
||||
aliceSession.roomService().getRoomMember(it.myUserId, e2eRoomID)?.membership
|
||||
}.all {
|
||||
it == Membership.JOIN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun waitForAndAcceptInviteInRoom(testHelper: CommonTestHelper, otherSession: Session, e2eRoomID: String) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
||||
val roomSummary = otherSession.getRoomSummary(e2eRoomID)
|
||||
(roomSummary != null && roomSummary.membership == Membership.INVITE).also {
|
||||
if (it) {
|
||||
Log.v("#E2E TEST", "${otherSession.myUserId} can see the invite from alice")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not sure why it's taking so long :/
|
||||
testHelper.runBlockingTest(90_000) {
|
||||
Log.v("#E2E TEST", "${otherSession.myUserId} tries to join room $e2eRoomID")
|
||||
try {
|
||||
otherSession.roomService().joinRoom(e2eRoomID)
|
||||
} catch (ex: JoinRoomFailure.JoinedWithTimeout) {
|
||||
// it's ok we will wait after
|
||||
}
|
||||
}
|
||||
|
||||
Log.v("#E2E TEST", "${otherSession.myUserId} waiting for join echo ...")
|
||||
testHelper.waitWithLatch {
|
||||
testHelper.retryPeriodicallyWithLatch(it) {
|
||||
val roomSummary = otherSession.getRoomSummary(e2eRoomID)
|
||||
roomSummary != null && roomSummary.membership == Membership.JOIN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ensureIsDecrypted(testHelper: CommonTestHelper, sentEventIds: List<String>, session: Session, e2eRoomID: String) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
sentEventIds.forEach { sentEventId ->
|
||||
|
|
|
@ -625,11 +625,11 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
}
|
||||
|
||||
override fun enableKeyGossiping(enable: Boolean) {
|
||||
TODO("Not yet implemented")
|
||||
cryptoStore.enableKeyGossiping(enable)
|
||||
}
|
||||
|
||||
override fun isKeyGossipingEnabled(): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
return cryptoStore.isKeyGossipingEnabled()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue