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

test: adds negative scenario outline for jwt credential offer #1454

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
}
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,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": {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -59,7 +54,6 @@ enum class SchemaErrorTemplate {
}
}
"""
}
}, ;

abstract fun inner_schema(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
}
}
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 @@ -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>("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
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 <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 |
Loading