Skip to content

Commit f3e9478

Browse files
committed
test: Add ErrorTypeHandlerVs tests and amend docs
1 parent ebcaa0e commit f3e9478

3 files changed

Lines changed: 74 additions & 14 deletions

File tree

app/src/main/java/uk/gov/android/securestore/SecureStoreAsyncV2.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface SecureStoreAsyncV2 {
2626
* @param [key] The unique key to save the data against
2727
* @param [value] The data to save as a [String]
2828
*
29-
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to save
29+
* @throws [uk.gov.android.securestore.error.SecureStorageErrorV2] if unable to save
3030
*/
3131
suspend fun upsert(key: String, value: String): String
3232

@@ -41,15 +41,15 @@ interface SecureStoreAsyncV2 {
4141
/**
4242
* Delete everything in the SecureStore
4343
*
44-
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to delete
44+
* @throws [uk.gov.android.securestore.error.SecureStorageErrorV2] if unable to delete
4545
*/
4646
suspend fun deleteAll()
4747

4848
/**
4949
* Access the data for a given key when authentication is not required; access control level is set to OPEN
5050
*
5151
* @param [key] The unique key to identify data to retrieve
52-
* @return [RetrievalEvent] to cover success or failure
52+
* @return [RetrievalEventV2] to cover success or failure
5353
*
5454
*/
5555
suspend fun retrieve(
@@ -62,7 +62,7 @@ interface SecureStoreAsyncV2 {
6262
* @param [key] The unique key to identify data to retrieve
6363
* @param [authPromptConfig] Configuration for the Biometric prompt
6464
* @param [context] The [FragmentActivity] where the method is called, used for auth prompt
65-
* @return A [Flow] of [RetrievalEvent]s, allowing for multiple failed attempts for auth
65+
* @return A [Flow] of [RetrievalEventV2], allowing for multiple failed attempts for auth
6666
*
6767
*/
6868
suspend fun retrieveWithAuthentication(
@@ -77,7 +77,7 @@ interface SecureStoreAsyncV2 {
7777
* @param [key] Key to select
7878
* @return True or false if the key exists in the store
7979
*
80-
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to check for existence
80+
* @throws [uk.gov.android.securestore.error.SecureStorageErrorV2] if unable to check for existence
8181
*/
8282
fun exists(key: String): Boolean
8383
}

app/src/main/java/uk/gov/android/securestore/error/ErrorTypeHandlerV2.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ object ErrorTypeHandlerV2 {
3333
is IndexOutOfBoundsException,
3434
is GeneralSecurityException,
3535
-> SecureStoreErrorTypeV2.UNRECOVERABLE
36+
// This will always be RECOVERABLE because the SecureStorageErrorV2 type default to RECOVERABLE
3637
else -> error.type
3738
}
3839
}

app/src/test/java/uk/gov/android/securestore/error/ErrorTypeHandlerV2Test.kt

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,91 @@ import android.security.keystore.UserNotAuthenticatedException
44
import org.junit.jupiter.params.ParameterizedTest
55
import org.junit.jupiter.params.provider.Arguments
66
import org.junit.jupiter.params.provider.MethodSource
7-
import kotlin.UnsupportedOperationException
7+
import java.lang.IllegalStateException
8+
import java.lang.IndexOutOfBoundsException
9+
import java.security.GeneralSecurityException
10+
import java.security.InvalidAlgorithmParameterException
11+
import java.security.InvalidKeyException
12+
import java.security.KeyStoreException
13+
import java.security.NoSuchAlgorithmException
14+
import java.security.UnrecoverableKeyException
15+
import javax.crypto.AEADBadTagException
16+
import javax.crypto.BadPaddingException
17+
import javax.crypto.NoSuchPaddingException
818
import kotlin.test.assertEquals
919

1020
class ErrorTypeHandlerV2Test {
1121
@ParameterizedTest
1222
@MethodSource("getData")
13-
fun testHandler(error: SecureStorageError, expectedType: SecureStoreErrorType) {
14-
val actualType = ErrorTypeHandler.getErrorType(error)
23+
fun testHandler(error: SecureStorageErrorV2, expectedType: SecureStoreErrorTypeV2) {
24+
val actualType = ErrorTypeHandlerV2.getErrorType(error)
1525
assertEquals(expectedType, actualType)
1626
}
1727

1828
companion object {
29+
@Suppress("LongMethod")
1930
@JvmStatic
2031
fun getData(): List<Arguments> {
2132
return listOf(
2233
Arguments.of(
23-
SecureStorageError(UserNotAuthenticatedException()),
24-
SecureStoreErrorType.USER_CANCELED_BIO_PROMPT,
34+
SecureStorageErrorV2(AEADBadTagException()),
35+
SecureStoreErrorTypeV2.UNRECOVERABLE,
2536
),
2637
Arguments.of(
27-
SecureStorageError(UnsupportedOperationException()),
28-
SecureStoreErrorType.USER_CANCELED_BIO_PROMPT,
38+
SecureStorageErrorV2(UnrecoverableKeyException()),
39+
SecureStoreErrorTypeV2.UNRECOVERABLE,
2940
),
3041
Arguments.of(
31-
SecureStorageError(Exception()),
32-
SecureStoreErrorType.GENERAL,
42+
SecureStorageErrorV2(BadPaddingException()),
43+
SecureStoreErrorTypeV2.UNRECOVERABLE,
44+
),
45+
Arguments.of(
46+
SecureStorageErrorV2(UserNotAuthenticatedException()),
47+
SecureStoreErrorTypeV2.UNRECOVERABLE,
48+
),
49+
Arguments.of(
50+
SecureStorageErrorV2(NoSuchAlgorithmException()),
51+
SecureStoreErrorTypeV2.UNRECOVERABLE,
52+
),
53+
Arguments.of(
54+
SecureStorageErrorV2(NoSuchPaddingException()),
55+
SecureStoreErrorTypeV2.UNRECOVERABLE,
56+
),
57+
Arguments.of(
58+
SecureStorageErrorV2(java.lang.UnsupportedOperationException()),
59+
SecureStoreErrorTypeV2.UNRECOVERABLE,
60+
),
61+
Arguments.of(
62+
SecureStorageErrorV2(InvalidKeyException()),
63+
SecureStoreErrorTypeV2.UNRECOVERABLE,
64+
),
65+
Arguments.of(
66+
SecureStorageErrorV2(UnrecoverableKeyException()),
67+
SecureStoreErrorTypeV2.UNRECOVERABLE,
68+
),
69+
Arguments.of(
70+
SecureStorageErrorV2(KeyStoreException()),
71+
SecureStoreErrorTypeV2.UNRECOVERABLE,
72+
),
73+
Arguments.of(
74+
SecureStorageErrorV2(IllegalStateException()),
75+
SecureStoreErrorTypeV2.UNRECOVERABLE,
76+
),
77+
Arguments.of(
78+
SecureStorageErrorV2(InvalidAlgorithmParameterException()),
79+
SecureStoreErrorTypeV2.UNRECOVERABLE,
80+
),
81+
Arguments.of(
82+
SecureStorageErrorV2(IndexOutOfBoundsException()),
83+
SecureStoreErrorTypeV2.UNRECOVERABLE,
84+
),
85+
Arguments.of(
86+
SecureStorageErrorV2(GeneralSecurityException()),
87+
SecureStoreErrorTypeV2.UNRECOVERABLE,
88+
),
89+
Arguments.of(
90+
SecureStorageErrorV2(Exception()),
91+
SecureStoreErrorTypeV2.RECOVERABLE,
3392
),
3493
)
3594
}

0 commit comments

Comments
 (0)