Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run and report tests on push #17

Merged
merged 14 commits into from
Sep 22, 2023
2 changes: 1 addition & 1 deletion .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build iOS Framework
on: [push]
on: workflow_dispatch
jobs:
build:
runs-on: macos-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-jvm.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build JVM artifacts
on: [push]
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/test-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test iOS implementation
on: [push]
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Build klibs
run: ./gradlew iosArm64MainKlibrary iosX64MainKlibrary
- name: Run tests
run: ./gradlew iosX64Test
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: vclib Tests
path: vclib/build/test-results/**/TEST*.xml,vclib-aries/build/test-results/**/TEST*.xml,vclib-openid/build/test-results/**/TEST*.xml
reporter: java-junit
23 changes: 23 additions & 0 deletions .github/workflows/test-jvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test JVM implementation
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Run tests
run: ./gradlew jvmTest
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: vclib Tests
path: vclib/build/test-results/**/TEST*.xml,vclib-aries/build/test-results/**/TEST*.xml,vclib-openid/build/test-results/**/TEST*.xml
reporter: java-junit
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package at.asitplus.wallet.lib.msg

import at.asitplus.wallet.lib.aries.jsonSerializer
import at.asitplus.wallet.lib.data.Base64Strict
import com.benasher44.uuid.uuid4
import io.github.aakira.napier.Napier
import io.matthewnelson.component.base64.decodeBase64ToArray
import io.matthewnelson.component.base64.encodeBase64
import io.matthewnelson.encoding.base64.Base64
import io.matthewnelson.encoding.core.Decoder.Companion.decodeToByteArrayOrNull
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString

