code review

This commit is contained in:
Valere 2022-05-12 18:45:19 +02:00
parent 5a323db7dc
commit 8077406cba
7 changed files with 18 additions and 17 deletions

View file

@ -231,7 +231,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
return cryptoTestData return cryptoTestData
} }
private fun ensureEventReceived(roomId: String, eventId: String, session: Session, andCanDecrypt : Boolean) { private fun ensureEventReceived(roomId: String, eventId: String, session: Session, andCanDecrypt: Boolean) {
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch { latch ->
testHelper.retryPeriodicallyWithLatch(latch) { testHelper.retryPeriodicallyWithLatch(latch) {
val timeLineEvent = session.getRoom(roomId)?.timelineService()?.getTimelineEvent(eventId) val timeLineEvent = session.getRoom(roomId)?.timelineService()?.getTimelineEvent(eventId)

View file

@ -24,7 +24,6 @@ import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.junit.runners.MethodSorters import org.junit.runners.MethodSorters
@ -63,7 +62,6 @@ class KeysBackupTest : InstrumentedTest {
*/ */
@Test @Test
fun roomKeysTest_testBackupStore_ok() { fun roomKeysTest_testBackupStore_ok() {
val testHelper = CommonTestHelper(context()) val testHelper = CommonTestHelper(context())
val cryptoTestHelper = CryptoTestHelper(testHelper) val cryptoTestHelper = CryptoTestHelper(testHelper)
@ -105,7 +103,6 @@ class KeysBackupTest : InstrumentedTest {
*/ */
@Test @Test
fun prepareKeysBackupVersionTest() { fun prepareKeysBackupVersionTest() {
val testHelper = CommonTestHelper(context()) val testHelper = CommonTestHelper(context())
val cryptoTestHelper = CryptoTestHelper(testHelper) val cryptoTestHelper = CryptoTestHelper(testHelper)

View file

@ -113,7 +113,7 @@ internal class KeysBackupTestHelper(
keysBackup.createKeysBackupVersion(megolmBackupCreationInfo, it) keysBackup.createKeysBackupVersion(megolmBackupCreationInfo, it)
} }
Assert.assertNotNull("Key backup version should not be null",keysVersion.version) Assert.assertNotNull("Key backup version should not be null", keysVersion.version)
// Backup must be enable now // Backup must be enable now
Assert.assertTrue(keysBackup.isEnabled) Assert.assertTrue(keysBackup.isEnabled)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright 2020 The Matrix.org Foundation C.I.C. * Copyright 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.

View file

@ -347,7 +347,6 @@ internal class DefaultKeysBackupService @Inject constructor(
override fun backupAllGroupSessions(progressListener: ProgressListener?, override fun backupAllGroupSessions(progressListener: ProgressListener?,
callback: MatrixCallback<Unit>?) { callback: MatrixCallback<Unit>?) {
if (!isEnabled || backupOlmPkEncryption == null || keysBackupVersion == null) { if (!isEnabled || backupOlmPkEncryption == null || keysBackupVersion == null) {
callback?.onFailure(Throwable("Backup not enabled")) callback?.onFailure(Throwable("Backup not enabled"))
return return

View file

@ -98,9 +98,8 @@ class KeysBackupManageActivity : SimpleFragmentActivity() {
is KeysBackupViewEvents.RequestStore4SSecret -> { is KeysBackupViewEvents.RequestStore4SSecret -> {
secretStartForActivityResult.launch( secretStartForActivityResult.launch(
SharedSecureStorageActivity.newWriteIntent( SharedSecureStorageActivity.newWriteIntent(
this, context = this,
null, // default key writeSecrets = listOf(KEYBACKUP_SECRET_SSSS_NAME to it.recoveryKey)
listOf(KEYBACKUP_SECRET_SSSS_NAME to it.recoveryKey)
) )
) )
} }

View file

@ -156,14 +156,20 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS
suspend fun completeBackupCreation() { suspend fun completeBackupCreation() {
val info = pendingBackupCreationInfo ?: return val info = pendingBackupCreationInfo ?: return
val version = awaitCallback<KeysVersion> { try {
session.cryptoService().keysBackupService().createKeysBackupVersion(info, it) val version = awaitCallback<KeysVersion> {
} session.cryptoService().keysBackupService().createKeysBackupVersion(info, it)
// Save it for gossiping }
Timber.d("## BootstrapCrossSigningTask: Creating 4S - Save megolm backup key for gossiping") // Save it for gossiping
session.cryptoService().keysBackupService().saveBackupRecoveryKey(info.recoveryKey, version = version.version) Timber.d("## BootstrapCrossSigningTask: Creating 4S - Save megolm backup key for gossiping")
session.cryptoService().keysBackupService().saveBackupRecoveryKey(info.recoveryKey, version = version.version)
} catch (failure: Throwable) {
// XXX mm... failed we should remove what we put in 4S, as it was not created?
// TODO catch, delete 4S account data // for now just stay on the screen, user can retry, there is no api to delete account data
} finally {
pendingBackupCreationInfo = null
}
} }
private fun deleteCurrentBackup() { private fun deleteCurrentBackup() {