From 2aabc9ad1333049a2dcb4803ef0e408e1acebd46 Mon Sep 17 00:00:00 2001 From: milan Date: Tue, 26 Mar 2024 08:10:04 +0530 Subject: [PATCH] Fix #3: Discovery service, param has to contain the whole url --- .../eudiwalletoidcandroid/MainViewModel.kt | 4 +- .../services/discovery/DiscoveryService.kt | 26 ++++++------- .../DiscoveryServiceTest.kt | 38 +++++++++++++++++++ 3 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 eudi-wallet-oidc-android/src/test/java/com/ewc/eudi_wallet_oidc_android/DiscoveryServiceTest.kt diff --git a/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt b/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt index f93d9da..7506175 100644 --- a/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt +++ b/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt @@ -54,11 +54,11 @@ class MainViewModel : ViewModel() { // Discovery issuerConfig = - DiscoveryService().getIssuerConfig(offerCredential?.credentialIssuer) + DiscoveryService().getIssuerConfig("${offerCredential?.credentialIssuer}/.well-known/openid-credential-issuer") authConfig = DiscoveryService().getAuthConfig( - issuerConfig?.authorizationServer ?: issuerConfig?.issuer + "${issuerConfig?.authorizationServer ?: issuerConfig?.issuer}/.well-known/openid-configuration" ) // Generating code verifier diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/discovery/DiscoveryService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/discovery/DiscoveryService.kt index d9bc61c..5eed5fc 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/discovery/DiscoveryService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/discovery/DiscoveryService.kt @@ -19,7 +19,7 @@ class DiscoveryService : DiscoveryServiceInterface { UrlUtils.validateUri(credentialIssuerWellKnownURI) val response = ApiManager.api.getService() - ?.fetchIssuerConfig("$credentialIssuerWellKnownURI/.well-known/openid-credential-issuer") + ?.fetchIssuerConfig("$credentialIssuerWellKnownURI") return if (response?.isSuccessful == true) { response.body() } else { @@ -37,19 +37,19 @@ class DiscoveryService : DiscoveryServiceInterface { * @return AuthorisationServerWellKnownConfiguration */ override suspend fun getAuthConfig(authorisationServerWellKnownURI: String?): AuthorisationServerWellKnownConfiguration? { - if (authorisationServerWellKnownURI.isNullOrBlank() || !UrlUtils.isValidUrl( - authorisationServerWellKnownURI ?: "" - ) - ) - return null + try { + UrlUtils.validateUri(authorisationServerWellKnownURI) - val response = - ApiManager.api.getService() - ?.fetchAuthConfig("$authorisationServerWellKnownURI/.well-known/openid-configuration") - return if (response?.isSuccessful == true) { - response.body() - } else { - null + val response = + ApiManager.api.getService() + ?.fetchAuthConfig("$authorisationServerWellKnownURI") + return if (response?.isSuccessful == true) { + response.body() + } else { + null + } + } catch (exc: UriValidationFailed) { + return null } } } \ No newline at end of file diff --git a/eudi-wallet-oidc-android/src/test/java/com/ewc/eudi_wallet_oidc_android/DiscoveryServiceTest.kt b/eudi-wallet-oidc-android/src/test/java/com/ewc/eudi_wallet_oidc_android/DiscoveryServiceTest.kt new file mode 100644 index 0000000..1166832 --- /dev/null +++ b/eudi-wallet-oidc-android/src/test/java/com/ewc/eudi_wallet_oidc_android/DiscoveryServiceTest.kt @@ -0,0 +1,38 @@ +package com.ewc.eudi_wallet_oidc_android + +import com.ewc.eudi_wallet_oidc_android.services.UriValidationFailed +import com.ewc.eudi_wallet_oidc_android.services.UrlUtils +import com.ewc.eudi_wallet_oidc_android.services.discovery.DiscoveryService +import com.ewc.eudi_wallet_oidc_android.services.issue.IssueService +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Test + +class DiscoveryServiceTest { + + private val discoveryService = DiscoveryService() + + @Test + fun issuerConfigUrlIsNull() { + val result = runBlocking { discoveryService.getIssuerConfig(null)} + Assert.assertNull(result) + } + + @Test + fun issuerConfigUrlIsNotValid() { + val result = runBlocking { discoveryService.getIssuerConfig("://abc")} + Assert.assertNull(result) + } + + @Test + fun authConfigUrlIsNull() { + val result = runBlocking { discoveryService.getAuthConfig(null)} + Assert.assertNull(result) + } + + @Test + fun authConfigUrlIsNotValid() { + val result = runBlocking { discoveryService.getAuthConfig("://abc")} + Assert.assertNull(result) + } +} \ No newline at end of file