/**
Expand All @@ -33,7 +30,7 @@ data class JwmAttachment(

fun decodeString(): String? {
if (data.base64 != null)
return data.base64.decodeToByteArrayOrNull(Base64())?.decodeToString()
return data.base64.decodeToByteArrayOrNull(Base64Strict)?.decodeToString()
if (data.jws != null)
return data.jws
return null
Expand All @@ -42,7 +39,7 @@ data class JwmAttachment(

fun decodeBinary(): ByteArray? {
if (data.base64 != null)
return data.base64.decodeToByteArrayOrNull(Base64())
return data.base64.decodeToByteArrayOrNull(Base64Strict)
return null
.also { Napier.w("Could not binary decode JWM attachment") }
}
Expand All @@ -60,15 +57,15 @@ data class JwmAttachment(
id = uuid4().toString(),
mediaType = "application/base64",
data = JwmAttachmentData(
base64 = data.encodeToByteArray().encodeToString(Base64())
base64 = data.encodeToByteArray().encodeToString(Base64Strict)
)
)

fun encodeBase64(data: ByteArray) = JwmAttachment(
id = uuid4().toString(),
mediaType = "application/base64",
data = JwmAttachmentData(
base64 = data.encodeToString(Base64())
base64 = data.encodeToString(Base64Strict)
)
)

Expand All @@ -78,7 +75,7 @@ data class JwmAttachment(
filename = filename,
parent = parent,
data = JwmAttachmentData(
base64 = data.encodeToString(Base64())
base64 = data.encodeToString(Base64Strict)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import at.asitplus.wallet.lib.agent.IssuerCredentialDataProvider
import at.asitplus.wallet.lib.cbor.CoseKey
import at.asitplus.wallet.lib.data.AtomicAttribute2023
import at.asitplus.wallet.lib.data.ConstantIndex
import io.matthewnelson.component.encoding.base16.encodeBase16
import io.matthewnelson.encoding.base16.Base16
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.datetime.Clock
import kotlin.random.Random
import kotlin.time.Duration.Companion.minutes
Expand Down Expand Up @@ -60,7 +61,7 @@ class DummyCredentialDataProvider(
)
}

private fun randomValue() = Random.nextBytes(32).encodeBase16()
private fun randomValue() = Random.nextBytes(32).encodeToString(Base16(strict = true))

}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProblemReporterTest : FreeSpec({
val problemReporter = ProblemReporter()

"sorter" - {
withData(ProblemReportSorter.values().asList()) {
withData(ProblemReportSorter.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = it,
Expand All @@ -36,7 +36,7 @@ class ProblemReporterTest : FreeSpec({
}

"scope" - {
withData(ProblemReportScope.values().asList()) {
withData(ProblemReportScope.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = ProblemReportSorter.WARNING,
Expand All @@ -57,7 +57,7 @@ class ProblemReporterTest : FreeSpec({
}

"descriptor" - {
withData(ProblemReportDescriptor.values().asList()) {
withData(ProblemReportDescriptor.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = ProblemReportSorter.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import io.github.aakira.napier.Napier
import io.ktor.http.URLBuilder
import io.ktor.http.Url
import io.ktor.util.flattenEntries
import io.matthewnelson.component.encoding.base16.encodeBase16
import io.matthewnelson.encoding.base16.Base16
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.datetime.Clock
Expand Down Expand Up @@ -292,7 +291,7 @@ class OidcSiopWallet(
AuthenticationResponseParameters(
idToken = signedIdToken,
state = params.state,
vpToken = vp.document.serialize().encodeToString(Base16()),
vpToken = vp.document.serialize().encodeToString(Base16(strict = true)),
presentationSubmission = presentationSubmission,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.asitplus.wallet.lib.agent.Issuer
import at.asitplus.wallet.lib.cbor.CoseEllipticCurve
import at.asitplus.wallet.lib.cbor.CoseKey
import at.asitplus.wallet.lib.cbor.CoseKeyType
import at.asitplus.wallet.lib.data.Base64UrlStrict
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.data.VcDataModelConstants.VERIFIABLE_CREDENTIAL
import at.asitplus.wallet.lib.iso.IsoDataModelConstants.DOC_TYPE_MDL
Expand All @@ -22,8 +23,7 @@ import at.asitplus.wallet.lib.oidc.OpenIdConstants.TOKEN_PREFIX_BEARER
import at.asitplus.wallet.lib.oidc.OpenIdConstants.TOKEN_TYPE_BEARER
import at.asitplus.wallet.lib.oidc.OpenIdConstants.URN_TYPE_JWK_THUMBPRINT
import at.asitplus.wallet.lib.oidvci.mdl.RequestedCredentialClaimSpecification
import io.ktor.http.*
import io.matthewnelson.encoding.base64.Base64
import io.ktor.http.URLBuilder
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlin.coroutines.cancellation.CancellationException

Expand Down Expand Up @@ -167,8 +167,7 @@ class IssuerService(
return when (val issuedCredential = issuedCredentialResult.successful.first()) {
is Issuer.IssuedCredential.Iso -> CredentialResponseParameters(
format = CredentialFormatEnum.MSO_MDOC,
credential = issuedCredential.issuerSigned.serialize()
.encodeToString(Base64 { encodeToUrlSafe = true; padEncoded = false })
credential = issuedCredential.issuerSigned.serialize().encodeToString(Base64UrlStrict)
)

is Issuer.IssuedCredential.Vc -> CredentialResponseParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import at.asitplus.wallet.lib.iso.DrivingPrivilege
import at.asitplus.wallet.lib.iso.ElementValue
import at.asitplus.wallet.lib.iso.IsoDataModelConstants.DataElements
import at.asitplus.wallet.lib.iso.IssuerSignedItem
import io.matthewnelson.component.encoding.base16.encodeBase16
import io.matthewnelson.encoding.base16.Base16
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDate
import kotlin.random.Random
Expand Down Expand Up @@ -91,7 +92,7 @@ class DummyCredentialDataProvider(
return KmmResult.success(listOfAttributes)
}

private fun randomValue() = Random.nextBytes(32).encodeBase16()
private fun randomValue() = Random.nextBytes(32).encodeToString(Base16(strict = true))

fun buildIssuerSignedItem(elementIdentifier: String, elementValue: String, digestId: UInt) = IssuerSignedItem(
digestId = digestId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.iso.IsoDataModelConstants
import com.benasher44.uuid.uuid4
import io.github.aakira.napier.DebugAntilog
import io.github.aakira.napier.Napier
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldBeSingleton
import io.kotest.matchers.collections.shouldHaveSingleElement
import io.kotest.matchers.collections.shouldMatchEach
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.types.shouldBeInstanceOf
import kotlinx.coroutines.runBlocking
Expand All @@ -34,6 +35,8 @@ class OidcSiopIsoProtocolTest : FreeSpec({
lateinit var verifierSiop: OidcSiopVerifier

beforeEach {
Napier.takeLogarithm()
Napier.base(DebugAntilog())
holderCryptoService = DefaultCryptoService()
verifierCryptoService = DefaultCryptoService()
relyingPartyUrl = "https://example.com/rp/${uuid4()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package at.asitplus.wallet.lib.oidc

import at.asitplus.wallet.lib.LibraryInitializer
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.AtomicAttribute2023
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.data.CredentialSubject
import at.asitplus.wallet.lib.oidvci.decodeFromPostBody
Expand Down Expand Up @@ -34,15 +35,6 @@ class OidcSiopProtocolTest : FreeSpec({
lateinit var holderSiop: OidcSiopWallet
lateinit var verifierSiop: OidcSiopVerifier

LibraryInitializer.registerExtensionLibrary(LibraryInitializer.ExtensionLibraryInfo(
credentialScheme = TestCredentialScheme,
serializersModule = kotlinx.serialization.modules.SerializersModule {
polymorphic(CredentialSubject::class) {
subclass(TestCredential::class)
}
}
))

beforeEach {
holderCryptoService = DefaultCryptoService()
verifierCryptoService = DefaultCryptoService()
Expand Down Expand Up @@ -165,16 +157,7 @@ class OidcSiopProtocolTest : FreeSpec({
verifier = verifierAgent,
cryptoService = verifierCryptoService,
relyingPartyUrl = relyingPartyUrl,
credentialScheme = TestCredentialScheme
)
holderAgent.storeCredentials(
IssuerAgent.newDefaultInstance(
DefaultCryptoService(),
dataProvider = TestCredentialDataProvider(),
).issueCredentialWithTypes(
holderAgent.identifier,
attributeTypes = listOf(TestCredentialScheme.vcType)
).toStoreCredentialInput()
credentialScheme = ConstantIndex.AtomicAttribute2023
)

val authnRequest = verifierSiop.createAuthnRequestUrl(walletUrl)
Expand All @@ -188,7 +171,7 @@ class OidcSiopProtocolTest : FreeSpec({
result.shouldBeInstanceOf<OidcSiopVerifier.AuthnResponseResult.Success>()
result.vp.verifiableCredentials.shouldNotBeEmpty()
result.vp.verifiableCredentials.forEach {
it.vc.credentialSubject.shouldBeInstanceOf<TestCredential>()
it.vc.credentialSubject.shouldBeInstanceOf<AtomicAttribute2023>()
}
}
})

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package at.asitplus.wallet.lib.agent
import at.asitplus.wallet.lib.data.CredentialSubject
import at.asitplus.wallet.lib.iso.IssuerSignedItem
import at.asitplus.wallet.lib.iso.sha256
import io.matthewnelson.component.encoding.base16.encodeBase16
import io.matthewnelson.encoding.base16.Base16
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.datetime.Instant
Expand Down Expand Up @@ -47,7 +46,7 @@ class InMemoryIssuerCredentialStore : IssuerCredentialStore {
val list = map.getOrPut(timePeriod) { mutableListOf() }
val newIndex = (list.maxOfOrNull { it.statusListIndex } ?: 0) + 1
list += Credential(
vcId = issuerSignedItemList.toString().encodeToByteArray().sha256().encodeToString(Base16()),
vcId = issuerSignedItemList.toString().encodeToByteArray().sha256().encodeToString(Base16(strict = true)),
statusListIndex = newIndex,
revoked = false,
expirationDate = expirationDate
Expand Down
Loading