Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jszersze committed Jun 6, 2024
1 parent a31c60d commit 2999711
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
1 change: 1 addition & 0 deletions WalletSdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions WalletSdk/src/main/java/com/spruceid/wallet/sdk/KeyManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 15 additions & 38 deletions WalletSdk/src/test/java/com/spruceid/wallet/sdk/KeyManagerTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 2999711

Please sign in to comment.