Skip to content

Commit

Permalink
test: partial cases
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <[email protected]>

test: finalized tests and refactoring

Signed-off-by: Allain Magyar <[email protected]>

Revert "fix: use Kafka 'earliest' offset strategy to avoid missing messages"

This reverts commit 241abe8.

Revert "chore: reduce Kafka clients lib log verbosity"

This reverts commit 8935889.

style: apply linters automatic fixes (#1449)

Signed-off-by: Hyperledger Bot <[email protected]>
Co-authored-by: Hyperledger Bot <[email protected]>

test: removes unused code

Signed-off-by: Allain Magyar <[email protected]>

style: apply linters automatic fixes (#1456)

Signed-off-by: Hyperledger Bot <[email protected]>
Co-authored-by: Hyperledger Bot <[email protected]>
  • Loading branch information
amagyar-iohk and hyperledger-bot committed Nov 20, 2024
1 parent 7839b95 commit 8ae3698
Show file tree
Hide file tree
Showing 34 changed files with 358 additions and 323 deletions.
3 changes: 0 additions & 3 deletions cloud-agent/service/server/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<logger name="io.getquill" level="WARN">
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.apache.kafka.clients" level="WARN">
<appender-ref ref="STDOUT" />
</logger>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import zio.kafka.consumer.{
ConsumerSettings as ZKConsumerSettings,
Subscription as ZKSubscription
}
import zio.kafka.consumer.Consumer.{AutoOffsetStrategy, OffsetRetrieval}
import zio.kafka.producer.{Producer as ZKProducer, ProducerSettings as ZKProducerSettings}
import zio.kafka.serde.{Deserializer as ZKDeserializer, Serializer as ZKSerializer}

Expand Down Expand Up @@ -81,7 +80,7 @@ class ZKafkaConsumerImpl[K, V](
.withMaxPollInterval(maxPollInterval) // Should be max.poll.records x 'max processing time per record'
// 'pollTimeout' default is 50 millis. This is a ZIO Kafka property.
.withPollTimeout(pollTimeout)
.withOffsetRetrieval(OffsetRetrieval.Auto(AutoOffsetStrategy.Earliest))
// .withOffsetRetrieval(OffsetRetrieval.Auto(AutoOffsetStrategy.Earliest))
.withRebalanceSafeCommits(rebalanceSafeCommits)
// .withMaxRebalanceDuration(30.seconds)
)
Expand Down
83 changes: 40 additions & 43 deletions tests/integration-tests/src/test/kotlin/abilities/ListenToEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@ package abilities
import com.google.gson.GsonBuilder
import common.TestConstants
import io.iohk.atala.automation.restassured.CustomGsonObjectMapperFactory
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import models.*
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.engine.ApplicationEngine
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.request.receiveText
import io.ktor.server.response.respond
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import models.ConnectionEvent
import models.CredentialEvent
import models.DidEvent
import models.Event
import models.PresentationEvent
import models.PresentationStatusAdapter
import net.serenitybdd.screenplay.Ability
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.HasTeardown
import net.serenitybdd.screenplay.Question
import org.hyperledger.identus.client.models.*
import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.IssueCredentialRecord
import java.net.URL
import java.time.OffsetDateTime

open class ListenToEvents(
private val url: URL,
webhookPort: Int?,
) : Ability, HasTeardown {
) : Ability,
HasTeardown {

private val server: ApplicationEngine
private val gson = GsonBuilder()
Expand Down Expand Up @@ -88,48 +99,36 @@ open class ListenToEvents(
}

companion object {
fun at(url: URL, webhookPort: Int?): ListenToEvents {
return ListenToEvents(url, webhookPort)
}
fun at(url: URL, webhookPort: Int?): ListenToEvents = ListenToEvents(url, webhookPort)

fun with(actor: Actor): ListenToEvents {
return actor.abilityTo(ListenToEvents::class.java)
}
fun with(actor: Actor): ListenToEvents = actor.abilityTo(ListenToEvents::class.java)

fun presentationProofStatus(actor: Actor): Question<PresentationStatusAdapter.Status?> {
return Question.about("presentation status").answeredBy {
val proofEvent = with(actor).presentationEvents.lastOrNull {
it.data.thid == actor.recall<String>("thid")
}
proofEvent?.data?.status
fun presentationProofStatus(actor: Actor): Question<PresentationStatusAdapter.Status?> = Question.about("presentation status").answeredBy {
val proofEvent = with(actor).presentationEvents.lastOrNull {
it.data.thid == actor.recall<String>("thid")
}
proofEvent?.data?.status
}

fun connectionState(actor: Actor): Question<Connection.State?> {
return Question.about("connection state").answeredBy {
val lastEvent = with(actor).connectionEvents.lastOrNull {
it.data.thid == actor.recall<Connection>("connection").thid
}
lastEvent?.data?.state
fun connectionState(actor: Actor): Question<Connection.State?> = Question.about("connection state").answeredBy {
val lastEvent = with(actor).connectionEvents.lastOrNull {
it.data.thid == actor.recall<Connection>("connection").thid
}
lastEvent?.data?.state
}

fun credentialState(actor: Actor): Question<IssueCredentialRecord.ProtocolState?> {
return Question.about("credential state").answeredBy {
val credentialEvent = ListenToEvents.with(actor).credentialEvents.lastOrNull {
it.data.thid == actor.recall<String>("thid")
}
credentialEvent?.data?.protocolState
fun credentialState(actor: Actor): Question<IssueCredentialRecord.ProtocolState?> = Question.about("credential state").answeredBy {
val credentialEvent = ListenToEvents.with(actor).credentialEvents.lastOrNull {
it.data.thid == actor.recall<String>("thid")
}
credentialEvent?.data?.protocolState
}

fun didStatus(actor: Actor): Question<String> {
return Question.about("did status").answeredBy {
val didEvent = ListenToEvents.with(actor).didEvents.lastOrNull {
it.data.did == actor.recall<String>("shortFormDid")
}
didEvent?.data?.status
fun didStatus(actor: Actor): Question<String> = Question.about("did status").answeredBy {
val didEvent = ListenToEvents.with(actor).didEvents.lastOrNull {
it.data.did == actor.recall<String>("shortFormDid")
}
didEvent?.data?.status
}
}

Expand All @@ -143,9 +142,7 @@ open class ListenToEvents(
.start(wait = false)
}

override fun toString(): String {
return "Listen HTTP port at $url"
}
override fun toString(): String = "Listen HTTP port at $url"

override fun tearDown() {
server.stop()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package common

import org.hyperledger.identus.client.models.ManagedDIDKeyTemplate
import org.hyperledger.identus.client.models.Service

data class DidDocumentTemplate(
val publicKeys: MutableList<ManagedDIDKeyTemplate>,
val services: MutableList<Service>,
)
41 changes: 0 additions & 41 deletions tests/integration-tests/src/test/kotlin/common/DidPurpose.kt

This file was deleted.

50 changes: 50 additions & 0 deletions tests/integration-tests/src/test/kotlin/common/DidType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package common

import org.hyperledger.identus.client.models.*

enum class DidType {
CUSTOM {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(),
services = mutableListOf(),
)
},
SD_JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.ED25519),
),
services = mutableListOf(),
)
},
JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.SECP256K1),
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.SECP256K1),
ManagedDIDKeyTemplate("assertion-2", Purpose.ASSERTION_METHOD, Curve.ED25519),
),
services = mutableListOf(),
)
},
OIDC_JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.SECP256K1),
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.SECP256K1),
),
services = mutableListOf(),
)
},
ANONCRED {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(),
services = mutableListOf(),
)
}, ;

