diff --git a/WalletSdk/build.gradle.kts b/WalletSdk/build.gradle.kts index d187615..cb66bfb 100644 --- a/WalletSdk/build.gradle.kts +++ b/WalletSdk/build.gradle.kts @@ -128,6 +128,7 @@ dependencies { implementation("androidx.camera:camera-view:1.3.2") implementation("com.google.zxing:core:3.3.3") implementation("com.google.accompanist:accompanist-permissions:0.34.0") + implementation("androidx.test.ext:junit-ktx:1.1.5") /* End UI dependencies */ testImplementation("junit:junit:4.13.2") testImplementation("org.robolectric:robolectric:4.8") diff --git a/WalletSdk/src/main/java/com/spruceid/wallet/sdk/KeyManager.kt b/WalletSdk/src/main/java/com/spruceid/wallet/sdk/KeyManager.kt index b9bc714..1f522c8 100644 --- a/WalletSdk/src/main/java/com/spruceid/wallet/sdk/KeyManager.kt +++ b/WalletSdk/src/main/java/com/spruceid/wallet/sdk/KeyManager.kt @@ -26,8 +26,7 @@ class KeyManager { * Returns the Android Keystore. * @return instance of the key store. */ - @VisibleForTesting - fun getKeyStore(): KeyStore { + private fun getKeyStore(): KeyStore { return KeyStore.getInstance("AndroidKeyStore").apply { load(null) } @@ -139,7 +138,7 @@ class KeyManager { * @property input byte array to be processed. * @return byte array with 32 bytes. */ - private fun clampOrFill(input: ByteArray): ByteArray { + fun clampOrFill(input: ByteArray): ByteArray { return if (input.size > 32) { input.drop(1).toByteArray() } else if (input.size < 32) { diff --git a/WalletSdk/src/test/java/com/spruceid/wallet/sdk/ExampleInstrumentedTest.kt b/WalletSdk/src/test/java/com/spruceid/wallet/sdk/ExampleInstrumentedTest.kt index 657235d..a803d5e 100644 --- a/WalletSdk/src/test/java/com/spruceid/wallet/sdk/ExampleInstrumentedTest.kt +++ b/WalletSdk/src/test/java/com/spruceid/wallet/sdk/ExampleInstrumentedTest.kt @@ -1,7 +1,7 @@ package com.spruceid.wallet.sdk import androidx.test.InstrumentationRegistry -import androidx.test.runner.AndroidJUnit4 +import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith diff --git a/WalletSdk/src/test/java/com/spruceid/wallet/sdk/KeyManagerTest.kt b/WalletSdk/src/test/java/com/spruceid/wallet/sdk/KeyManagerTest.kt index 4fcac2c..c9e443c 100644 --- a/WalletSdk/src/test/java/com/spruceid/wallet/sdk/KeyManagerTest.kt +++ b/WalletSdk/src/test/java/com/spruceid/wallet/sdk/KeyManagerTest.kt @@ -1,61 +1,38 @@ package com.spruceid.wallet.sdk -import org.junit.Assert import org.junit.Test import org.junit.Assert.* -import org.junit.runner.RunWith - -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ -//@RunWith(RobolectricTestRunner::class) -//@Config(sdk = [30]) class KeyManagerTest { @Test - fun getKeyStore() { + fun clampOrFill() { val keyManager = KeyManager() - val keyStore = keyManager.getKeyStore() - - assertNotNull(keyStore) - } - - @Test - fun reset() { - Assert.assertEquals(4, 2 + 2) - } - @Test - fun generateSigningKey() { - } - - @Test - fun getJwk() { - } + // Greater than 32 + val inputMoreThan = ByteArray(33) { it.toByte() } + val expectedMoreThan = inputMoreThan.drop(1).toByteArray() + val resultMoreThan = keyManager.clampOrFill(inputMoreThan) - @Test - fun keyExists() { - } + assertArrayEquals(expectedMoreThan, resultMoreThan) - @Test - fun signPayload() { - } + // Less than 32. + val inputLessThan = ByteArray(30) { it.toByte() } + val expectedLessThan = ByteArray(2) { 0.toByte() } + inputLessThan + val result = keyManager.clampOrFill(inputLessThan) - @Test - fun generateEncryptionKey() { - } + assertArrayEquals(expectedLessThan, result) - @Test - fun encryptPayload() { - } + // Equal to 32. + val inputEqualTo = ByteArray(32) { it.toByte() } + val resultEqualTo = keyManager.clampOrFill(inputEqualTo) - @Test - fun decryptPayload() { + assertArrayEquals(inputEqualTo, resultEqualTo) } }