diff --git a/tests/integration-tests/src/test/kotlin/common/errors/CredentialOfferError.kt b/tests/integration-tests/src/test/kotlin/common/errors/CredentialOfferError.kt new file mode 100644 index 0000000000..0dbd8e6d42 --- /dev/null +++ b/tests/integration-tests/src/test/kotlin/common/errors/CredentialOfferError.kt @@ -0,0 +1,21 @@ +package common.errors + +import org.hyperledger.identus.client.models.CreateIssueCredentialRecordRequest +import java.util.UUID + +enum class CredentialOfferError { + UNKNOWN_CONNECTION_ID { + override fun updateCredentialWithError(credentialOffer: CreateIssueCredentialRecordRequest): CreateIssueCredentialRecordRequest = CreateIssueCredentialRecordRequest( + schemaId = credentialOffer.schemaId, + claims = credentialOffer.claims, + issuingDID = credentialOffer.issuingDID, + issuingKid = credentialOffer.issuingKid, + connectionId = UUID.randomUUID(), + validityPeriod = credentialOffer.validityPeriod, + credentialFormat = credentialOffer.credentialFormat, + automaticIssuance = credentialOffer.automaticIssuance, + ) + }, ; + + abstract fun updateCredentialWithError(credentialOffer: CreateIssueCredentialRecordRequest): CreateIssueCredentialRecordRequest +} diff --git a/tests/integration-tests/src/test/kotlin/common/JwtCredentialProblem.kt b/tests/integration-tests/src/test/kotlin/common/errors/JwtCredentialError.kt similarity index 96% rename from tests/integration-tests/src/test/kotlin/common/JwtCredentialProblem.kt rename to tests/integration-tests/src/test/kotlin/common/errors/JwtCredentialError.kt index eb9435d881..d2c5699811 100644 --- a/tests/integration-tests/src/test/kotlin/common/JwtCredentialProblem.kt +++ b/tests/integration-tests/src/test/kotlin/common/errors/JwtCredentialError.kt @@ -1,12 +1,13 @@ -package common +package common.errors import com.nimbusds.jose.JWSAlgorithm import com.nimbusds.jose.jwk.Curve +import common.VerifiableJwt import models.JwtCredential import org.hyperledger.identus.client.models.VcVerification import java.time.OffsetDateTime -enum class JwtCredentialProblem { +enum class JwtCredentialError { ALGORITHM_VERIFICATION { override fun jwt(): String { val jwt = VerifiableJwt.jwtVCv1() @@ -104,7 +105,7 @@ enum class JwtCredentialProblem { // cases since it's not possible to inherit final class VcVerification.entries.forEach { try { - JwtCredentialProblem.valueOf(it.name) + JwtCredentialError.valueOf(it.name) } catch (e: IllegalArgumentException) { throw IllegalArgumentException("JwtCredentialProblem does not contain the new ${it.name} VcVerification case") } diff --git a/tests/integration-tests/src/test/kotlin/common/SchemaErrorTemplate.kt b/tests/integration-tests/src/test/kotlin/common/errors/SchemaTemplateError.kt similarity index 85% rename from tests/integration-tests/src/test/kotlin/common/SchemaErrorTemplate.kt rename to tests/integration-tests/src/test/kotlin/common/errors/SchemaTemplateError.kt index c76c614113..c75159952d 100644 --- a/tests/integration-tests/src/test/kotlin/common/SchemaErrorTemplate.kt +++ b/tests/integration-tests/src/test/kotlin/common/errors/SchemaTemplateError.kt @@ -1,14 +1,13 @@ -package common +package common.errors import com.google.gson.Gson import com.google.gson.JsonObject import common.CredentialSchema.STUDENT_SCHEMA import net.serenitybdd.screenplay.Actor -enum class SchemaErrorTemplate { +enum class SchemaTemplateError { TYPE_AND_PROPERTIES_WITHOUT_SCHEMA_TYPE { - override fun inner_schema(): String { - return """ + override fun inner_schema(): String = """ { "type": "object", "properties": { @@ -21,12 +20,10 @@ enum class SchemaErrorTemplate { }, "required": ["name"] } - """.trimIndent() - } + """.trimIndent() }, CUSTOM_WORDS_NOT_DEFINED { - override fun inner_schema(): String { - return """ + override fun inner_schema(): String = """ { "${"$"}schema": "http://json-schema.org/draft-2020-12/schema#", "type": "object", @@ -40,12 +37,10 @@ enum class SchemaErrorTemplate { }, "customKeyword": "value" } - """.trimIndent() - } + """.trimIndent() }, MISSING_REQUIRED_FOR_MANDATORY_PROPERTY { - override fun inner_schema(): String { - return """ + override fun inner_schema(): String = """ { "${"$"}schema": "http://json-schema.org/draft-2020-12/schema#", "type": "object", @@ -59,7 +54,6 @@ enum class SchemaErrorTemplate { } } """ - } }, ; abstract fun inner_schema(): String diff --git a/tests/integration-tests/src/test/kotlin/steps/common/CommonSteps.kt b/tests/integration-tests/src/test/kotlin/steps/common/CommonSteps.kt index 06aaab22bf..c2c8497315 100644 --- a/tests/integration-tests/src/test/kotlin/steps/common/CommonSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/common/CommonSteps.kt @@ -4,6 +4,7 @@ import common.CredentialSchema import common.DidType import interactions.Get import io.cucumber.java.en.Given +import io.cucumber.java.en.Then import io.iohk.atala.automation.extensions.get import io.iohk.atala.automation.serenity.ensure.Ensure import net.serenitybdd.rest.SerenityRest @@ -126,4 +127,11 @@ class CommonSteps { connectionSteps.inviterAndInviteeHaveAConnection(inviter, invitee) } } + + @Then("{actor} should see the status code was {int}") + fun actorShouldSeeHttpStatusWasExpected(actor: Actor, statusCode: Int) { + actor.attemptsTo( + Ensure.thatTheLastResponse().statusCode().isEqualTo(statusCode), + ) + } } diff --git a/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt b/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt index 551662d448..6f14a907f2 100644 --- a/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt @@ -1,6 +1,7 @@ package steps.credentials import common.CredentialSchema +import common.errors.CredentialOfferError import interactions.Post import interactions.body import io.cucumber.java.en.When @@ -10,7 +11,10 @@ import net.serenitybdd.rest.SerenityRest import net.serenitybdd.screenplay.Actor import org.apache.http.HttpStatus.SC_CREATED import org.apache.http.HttpStatus.SC_OK -import org.hyperledger.identus.client.models.* +import org.hyperledger.identus.client.models.AcceptCredentialOfferRequest +import org.hyperledger.identus.client.models.Connection +import org.hyperledger.identus.client.models.CreateIssueCredentialRecordRequest +import org.hyperledger.identus.client.models.IssueCredentialRecord class JwtCredentialSteps { @@ -120,4 +124,30 @@ class JwtCredentialSteps { Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), ) } + + @When("{actor} offers a jwt credential to {actor} with {} issue") + fun issuerIssuesTheJwtCredentialWithIssue( + issuer: Actor, + holder: Actor, + credentialOfferError: CredentialOfferError, + ) { + val credentialOfferRequest = CreateIssueCredentialRecordRequest( + claims = linkedMapOf( + "name" to "Name", + "surname" to "Surname", + ), + issuingDID = issuer.recall("shortFormDid"), + issuingKid = "assertion-1", + connectionId = issuer.recall("connection-with-${holder.name}").connectionId, + validityPeriod = 3600.0, + credentialFormat = "JWT", + automaticIssuance = false, + ) + + val credentialOfferRequestError = credentialOfferError.updateCredentialWithError(credentialOfferRequest) + + issuer.attemptsTo( + Post.to("/issue-credentials/credential-offers").body(credentialOfferRequestError), + ) + } } diff --git a/tests/integration-tests/src/test/kotlin/steps/schemas/CredentialSchemasSteps.kt b/tests/integration-tests/src/test/kotlin/steps/schemas/CredentialSchemasSteps.kt index 37511cd35f..0faa465b47 100644 --- a/tests/integration-tests/src/test/kotlin/steps/schemas/CredentialSchemasSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/schemas/CredentialSchemasSteps.kt @@ -2,6 +2,7 @@ package steps.schemas import common.* import common.CredentialSchema.STUDENT_SCHEMA +import common.errors.SchemaTemplateError import interactions.* import io.cucumber.java.en.* import io.iohk.atala.automation.extensions.get @@ -35,7 +36,7 @@ class CredentialSchemasSteps { } @When("{actor} creates a schema containing '{}' issue") - fun agentCreatesASchemaContainingIssue(actor: Actor, schema: SchemaErrorTemplate) { + fun agentCreatesASchemaContainingIssue(actor: Actor, schema: SchemaTemplateError) { actor.attemptsTo(Post.to("/schema-registry/schemas").body(schema.schema(actor))) } diff --git a/tests/integration-tests/src/test/kotlin/steps/verification/VcVerificationSteps.kt b/tests/integration-tests/src/test/kotlin/steps/verification/VcVerificationSteps.kt index 174aed265d..b6647b1ba5 100644 --- a/tests/integration-tests/src/test/kotlin/steps/verification/VcVerificationSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/verification/VcVerificationSteps.kt @@ -3,6 +3,7 @@ package steps.verification import com.nimbusds.jose.JWSAlgorithm import com.nimbusds.jose.jwk.Curve import common.* +import common.errors.JwtCredentialError import interactions.Post import interactions.body import io.cucumber.datatable.DataTable @@ -48,7 +49,7 @@ class VcVerificationSteps { } @Given("{actor} has a '{}' problem in the Verifiable Credential") - fun holderHasProblemInTheVerifiableCredential(holder: Actor, problem: JwtCredentialProblem) { + fun holderHasProblemInTheVerifiableCredential(holder: Actor, problem: JwtCredentialError) { val jwt = problem.jwt() holder.remember("jwt", jwt) holder.remember("issuerDid", "did:prism:issuer") @@ -65,7 +66,7 @@ class VcVerificationSteps { } @Then("{actor} should see that verification has failed with '{}' problem") - fun holderShouldSeeThatVerificationHasFailedWithProblem(holder: Actor, problem: JwtCredentialProblem) { + fun holderShouldSeeThatVerificationHasFailedWithProblem(holder: Actor, problem: JwtCredentialError) { } @Then("{actor} should see that all checks have passed") diff --git a/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature b/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature index 5e15b98f8f..3c39d18f29 100644 --- a/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature +++ b/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature @@ -13,12 +13,6 @@ Feature: Issue JWT credential And Holder accepts jwt credential offer using 'auth-1' key id And Issuer issues the credential Then Holder receives the issued credential - When Issuer revokes the credential issued to Holder - Then Issuer should see the credential was revoked - When Issuer sends a request for jwt proof presentation to Holder - And Holder receives the presentation proof request - And Holder makes the jwt presentation of the proof - Then Issuer sees the proof returned verification failed Examples: | assertionMethod | assertionName | | secp256k1 | assert-1 | @@ -71,3 +65,13 @@ Feature: Issue JWT credential And Holder accepts jwt credential offer using 'auth-1' key id And Issuer issues the credential Then Holder receives the issued credential + + Scenario Outline: Issuing a credential with issuer should return + Given Issuer and Holder have an existing connection + And Issuer has a published DID for 'JWT' + And Holder has an unpublished DID for 'JWT' + When Issuer offers a jwt credential to Holder with issue + Then Issuer should see the status code was + Examples: + | issue | httpStatus | + | UNKNOWN_CONNECTION_ID | 404 |