From 35f011ba37fbea05edb2cd258e952e4b5ccfe392 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 8 Jan 2020 18:19:37 +0100 Subject: [PATCH] Fix ktlint issues --- .../matrix/android/common/CommonTestHelper.kt | 8 ++--- .../matrix/android/common/CryptoTestHelper.kt | 1 - .../android/common/MockOkHttpInterceptor.kt | 3 -- .../crypto/AttachmentEncryptionTest.kt | 1 - .../crypto/keysbackup/KeysBackupTest.kt | 9 ------ .../internal/crypto/verification/SASTest.kt | 31 +++++-------------- .../internal/crypto/keysbackup/KeysBackup.kt | 1 - .../crypto/keysbackup/util/Base58Test.kt | 3 +- 8 files changed, 12 insertions(+), 45 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt index 7525cb1c0b..b16c865765 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt @@ -50,7 +50,6 @@ class CommonTestHelper(context: Context) { matrix = Matrix.getInstance(context) } - fun createAccount(userNamePrefix: String, testParams: SessionTestParams): Session { return createAccount(userNamePrefix, TestConstants.PASSWORD, testParams) } @@ -74,7 +73,7 @@ class CommonTestHelper(context: Context) { * @param session the session to sync */ fun syncSession(session: Session) { - //val lock = CountDownLatch(1) + // val lock = CountDownLatch(1) // val observer = androidx.lifecycle.Observer { syncState -> // if (syncState is SyncState.Idle) { @@ -89,8 +88,8 @@ class CommonTestHelper(context: Context) { session.open() session.startSync(true) - //await(lock) - //session.syncState().removeObserver(observer) + // await(lock) + // session.syncState().removeObserver(observer) } /** @@ -129,7 +128,6 @@ class CommonTestHelper(context: Context) { return sentEvents } - // PRIVATE METHODS ***************************************************************************** /** diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt index 4ba421e826..df45249265 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CryptoTestHelper.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.common import android.os.SystemClock -import android.text.TextUtils import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/MockOkHttpInterceptor.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/MockOkHttpInterceptor.kt index c3d5d73552..a1f95424a6 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/MockOkHttpInterceptor.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/MockOkHttpInterceptor.kt @@ -41,7 +41,6 @@ class MockOkHttpInterceptor : Interceptor { private var rules: ArrayList = ArrayList() - fun addRule(rule: Rule) { rules.add(rule) } @@ -60,7 +59,6 @@ class MockOkHttpInterceptor : Interceptor { return chain.proceed(originalRequest) } - abstract class Rule(val match: String) { abstract fun process(originalRequest: Request): Response? } @@ -81,6 +79,5 @@ class MockOkHttpInterceptor : Interceptor { .code(code) .build() } - } } diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/AttachmentEncryptionTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/AttachmentEncryptionTest.kt index 39a98693b5..84b3f24191 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/AttachmentEncryptionTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/AttachmentEncryptionTest.kt @@ -16,7 +16,6 @@ package im.vector.matrix.android.internal.crypto - import android.os.MemoryFile import android.util.Base64 import androidx.test.ext.junit.runners.AndroidJUnit4 diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt index 5dbc45c7cf..15deebdab1 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt @@ -150,7 +150,6 @@ class KeysBackupTest : InstrumentedTest { var megolmBackupCreationInfo: MegolmBackupCreationInfo? = null val latch = CountDownLatch(1) keysBackup.prepareKeysBackupVersion(null, null, object : MatrixCallback { - override fun onSuccess(data: MegolmBackupCreationInfo) { megolmBackupCreationInfo = data @@ -210,7 +209,6 @@ class KeysBackupTest : InstrumentedTest { mTestHelper.await(latch) - val nbOfKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(false) val backedUpKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(true) @@ -230,7 +228,6 @@ class KeysBackupTest : InstrumentedTest { cryptoTestData.close() } - /** * Check that backupAllGroupSessions() returns valid data */ @@ -258,7 +255,6 @@ class KeysBackupTest : InstrumentedTest { assertEquals(nbOfKeys, total) lastBackedUpKeysProgress = progress } - }, TestMatrixCallback(latch)) mTestHelper.await(latch) @@ -400,7 +396,6 @@ class KeysBackupTest : InstrumentedTest { testData.cryptoTestData.close() } - /** * - Do an e2e backup to the homeserver with a recovery key * - And log Alice on a new device @@ -1081,7 +1076,6 @@ class KeysBackupTest : InstrumentedTest { keysBackup.backupAllGroupSessions(object : ProgressListener { override fun onProgress(progress: Int, total: Int) { } - }, TestMatrixCallback(latch2, false)) mTestHelper.await(latch2) @@ -1121,7 +1115,6 @@ class KeysBackupTest : InstrumentedTest { val latch = CountDownLatch(1) keysBackup.backupAllGroupSessions(object : ProgressListener { override fun onProgress(progress: Int, total: Int) { - } }, TestMatrixCallback(latch)) mTestHelper.await(latch) @@ -1153,7 +1146,6 @@ class KeysBackupTest : InstrumentedTest { keysBackup2.backupAllGroupSessions(object : ProgressListener { override fun onProgress(progress: Int, total: Int) { } - }, object : TestMatrixCallback(latch2, false) { override fun onSuccess(data: Unit) { isSuccessful = true @@ -1274,7 +1266,6 @@ class KeysBackupTest : InstrumentedTest { var megolmBackupCreationInfo: MegolmBackupCreationInfo? = null val latch = CountDownLatch(1) keysBackup.prepareKeysBackupVersion(password, null, object : MatrixCallback { - override fun onSuccess(data: MegolmBackupCreationInfo) { megolmBackupCreationInfo = data diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/verification/SASTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/verification/SASTest.kt index d6f2f169a8..c05523f009 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/verification/SASTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/verification/SASTest.kt @@ -88,13 +88,12 @@ class SASTest : InstrumentedTest { assertEquals("Alice state should be started", SasVerificationTxState.Started, aliceSasTx!!.state) assertEquals("Bob state should be started by alice", SasVerificationTxState.OnStarted, bobSasTx!!.state) - //Let's cancel from alice side + // Let's cancel from alice side val cancelLatch = CountDownLatch(1) val bobListener2 = object : SasVerificationService.SasVerificationListener { override fun transactionCreated(tx: SasVerificationTransaction) {} - override fun transactionUpdated(tx: SasVerificationTransaction) { if (tx.transactionId == txID) { if ((tx as SASVerificationTransaction).state === SasVerificationTxState.OnCancelled) { @@ -135,7 +134,7 @@ class SASTest : InstrumentedTest { val protocols = listOf("meh_dont_know") val tid = "00000000" - //Bob should receive a cancel + // Bob should receive a cancel var canceledToDeviceEvent: Event? = null val cancelLatch = CountDownLatch(1) // TODO bobSession!!.dataHandler.addListener(object : MXEventListener() { @@ -166,7 +165,6 @@ class SASTest : InstrumentedTest { } aliceSession.getSasVerificationService().addListener(aliceListener) - fakeBobStart(bobSession, aliceUserID, aliceDevice, tid, protocols = protocols) mTestHelper.await(cancelLatch) @@ -175,7 +173,6 @@ class SASTest : InstrumentedTest { assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code) cryptoTestData.close() - } @Test @@ -187,7 +184,7 @@ class SASTest : InstrumentedTest { val mac = listOf("shaBit") val tid = "00000000" - //Bob should receive a cancel + // Bob should receive a cancel var canceledToDeviceEvent: Event? = null val cancelLatch = CountDownLatch(1) // TODO bobSession!!.dataHandler.addListener(object : MXEventListener() { @@ -213,7 +210,6 @@ class SASTest : InstrumentedTest { assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code) cryptoTestData.close() - } @Test @@ -222,11 +218,10 @@ class SASTest : InstrumentedTest { val bobSession = cryptoTestData.secondSession!! - val codes = listOf("bin", "foo", "bar") val tid = "00000000" - //Bob should receive a cancel + // Bob should receive a cancel var canceledToDeviceEvent: Event? = null val cancelLatch = CountDownLatch(1) // TODO bobSession!!.dataHandler.addListener(object : MXEventListener() { @@ -252,7 +247,6 @@ class SASTest : InstrumentedTest { assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code) cryptoTestData.close() - } private fun fakeBobStart(bobSession: Session, @@ -284,8 +278,7 @@ class SASTest : InstrumentedTest { // TODO ) } - - //any two devices may only have at most one key verification in flight at a time. + // any two devices may only have at most one key verification in flight at a time. // If a device has two verifications in progress with the same device, then it should cancel both verifications. @Test fun test_aliceStartTwoRequests() { @@ -294,7 +287,6 @@ class SASTest : InstrumentedTest { val aliceSession = cryptoTestData.firstSession val bobSession = cryptoTestData.secondSession - val aliceSasMgr = aliceSession.getSasVerificationService() val aliceCreatedLatch = CountDownLatch(2) @@ -343,7 +335,6 @@ class SASTest : InstrumentedTest { var accepted: KeyVerificationAccept? = null var startReq: KeyVerificationStart? = null - val aliceAcceptedLatch = CountDownLatch(1) val aliceListener = object : SasVerificationService.SasVerificationListener { override fun markedAsManuallyVerified(userId: String, deviceId: String) {} @@ -375,7 +366,6 @@ class SASTest : InstrumentedTest { } bobSasMgr.addListener(bobListener) - val bobUserId = bobSession.myUserId val bobDeviceId = bobSession.getMyDevice().deviceId aliceSasMgr.beginKeyVerificationSAS(bobUserId, bobDeviceId) @@ -383,7 +373,7 @@ class SASTest : InstrumentedTest { assertTrue("Should have receive a commitment", accepted!!.commitment?.trim()?.isEmpty() == false) - //check that agreement is valid + // check that agreement is valid assertTrue("Agreed Protocol should be Valid", accepted!!.isValid()) assertTrue("Agreed Protocol should be known by alice", startReq!!.keyAgreementProtocols!!.contains(accepted!!.keyAgreementProtocol)) assertTrue("Hash should be known by alice", startReq!!.hashes!!.contains(accepted!!.hash)) @@ -406,7 +396,6 @@ class SASTest : InstrumentedTest { val aliceSasMgr = aliceSession.getSasVerificationService() val bobSasMgr = bobSession!!.getSasVerificationService() - val aliceSASLatch = CountDownLatch(1) val aliceListener = object : SasVerificationService.SasVerificationListener { override fun transactionCreated(tx: SasVerificationTransaction) {} @@ -446,7 +435,6 @@ class SASTest : InstrumentedTest { } bobSasMgr.addListener(bobListener) - val bobUserId = bobSession.myUserId val bobDeviceId = bobSession.getMyDevice().deviceId val verificationSAS = aliceSasMgr.beginKeyVerificationSAS(bobUserId, bobDeviceId) @@ -462,7 +450,6 @@ class SASTest : InstrumentedTest { cryptoTestData.close() } - @Test fun test_happyPath() { val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoom() @@ -473,7 +460,6 @@ class SASTest : InstrumentedTest { val aliceSasMgr = aliceSession.getSasVerificationService() val bobSasMgr = bobSession!!.getSasVerificationService() - val aliceSASLatch = CountDownLatch(1) val aliceListener = object : SasVerificationService.SasVerificationListener { override fun transactionCreated(tx: SasVerificationTransaction) {} @@ -519,18 +505,17 @@ class SASTest : InstrumentedTest { } bobSasMgr.addListener(bobListener) - val bobUserId = bobSession.myUserId val bobDeviceId = bobSession.getMyDevice().deviceId aliceSasMgr.beginKeyVerificationSAS(bobUserId, bobDeviceId) mTestHelper.await(aliceSASLatch) mTestHelper.await(bobSASLatch) - //Assert that devices are verified + // Assert that devices are verified val bobDeviceInfoFromAlicePOV: MXDeviceInfo? = aliceSession.getDeviceInfo(bobUserId, bobDeviceId) val aliceDeviceInfoFromBobPOV: MXDeviceInfo? = bobSession.getDeviceInfo(aliceSession.myUserId, aliceSession.getMyDevice().deviceId) - //latch wait a bit again + // latch wait a bit again Thread.sleep(1000) assertTrue("alice device should be verified from bob point of view", aliceDeviceInfoFromBobPOV!!.isVerified) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt index 61bf7841c7..99267ee89c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt @@ -1364,7 +1364,6 @@ internal class KeysBackup @Inject constructor( .executeBy(taskExecutor) } - companion object { // Maximum delay in ms in {@link maybeBackupKeys} private const val KEY_BACKUP_WAITING_TIME_TO_SEND_KEY_BACKUP_MILLIS = 10_000L diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt index ce1f6a6fd0..42295dada0 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt @@ -16,7 +16,6 @@ package im.vector.matrix.android.internal.crypto.keysbackup.util - import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals import org.junit.FixMethodOrder @@ -35,7 +34,7 @@ class Base58Test { @Test fun decode() { // Example comes from https://github.com/keis/base58 - assertArrayEquals("hello world".toByteArray(), base58decode("StV1DL6CwTryKyV")); + assertArrayEquals("hello world".toByteArray(), base58decode("StV1DL6CwTryKyV")) } @Test