abstract val documentTemplate: DidDocumentTemplate
}
38 changes: 17 additions & 21 deletions tests/integration-tests/src/test/kotlin/steps/common/CommonSteps.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package steps.common

import common.CredentialSchema
import common.DidPurpose
import common.DidType
import interactions.Get
import io.cucumber.java.en.Given
import io.iohk.atala.automation.extensions.get
Expand All @@ -13,39 +13,39 @@ import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.ConnectionsPage
import steps.connection.ConnectionSteps
import steps.credentials.*
import steps.did.PublishDidSteps
import steps.did.CreateDidSteps
import steps.schemas.CredentialSchemasSteps

class CommonSteps {
@Given("{actor} has a jwt issued credential from {actor}")
fun holderHasIssuedJwtCredentialFromIssuer(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.JWT)

val jwtCredentialSteps = JwtCredentialSteps()
val credentialSteps = CredentialSteps()

jwtCredentialSteps.issuerOffersAJwtCredential(issuer, holder, "short")
credentialSteps.holderReceivesCredentialOffer(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder, "auth-1")
credentialSteps.issuerIssuesTheCredential(issuer)
credentialSteps.holderReceivesTheIssuedCredential(holder)
}

@Given("{actor} has a jwt issued credential with {} schema from {actor}")
@Given("{actor} has a jwt issued credential with '{}' schema from {actor}")
fun holderHasIssuedJwtCredentialFromIssuerWithSchema(
holder: Actor,
schema: CredentialSchema,
issuer: Actor,
) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.JWT)

val schemaSteps = CredentialSchemasSteps()
schemaSteps.agentHasAPublishedSchema(issuer, schema)
Expand All @@ -54,7 +54,7 @@ class CommonSteps {
val credentialSteps = CredentialSteps()
jwtCredentialSteps.issuerOffersJwtCredentialToHolderUsingSchema(issuer, holder, "short", schema)
credentialSteps.holderReceivesCredentialOffer(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder, "auth-1")
credentialSteps.issuerIssuesTheCredential(issuer)
credentialSteps.holderReceivesTheIssuedCredential(holder)
}
Expand All @@ -63,9 +63,9 @@ class CommonSteps {
fun holderHasIssuedSdJwtCredentialFromIssuer(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.SD_JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.SD_JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.SD_JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.SD_JWT)

val sdJwtCredentialSteps = SdJwtCredentialSteps()
val credentialSteps = CredentialSteps()
Expand All @@ -80,9 +80,9 @@ class CommonSteps {
fun holderHasIssuedSdJwtCredentialFromIssuerWithKeyBind(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.SD_JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.SD_JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.SD_JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.SD_JWT)

val sdJwtCredentialSteps = SdJwtCredentialSteps()
val credentialSteps = CredentialSteps()
Expand All @@ -97,8 +97,6 @@ class CommonSteps {
fun actorsHaveExistingConnection(inviter: Actor, invitee: Actor) {
inviter.attemptsTo(
Get.resource("/connections"),
)
inviter.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK),
)
val inviterConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
Expand All @@ -109,8 +107,6 @@ class CommonSteps {
if (inviterConnection != null) {
invitee.attemptsTo(
Get.resource("/connections"),
)
invitee.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK),
)
inviteeConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
Expand Down
Loading

0 comments on commit 8ae3698

Please sign in to comment.