Skip to content

Commit

Permalink
Fix #3: Discovery service, param has to contain the whole url
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Mar 26, 2024
1 parent c6be1d8 commit 2aabc9a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 2aabc9a

Please sign in to comment.