Skip to content

Commit

Permalink
test: adds negative scenario for jwt cred offer
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <[email protected]>
  • Loading branch information
amagyar-iohk committed Nov 19, 2024
1 parent b0effec commit bae280e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common.errors

import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.CreateIssueCredentialRecordRequest
import java.util.UUID

enum class CredentialOfferError {
UNKNOWN_CONNECTION_ID {
override fun updateCredentialWithError(credentialOffer: CreateIssueCredentialRecordRequest): CreateIssueCredentialRecordRequest {
return 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
}
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 {
TYPE_AND_PROPERTIES_WITHOUT_SCHEMA_TYPE {
enum class SchemaTemplateError {
TYPE_AND_PROPERTIES_WITHOUT_SCHEMA_TYPEError {
override fun inner_schema(): String {
return """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import common.CredentialSchema
import common.DidPurpose
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
Expand Down Expand Up @@ -130,4 +131,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),
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -129,4 +133,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>("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),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@jwt @issuance
Feature: Issue JWT credential


Scenario: Issuing jwt credential with published PRISM DID
Given Issuer and Holder have an existing connection
And Issuer has a published DID for JWT
Expand Down Expand Up @@ -58,4 +57,14 @@ Feature: Issue JWT credential
And Holder accepts the credential offer invitation from Issuer
And Holder accepts jwt credential offer
And Issuer issues the credential
Then Holder receives the issued credential
Then Holder receives the issued credential

Scenario Outline: Issuing a credential with <issue> issuer should return <httpStatus>
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> issue
Then Issuer should see the status code was <httpStatus>
Examples:
| issue | httpStatus |
| UNKNOWN_CONNECTION_ID | 404 |

0 comments on commit bae280e

Please sign in to comment.