Add instrumentation test for testing AES/GCM nonces are really unique
This commit is contained in:
parent
e955e021fd
commit
74aa62a264
5 changed files with 44 additions and 4 deletions
|
@ -37,6 +37,15 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
java.srcDirs += "$projectDir/src/sharedTest/java"
|
||||
}
|
||||
androidTest {
|
||||
java.srcDirs += "$projectDir/src/sharedTest/java"
|
||||
}
|
||||
}
|
||||
|
||||
// optional signingConfigs
|
||||
def keystorePropertiesFile = rootProject.file("keystore.properties")
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.stevesoltys.backup
|
||||
|
||||
import android.util.Log
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import com.stevesoltys.backup.crypto.CipherFactoryImpl
|
||||
import com.stevesoltys.backup.crypto.KeyManagerTestImpl
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
private val TAG = CipherUniqueNonceTest::class.java.simpleName
|
||||
private const val ITERATIONS = 1_000_000
|
||||
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class CipherUniqueNonceTest {
|
||||
|
||||
private val keyManager = KeyManagerTestImpl()
|
||||
private val cipherFactory = CipherFactoryImpl(keyManager)
|
||||
|
||||
private val nonceSet = HashSet<ByteArray>()
|
||||
|
||||
@Test
|
||||
fun testUniqueNonce() {
|
||||
for (i in 1..ITERATIONS) {
|
||||
val iv = cipherFactory.createEncryptionCipher().iv
|
||||
Log.w(TAG, "$i: ${iv.toHexString()}")
|
||||
assertTrue(nonceSet.add(iv))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ import kotlin.random.Random
|
|||
private const val filename = "test-file"
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AndroidUnitTest {
|
||||
class DocumentsStorageTest {
|
||||
|
||||
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
private val folderUri = getBackupFolderUri(context)
|
|
@ -1,11 +1,9 @@
|
|||
package com.stevesoltys.backup
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Assertions.fail
|
||||
import kotlin.random.Random
|
||||
|
||||
fun assertContains(stack: String?, needle: String) {
|
||||
assertTrue(stack?.contains(needle) ?: fail())
|
||||
if (stack?.contains(needle) != true) throw AssertionError()
|
||||
}
|
||||
|
||||
fun getRandomByteArray(size: Int = Random.nextInt(1337)) = ByteArray(size).apply {
|
Loading…
Reference in a new issue