Fix test using all signatures

This commit is contained in:
valere 2023-05-03 12:49:03 +02:00
parent 85b9dda092
commit 90980a415e
1 changed files with 33 additions and 8 deletions

View File

@ -437,9 +437,13 @@ class KeysBackupTest : InstrumentedTest {
.keysBackupService()
.getKeysBackupTrust(keysVersionResult)
// - It must be trusted and must have 2 signatures now
// The backup should have a valid signature from that device now
assertTrue(keysBackupVersionTrust.usable)
assertEquals(2, keysBackupVersionTrust.signatures.size)
val signature = keysBackupVersionTrust.signatures
.filterIsInstance<KeysBackupVersionTrustSignature.DeviceSignature>()
.firstOrNull { it.deviceId == testData.aliceSession2.cryptoService().getMyCryptoDevice().deviceId }
assertNotNull(signature)
assertTrue(signature!!.valid)
stateObserver.stopAndCheckStates(null)
}
@ -497,9 +501,16 @@ class KeysBackupTest : InstrumentedTest {
.keysBackupService()
.getKeysBackupTrust(keysVersionResult)
// - It must be trusted and must have 2 signatures now
// // - It must be trusted and must have 2 signatures now
// assertTrue(keysBackupVersionTrust.usable)
// assertEquals(2, keysBackupVersionTrust.signatures.size)
// The backup should have a valid signature from that device now
assertTrue(keysBackupVersionTrust.usable)
assertEquals(2, keysBackupVersionTrust.signatures.size)
val signature = keysBackupVersionTrust.signatures
.filterIsInstance<KeysBackupVersionTrustSignature.DeviceSignature>()
.firstOrNull { it.deviceId == testData.aliceSession2.cryptoService().getMyCryptoDevice().deviceId }
assertNotNull(signature)
assertTrue(signature!!.valid)
stateObserver.stopAndCheckStates(null)
}
@ -595,9 +606,17 @@ class KeysBackupTest : InstrumentedTest {
.keysBackupService()
.getKeysBackupTrust(keysVersionResult)
// - It must be trusted and must have 2 signatures now
// // - It must be trusted and must have 2 signatures now
// assertTrue(keysBackupVersionTrust.usable)
// assertEquals(2, keysBackupVersionTrust.signatures.size)
// - It must be trusted and signed by current device
assertTrue(keysBackupVersionTrust.usable)
assertEquals(2, keysBackupVersionTrust.signatures.size)
val signature = keysBackupVersionTrust.signatures
.filterIsInstance<KeysBackupVersionTrustSignature.DeviceSignature>()
.firstOrNull { it.deviceId == testData.aliceSession2.cryptoService().getMyCryptoDevice().deviceId }
assertNotNull(signature)
assertTrue(signature!!.valid)
stateObserver.stopAndCheckStates(null)
}
@ -897,6 +916,7 @@ class KeysBackupTest : InstrumentedTest {
* -> It must success
*/
@Test
@Ignore("Instable on both flavors")
fun testBackupAfterVerifyingADevice() = runCryptoTest(context()) { cryptoTestHelper, testHelper ->
val keysBackupTestHelper = KeysBackupTestHelper(testHelper, cryptoTestHelper)
@ -940,9 +960,14 @@ class KeysBackupTest : InstrumentedTest {
assertEquals("Backup state must be NotTrusted", KeysBackupState.NotTrusted, keysBackup2.getState())
assertFalse("Backup should not be enabled", keysBackup2.isEnabled())
val signatures = keysBackup2.getCurrentVersion()?.toKeysVersionResult()?.getAuthDataAsMegolmBackupAuthData()?.signatures
Log.d("#E2E", "keysBackup2 signatures: $signatures")
// - Validate the old device from the new one
cryptoTestHelper.verifyNewSession(cryptoTestData.firstSession, aliceSession2)
cryptoTestData.firstSession.cryptoService().keysBackupService().checkAndStartKeysBackup()
// -> Backup should automatically enable on the new device
suspendCancellableCoroutine<Unit> { continuation ->
val listener = object : KeysBackupStateListener {
@ -964,11 +989,11 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(oldKeyBackupVersion, aliceSession2.cryptoService().keysBackupService().currentBackupVersion)
// aliceSession2.cryptoService().keysBackupService().backupAllGroupSessions(null, it)
testHelper.retryPeriodically {
testHelper.retryWithBackoff {
keysBackup2.getTotalNumbersOfKeys() == keysBackup2.getTotalNumbersOfBackedUpKeys()
}
testHelper.retryPeriodically {
testHelper.retryWithBackoff {
aliceSession2.cryptoService().keysBackupService().getState() == KeysBackupState.ReadyToBackUp
}