Skip to content

Commit

Permalink
Merge pull request #289 from walt-id/fix-policy-result-serialization-etc
Browse files Browse the repository at this point in the history
fix verification policy result serialization
  • Loading branch information
severinstampler authored Apr 18, 2023
2 parents 520e4c9 + 308ddb6 commit 0a77a28
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
17 changes: 8 additions & 9 deletions src/main/kotlin/id/walt/auditor/VerificationPolicy.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package id.walt.auditor

import com.beust.klaxon.Json
import com.fasterxml.jackson.annotation.JsonIgnore
import id.walt.credentials.w3c.VerifiableCredential
import id.walt.credentials.w3c.VerifiablePresentation
Expand Down Expand Up @@ -57,9 +58,9 @@ data class VerificationPolicyMetadata(
)

class VerificationPolicyResult private constructor(
private val result: Boolean,
@JsonIgnore
private val errorList: List<Throwable> = emptyList()
val isSuccess: Boolean,
@JsonIgnore @Json(ignored = true)
val errors: List<Throwable> = emptyList()
) {

companion object {
Expand All @@ -70,17 +71,15 @@ class VerificationPolicyResult private constructor(
}
}

val isSuccess = result
val isFailure = !result
@JsonIgnore
val errors = errorList
@JsonIgnore @Json(ignored = true)
val isFailure = !isSuccess

private fun getErrorString() = errorList.mapIndexed { index, throwable ->
private fun getErrorString() = errors.mapIndexed { index, throwable ->
"#${index + 1}: ${throwable::class.simpleName ?: "Error"} - ${throwable.message}"
}.joinToString()

override fun toString(): String {
return when (result) {
return when (isSuccess) {
true -> "passed"
false -> "failed: ${getErrorString()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class EbsiTrustedIssuerRegistryPolicy(registryArg: EbsiTrustedIssuerRegistryPoli
constructor() : this(
EbsiTrustedIssuerRegistryPolicyArg(
"${TrustedIssuerClient.domain}/${TrustedIssuerClient.trustedIssuerPath}",
TrustedIssuerType.Undefined
TrustedIssuerType.TI
)
)

Expand Down
15 changes: 15 additions & 0 deletions src/test/kotlin/id/walt/auditor/AuditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,20 @@ class AuditorCommandTest : StringSpec() {
unmockkObject(TrustedIssuerClient)
}
}

"12. test serialize verification result" {
val verificationResult = VerificationResult(true, mapOf(
"SignaturePolicy" to VerificationPolicyResult.success()
))

val serializedResult = KlaxonWithConverters().toJsonString(verificationResult)

val deserializedResult = KlaxonWithConverters().parse<VerificationResult>(serializedResult)

verificationResult.result shouldBe deserializedResult!!.result
verificationResult.policyResults.forEach {
deserializedResult.policyResults[it.key]?.isSuccess shouldBe it.value.isSuccess
}
}
}
}
4 changes: 2 additions & 2 deletions src/test/kotlin/id/walt/auditor/PolicyFactoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import org.junit.jupiter.api.Assertions.assertAll

class PolicyFactoryTest : AnnotationSpec() {

private val testArgument = EbsiTrustedIssuerRegistryPolicyArg("testArg", TrustedIssuerType.Undefined)
private val testArgument = EbsiTrustedIssuerRegistryPolicyArg("testArg", TrustedIssuerType.TI)
private val wrongArg = AnotherArg("Else")
private val defaultArg = EbsiTrustedIssuerRegistryPolicyArg(
"${TrustedIssuerClient.domain}/${TrustedIssuerClient.trustedIssuerPath}",
TrustedIssuerType.Undefined
TrustedIssuerType.TI
)

@Test
Expand Down

0 comments on commit 0a77a28

Please sign in to comment.