Skip to content

Commit

Permalink
fix overriding ktorHttpClientFactory in EudiWallet object for openId4…
Browse files Browse the repository at this point in the history
…Vci and openId4Vp; fix don't delete deferred documents if deferred issuing fails
  • Loading branch information
vkanellopoulos committed Jul 15, 2024
1 parent 327c006 commit 873939d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ file.

```groovy
dependencies {
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.10.1-SNAPSHOT"
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.10.2-SNAPSHOT"
implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05"
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ androidJvm

## Functions

| Name | Summary |
|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [build](build.md) | [androidJvm]<br>fun [build](build.md)(): [OpenId4VciManager](../index.md)<br>Build the [OpenId4VciManager](../index.md) |
| [config](config.md) | [androidJvm]<br>fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)<br>Set the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)<br>Set the DocumentManager to use |
| [ktHttpClientFactory](kt-http-client-factory.md) | [androidJvm]<br>fun [ktHttpClientFactory](kt-http-client-factory.md)(factory: () -&gt; HttpClient): [OpenId4VciManager.Builder](index.md)<br>Override the Ktor HTTP client factory |
| [logger](logger.md) | [androidJvm]<br>fun [logger](logger.md)(logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md) |
| Name | Summary |
|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [build](build.md) | [androidJvm]<br>fun [build](build.md)(): [OpenId4VciManager](../index.md)<br>Build the [OpenId4VciManager](../index.md) |
| [config](config.md) | [androidJvm]<br>fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)<br>Set the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)<br>Set the DocumentManager to use |
| [ktorHttpClientFactory](ktor-http-client-factory.md) | [androidJvm]<br>fun [ktorHttpClientFactory](ktor-http-client-factory.md)(factory: () -&gt; HttpClient): [OpenId4VciManager.Builder](index.md)<br>Override the Ktor HTTP client factory |
| [logger](logger.md) | [androidJvm]<br>fun [logger](logger.md)(logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md) |

## Properties

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@

# ktorHttpClientFactory

[androidJvm]\
fun [ktorHttpClientFactory](ktor-http-client-factory.md)(factory: () -&gt;
HttpClient): [OpenId4VciManager.Builder](index.md)

Override the Ktor HTTP client factory

[androidJvm]\
var [ktorHttpClientFactory](ktor-http-client-factory.md): () -&gt; HttpClient?
2 changes: 1 addition & 1 deletion docs/wallet-core/package-list
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ $dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Buil
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/config/#eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Config/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/config.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/documentManager/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/document-manager.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/documentManager/#eu.europa.ec.eudi.wallet.document.DocumentManager/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/document-manager.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktHttpClientFactory/#kotlin.Function0[io.ktor.client.HttpClient]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/kt-http-client-factory.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktorHttpClientFactory/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/ktorHttpClientFactory/#kotlin.Function0[io.ktor.client.HttpClient]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/ktor-http-client-factory.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/logger/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/logger.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Builder/logger/#eu.europa.ec.eudi.wallet.logging.Logger/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-builder/logger.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Companion///PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-companion/index.md
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ systemProp.sonar.host.url=https://sonarcloud.io
systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml
systemProp.sonar.projectName=eudi-lib-android-wallet-core
VERSION_NAME=0.10.1-SNAPSHOT
VERSION_NAME=0.10.2-SNAPSHOT

SONATYPE_HOST=S01
SONATYPE_AUTOMATIC_RELEASE=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ object EudiWallet {
openId4VpConfig,
openId4VpCBORResponseGenerator,
).apply {
_config.ktorHttpClientFactory?.let { ktorHttpClientFactory = it }
logger = this@EudiWallet.logger
_config.trustedReaderCertificates?.let {
setReaderTrustStore(ReaderTrustStore.getDefault(it))
Expand Down Expand Up @@ -255,6 +256,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByDocType(docType, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
Expand Down Expand Up @@ -289,6 +291,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByOffer(offer, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
Expand Down Expand Up @@ -322,6 +325,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.issueDocumentByOfferUri(offerUri, txCode, executor, onEvent) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
Expand Down Expand Up @@ -351,6 +355,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also {
when (val document = documentManager.getDocumentById(documentId)) {
is DeferredDocument -> it.issueDeferredDocument(document, executor, onResult)
Expand Down Expand Up @@ -399,6 +404,7 @@ object EudiWallet {
documentManager(this@EudiWallet.documentManager)
config(config)
logger = this@EudiWallet.logger
ktorHttpClientFactory = _config.ktorHttpClientFactory
}.also { it.resolveDocumentOffer(offerUri, executor, onResult) }
} ?: run {
(executor ?: context.mainExecutor()).execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ interface OpenId4VciManager {
/**
* Override the Ktor HTTP client factory
*/
fun ktHttpClientFactory(factory: () -> HttpClient) = apply {
fun ktorHttpClientFactory(factory: () -> HttpClient) = apply {
this.ktorHttpClientFactory = factory
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ internal class ProcessDeferredOutcome(
try {
when (outcome) {
is DeferredCredentialQueryOutcome.Errored -> {
documentManager.deleteDocumentById(deferredDocument.id)
callback(
DeferredIssueResult.DocumentFailed(
deferredDocument.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@ import eu.europa.ec.eudi.wallet.transfer.openid4vp.ClientIdScheme
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionAlgorithm
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionMethod
import eu.europa.ec.eudi.wallet.transfer.openid4vp.PreregisteredVerifier
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.io.File
import java.security.cert.X509Certificate

class EudiWalletConfigTest {

private lateinit var context: Context

@Before
fun setUp() {
context = mock(Context::class.java)
`when`(context.applicationContext).thenReturn(context)
`when`(context.noBackupFilesDir).thenReturn(mock(File::class.java))
private val context: Context = mockk(relaxed = true) {
every { applicationContext } returns this@mockk
every { noBackupFilesDir } returns mockk()
}

@Test
fun testInvoke() {
val storageDir = File("/tmp")
val readerCertificate1 = mock(X509Certificate::class.java)
val readerCertificate2 = mock(X509Certificate::class.java)
val readerCertificate1 = mockk<X509Certificate>()
val readerCertificate2 = mockk<X509Certificate>()
val config = EudiWalletConfig(context) {
documentsStorageDir(storageDir)
userAuthenticationRequired(true)
Expand Down Expand Up @@ -114,38 +109,6 @@ class EudiWalletConfigTest {
assertEquals("eudi-openid4ci://authorize", config.openId4VciConfig?.authFlowRedirectionURI)
}

@Test
fun testBuilder() {
val builder = EudiWalletConfig.Builder(context)

builder.encryptDocumentsInStorage(false)
builder.useHardwareToStoreKeys(false)
builder.bleTransferMode(
EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE,
EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE
)
builder.bleClearCacheEnabled(true)
builder.userAuthenticationRequired(true)
builder.userAuthenticationTimeOut(30_000L)
builder.trustedReaderCertificates(listOf(mock(X509Certificate::class.java)))

val config = builder.build()

assertFalse(config.encryptDocumentsInStorage)
assertFalse(config.useHardwareToStoreKeys)
assertEquals(
EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE or EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE,
config.bleTransferMode
)
assertTrue(config.bleCentralClientModeEnabled)
assertTrue(config.blePeripheralServerModeEnabled)
assertTrue(config.bleClearCacheEnabled)
assertTrue(config.userAuthenticationRequired)
assertEquals(30_000L, config.userAuthenticationTimeOut)
assertEquals(1, config.trustedReaderCertificates?.size)

}

@Test
fun testDefaultValues() {
val config = EudiWalletConfig(context) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package eu.europa.ec.eudi.wallet.issue.openid4vci

import android.content.Context
import eu.europa.ec.eudi.wallet.document.DocumentManager
import io.ktor.client.*
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test


Expand Down Expand Up @@ -68,4 +68,19 @@ class OpenId4VciManagerBuilderTest {
builder.build()
}
}

@Test
fun `Builder sets the ktorClientFactory`() {
val ktorClientFactory: () -> HttpClient = mockk()
val builder = OpenId4VciManager.Builder(context)
.config(config)
.documentManager(documentManager)
.ktorHttpClientFactory(ktorClientFactory)

val manager = builder.build() as DefaultOpenId4VciManager

assertNotNull(manager)

assertSame(ktorClientFactory, manager.ktorHttpClientFactory)
}
}

0 comments on commit 873939d

Please sign in to comment.