Ignore secrets when the bundle does not contain the room keys version.
This commit is contained in:
parent
ff72bbb058
commit
7a10ce9e54
2 changed files with 86 additions and 2 deletions
|
|
@ -319,8 +319,16 @@ class DefaultElementClassicConnection(
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
ElementClassicConnectionState.ElementClassicReadyNoSession
|
ElementClassicConnectionState.ElementClassicReadyNoSession
|
||||||
} else {
|
} else {
|
||||||
val secrets = getString(KEY_SECRETS_STR)?.takeIf { it.isNotEmpty() }
|
var secrets = getString(KEY_SECRETS_STR)?.takeIf { it.isNotEmpty() }
|
||||||
val roomKeysVersion = getString(KEY_ROOM_KEYS_VERSION_STR)?.takeIf { it.isNotEmpty() }
|
val roomKeysVersion = getString(KEY_ROOM_KEYS_VERSION_STR)
|
||||||
|
.also {
|
||||||
|
if (secrets != null && it == null) {
|
||||||
|
Timber.tag(loggerTag.value).w("Room keys version is null, outdated version of Element Classic, ignore secrets")
|
||||||
|
// In this case, just ignore the secrets, the SDK will not accept them anyway
|
||||||
|
secrets = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?.takeIf { it.isNotEmpty() }
|
||||||
val homeserverUrl = getString(KEY_HOMESERVER_URL_STR)?.takeIf { it.isNotEmpty() }
|
val homeserverUrl = getString(KEY_HOMESERVER_URL_STR)?.takeIf { it.isNotEmpty() }
|
||||||
val displayName = getString(KEY_USER_DISPLAY_NAME_STR)?.takeIf { it.isNotEmpty() }
|
val displayName = getString(KEY_USER_DISPLAY_NAME_STR)?.takeIf { it.isNotEmpty() }
|
||||||
val doesContainBackupKey = secrets != null &&
|
val doesContainBackupKey = secrets != null &&
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,82 @@ class DefaultElementClassicConnectionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when session is received with secret but without room keys version Element Classic is outdated and the secret is ignored`() = runTest {
|
||||||
|
val connection = createDefaultElementClassicConnection(
|
||||||
|
homeServerLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(
|
||||||
|
checkResult = { Result.success(true) }
|
||||||
|
),
|
||||||
|
matrixAuthenticationService = FakeMatrixAuthenticationService(
|
||||||
|
setElementClassicSessionResult = {},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
connection.stateFlow.test {
|
||||||
|
assertThat(awaitItem()).isEqualTo(ElementClassicConnectionState.Idle)
|
||||||
|
// Simulate receiving a session from Element Classic
|
||||||
|
connection.onSessionReceived(
|
||||||
|
Bundle().apply {
|
||||||
|
putString(DefaultElementClassicConnection.KEY_USER_ID_STR, A_USER_ID.value)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_HOMESERVER_URL_STR, A_HOMESERVER_URL)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_SECRETS_STR, A_SECRET)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_ROOM_KEYS_VERSION_STR, null)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_USER_DISPLAY_NAME_STR, A_USER_NAME)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assertThat(awaitItem()).isEqualTo(
|
||||||
|
ElementClassicConnectionState.ElementClassicReady(
|
||||||
|
elementClassicSession = ElementClassicSession(
|
||||||
|
userId = A_USER_ID,
|
||||||
|
homeserverUrl = A_HOMESERVER_URL,
|
||||||
|
secrets = null,
|
||||||
|
roomKeysVersion = null,
|
||||||
|
doesContainBackupKey = false,
|
||||||
|
),
|
||||||
|
displayName = A_USER_NAME,
|
||||||
|
avatar = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when session is received with secret but with empty room keys version, doesContainBackupKey is false`() = runTest {
|
||||||
|
val connection = createDefaultElementClassicConnection(
|
||||||
|
homeServerLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(
|
||||||
|
checkResult = { Result.success(true) }
|
||||||
|
),
|
||||||
|
matrixAuthenticationService = FakeMatrixAuthenticationService(
|
||||||
|
setElementClassicSessionResult = {},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
connection.stateFlow.test {
|
||||||
|
assertThat(awaitItem()).isEqualTo(ElementClassicConnectionState.Idle)
|
||||||
|
// Simulate receiving a session from Element Classic
|
||||||
|
connection.onSessionReceived(
|
||||||
|
Bundle().apply {
|
||||||
|
putString(DefaultElementClassicConnection.KEY_USER_ID_STR, A_USER_ID.value)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_HOMESERVER_URL_STR, A_HOMESERVER_URL)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_SECRETS_STR, A_SECRET)
|
||||||
|
putString(DefaultElementClassicConnection.KEY_ROOM_KEYS_VERSION_STR, "")
|
||||||
|
putString(DefaultElementClassicConnection.KEY_USER_DISPLAY_NAME_STR, A_USER_NAME)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assertThat(awaitItem()).isEqualTo(
|
||||||
|
ElementClassicConnectionState.ElementClassicReady(
|
||||||
|
elementClassicSession = ElementClassicSession(
|
||||||
|
userId = A_USER_ID,
|
||||||
|
homeserverUrl = A_HOMESERVER_URL,
|
||||||
|
secrets = A_SECRET,
|
||||||
|
roomKeysVersion = null,
|
||||||
|
doesContainBackupKey = false,
|
||||||
|
),
|
||||||
|
displayName = A_USER_NAME,
|
||||||
|
avatar = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when session is received with empty data, and homeserver is supported, ElementClassicReady is emitted`() = runTest {
|
fun `when session is received with empty data, and homeserver is supported, ElementClassicReady is emitted`() = runTest {
|
||||||
val connection = createDefaultElementClassicConnection(
|
val connection = createDefaultElementClassicConnection(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue