post rebase fix & cleaning
This commit is contained in:
parent
92a72cb1e9
commit
f7d8356327
|
@ -25,13 +25,14 @@ import org.junit.runners.JUnit4
|
||||||
import org.junit.runners.MethodSorters
|
import org.junit.runners.MethodSorters
|
||||||
import org.matrix.android.sdk.InstrumentedTest
|
import org.matrix.android.sdk.InstrumentedTest
|
||||||
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
||||||
|
import org.matrix.android.sdk.api.session.getRoom
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
||||||
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest
|
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest
|
||||||
|
|
||||||
@RunWith(JUnit4::class)
|
@RunWith(JUnit4::class)
|
||||||
@FixMethodOrder(MethodSorters.JVM)
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
@LargeTest
|
@LargeTest
|
||||||
class E2eeTestConfig : InstrumentedTest {
|
class E2eeConfigTest : InstrumentedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testBlacklistUnverifiedDefault() = runCryptoTest(context()) { cryptoTestHelper, _ ->
|
fun testBlacklistUnverifiedDefault() = runCryptoTest(context()) { cryptoTestHelper, _ ->
|
||||||
|
@ -55,10 +56,8 @@ class E2eeTestConfig : InstrumentedTest {
|
||||||
|
|
||||||
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
||||||
// ensure other received
|
// ensure other received
|
||||||
testHelper.waitWithLatch { latch ->
|
testHelper.retryPeriodically {
|
||||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
roomBobPOV.timelineService().getTimelineEvent(sentMessage.eventId) != null
|
||||||
roomBobPOV.timelineService().getTimelineEvent(sentMessage.eventId) != null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoTestHelper.ensureCannotDecrypt(listOf(sentMessage.eventId), cryptoTestData.secondSession!!, cryptoTestData.roomId)
|
cryptoTestHelper.ensureCannotDecrypt(listOf(sentMessage.eventId), cryptoTestData.secondSession!!, cryptoTestData.roomId)
|
||||||
|
@ -81,10 +80,8 @@ class E2eeTestConfig : InstrumentedTest {
|
||||||
|
|
||||||
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
||||||
// ensure other received
|
// ensure other received
|
||||||
testHelper.waitWithLatch { latch ->
|
testHelper.retryPeriodically {
|
||||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
roomBobPOV.timelineService().getTimelineEvent(sentMessage.eventId) != null
|
||||||
roomBobPOV.timelineService().getTimelineEvent(sentMessage.eventId) != null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoTestHelper.ensureCanDecrypt(
|
cryptoTestHelper.ensureCanDecrypt(
|
||||||
|
@ -105,10 +102,8 @@ class E2eeTestConfig : InstrumentedTest {
|
||||||
|
|
||||||
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
val roomBobPOV = cryptoTestData.secondSession!!.roomService().getRoom(cryptoTestData.roomId)!!
|
||||||
// ensure other received
|
// ensure other received
|
||||||
testHelper.waitWithLatch { latch ->
|
testHelper.retryPeriodically {
|
||||||
testHelper.retryPeriodicallyWithLatch(latch) {
|
roomBobPOV.timelineService().getTimelineEvent(beforeMessage.eventId) != null
|
||||||
roomBobPOV.timelineService().getTimelineEvent(beforeMessage.eventId) != null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoTestHelper.ensureCanDecrypt(
|
cryptoTestHelper.ensureCanDecrypt(
|
||||||
|
@ -118,10 +113,15 @@ class E2eeTestConfig : InstrumentedTest {
|
||||||
listOf(beforeMessage.getLastMessageContent()!!.body)
|
listOf(beforeMessage.getLastMessageContent()!!.body)
|
||||||
)
|
)
|
||||||
|
|
||||||
cryptoTestData.firstSession.cryptoService().setRoomBlacklistUnverifiedDevices(cryptoTestData.roomId, true)
|
cryptoTestData.firstSession.cryptoService().setRoomBlockUnverifiedDevices(cryptoTestData.roomId, true)
|
||||||
|
|
||||||
val afterMessage = testHelper.sendTextMessage(roomAlicePOV, "you are blocked", 1).first()
|
val afterMessage = testHelper.sendTextMessage(roomAlicePOV, "you are blocked", 1).first()
|
||||||
|
|
||||||
|
// ensure received
|
||||||
|
testHelper.retryPeriodically {
|
||||||
|
cryptoTestData.secondSession?.getRoom(cryptoTestData.roomId)?.timelineService()?.getTimelineEvent(afterMessage.eventId)?.root != null
|
||||||
|
}
|
||||||
|
|
||||||
cryptoTestHelper.ensureCannotDecrypt(
|
cryptoTestHelper.ensureCannotDecrypt(
|
||||||
listOf(afterMessage.eventId),
|
listOf(afterMessage.eventId),
|
||||||
cryptoTestData.secondSession!!,
|
cryptoTestData.secondSession!!,
|
|
@ -104,7 +104,7 @@ interface CryptoService {
|
||||||
*/
|
*/
|
||||||
fun isShareKeysOnInviteEnabled(): Boolean
|
fun isShareKeysOnInviteEnabled(): Boolean
|
||||||
|
|
||||||
fun setRoomUnBlacklistUnverifiedDevices(roomId: String)
|
fun setRoomUnBlockUnverifiedDevices(roomId: String)
|
||||||
|
|
||||||
fun getDeviceTrackingStatus(userId: String): Int
|
fun getDeviceTrackingStatus(userId: String): Int
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ interface CryptoService {
|
||||||
|
|
||||||
suspend fun exportRoomKeys(password: String): ByteArray
|
suspend fun exportRoomKeys(password: String): ByteArray
|
||||||
|
|
||||||
fun setRoomBlacklistUnverifiedDevices(roomId: String, enable: Boolean)
|
fun setRoomBlockUnverifiedDevices(roomId: String, block: Boolean)
|
||||||
|
|
||||||
fun getCryptoDeviceInfo(userId: String, deviceId: String?): CryptoDeviceInfo?
|
fun getCryptoDeviceInfo(userId: String, deviceId: String?): CryptoDeviceInfo?
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 New Vector Ltd
|
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
package org.matrix.android.sdk.api.session.crypto
|
package org.matrix.android.sdk.api.session.crypto
|
||||||
|
|
||||||
data class GlobalCryptoConfig(
|
data class GlobalCryptoConfig(
|
||||||
val globalBlacklistUnverifiedDevices: Boolean,
|
val globalBlockUnverifiedDevices: Boolean,
|
||||||
val globalEnableKeyGossiping: Boolean,
|
val globalEnableKeyGossiping: Boolean,
|
||||||
val enableKeyForwardingOnInvite: Boolean,
|
val enableKeyForwardingOnInvite: Boolean,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1194,10 +1194,10 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
* Add this room to the ones which don't encrypt messages to unverified devices.
|
* Add this room to the ones which don't encrypt messages to unverified devices.
|
||||||
*
|
*
|
||||||
* @param roomId the room id
|
* @param roomId the room id
|
||||||
* @param if true will block sending keys to unverified devices
|
* @param block if true will block sending keys to unverified devices
|
||||||
*/
|
*/
|
||||||
override fun setRoomBlacklistUnverifiedDevices(roomId: String, enable: Boolean) {
|
override fun setRoomBlockUnverifiedDevices(roomId: String, block: Boolean) {
|
||||||
cryptoStore.blackListUnverifiedDevicesInRoom(roomId, enable)
|
cryptoStore.blockUnverifiedDevicesInRoom(roomId, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1205,8 +1205,8 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param roomId the room id
|
* @param roomId the room id
|
||||||
*/
|
*/
|
||||||
override fun setRoomUnBlacklistUnverifiedDevices(roomId: String) {
|
override fun setRoomUnBlockUnverifiedDevices(roomId: String) {
|
||||||
setRoomBlacklistUnverifiedDevices(roomId, false)
|
setRoomBlockUnverifiedDevices(roomId, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -138,9 +138,9 @@ internal interface IMXCryptoStore {
|
||||||
* Define if encryption keys should be sent to unverified devices in this room.
|
* Define if encryption keys should be sent to unverified devices in this room.
|
||||||
*
|
*
|
||||||
* @param roomId the roomId
|
* @param roomId the roomId
|
||||||
* @param blacklist if true will not send keys to unverified devices
|
* @param block if true will not send keys to unverified devices
|
||||||
*/
|
*/
|
||||||
fun blackListUnverifiedDevicesInRoom(roomId: String, blacklist: Boolean)
|
fun blockUnverifiedDevicesInRoom(roomId: String, block: Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current keys backup version.
|
* Get the current keys backup version.
|
||||||
|
|
|
@ -451,7 +451,7 @@ internal class RealmCryptoStore @Inject constructor(
|
||||||
realm.where<CryptoMetadataEntity>().findFirst()
|
realm.where<CryptoMetadataEntity>().findFirst()
|
||||||
?.let {
|
?.let {
|
||||||
GlobalCryptoConfig(
|
GlobalCryptoConfig(
|
||||||
globalBlacklistUnverifiedDevices = it.globalBlacklistUnverifiedDevices,
|
globalBlockUnverifiedDevices = it.globalBlacklistUnverifiedDevices,
|
||||||
globalEnableKeyGossiping = it.globalEnableKeyGossiping,
|
globalEnableKeyGossiping = it.globalEnableKeyGossiping,
|
||||||
enableKeyForwardingOnInvite = it.enableKeyForwardingOnInvite
|
enableKeyForwardingOnInvite = it.enableKeyForwardingOnInvite
|
||||||
)
|
)
|
||||||
|
@ -467,7 +467,7 @@ internal class RealmCryptoStore @Inject constructor(
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
GlobalCryptoConfig(
|
GlobalCryptoConfig(
|
||||||
globalBlacklistUnverifiedDevices = it.globalBlacklistUnverifiedDevices,
|
globalBlockUnverifiedDevices = it.globalBlacklistUnverifiedDevices,
|
||||||
globalEnableKeyGossiping = it.globalEnableKeyGossiping,
|
globalEnableKeyGossiping = it.globalEnableKeyGossiping,
|
||||||
enableKeyForwardingOnInvite = it.enableKeyForwardingOnInvite
|
enableKeyForwardingOnInvite = it.enableKeyForwardingOnInvite
|
||||||
)
|
)
|
||||||
|
@ -1121,10 +1121,10 @@ internal class RealmCryptoStore @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun blackListUnverifiedDevicesInRoom(roomId: String, blacklist: Boolean) {
|
override fun blockUnverifiedDevicesInRoom(roomId: String, block: Boolean) {
|
||||||
doRealmTransaction(realmConfiguration) { realm ->
|
doRealmTransaction(realmConfiguration) { realm ->
|
||||||
CryptoRoomEntity.getById(realm, roomId)
|
CryptoRoomEntity.getById(realm, roomId)
|
||||||
?.blacklistUnverifiedDevices = blacklist
|
?.blacklistUnverifiedDevices = block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ sealed class RoomSettingsAction : VectorViewModelAction {
|
||||||
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
|
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
|
||||||
data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules) : RoomSettingsAction()
|
data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules) : RoomSettingsAction()
|
||||||
data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction()
|
data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction()
|
||||||
data class SetEncryptToVerifiedDeviceOnly(val enable: Boolean) : RoomSettingsAction()
|
data class SetEncryptToVerifiedDeviceOnly(val enabled: Boolean) : RoomSettingsAction()
|
||||||
|
|
||||||
object Save : RoomSettingsAction()
|
object Save : RoomSettingsAction()
|
||||||
object Cancel : RoomSettingsAction()
|
object Cancel : RoomSettingsAction()
|
||||||
|
|
|
@ -154,7 +154,7 @@ class RoomSettingsController @Inject constructor(
|
||||||
buildProfileSection(stringProvider.getString(R.string.room_profile_section_security))
|
buildProfileSection(stringProvider.getString(R.string.room_profile_section_security))
|
||||||
|
|
||||||
data.globalCryptoConfig.invoke()?.let { globalConfig ->
|
data.globalCryptoConfig.invoke()?.let { globalConfig ->
|
||||||
if (globalConfig.globalBlacklistUnverifiedDevices) {
|
if (globalConfig.globalBlockUnverifiedDevices) {
|
||||||
genericFooterItem {
|
genericFooterItem {
|
||||||
id("globalConfig")
|
id("globalConfig")
|
||||||
centered(false)
|
centered(false)
|
||||||
|
|
|
@ -252,7 +252,7 @@ class RoomSettingsViewModel @AssistedInject constructor(
|
||||||
is RoomSettingsAction.SetRoomGuestAccess -> handleSetGuestAccess(action)
|
is RoomSettingsAction.SetRoomGuestAccess -> handleSetGuestAccess(action)
|
||||||
is RoomSettingsAction.Save -> saveSettings()
|
is RoomSettingsAction.Save -> saveSettings()
|
||||||
is RoomSettingsAction.Cancel -> cancel()
|
is RoomSettingsAction.Cancel -> cancel()
|
||||||
is RoomSettingsAction.SetEncryptToVerifiedDeviceOnly -> setEncryptToVerifiedDeviceOnly(action.enable)
|
is RoomSettingsAction.SetEncryptToVerifiedDeviceOnly -> setEncryptToVerifiedDeviceOnly(action.enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ class RoomSettingsViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
private fun setEncryptToVerifiedDeviceOnly(enabled: Boolean) {
|
private fun setEncryptToVerifiedDeviceOnly(enabled: Boolean) {
|
||||||
session.coroutineScope.launch {
|
session.coroutineScope.launch {
|
||||||
session.cryptoService().setRoomBlacklistUnverifiedDevices(room.roomId, enabled)
|
session.cryptoService().setRoomBlockUnverifiedDevices(room.roomId, enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue