diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala index ae852b5121..ea77c80792 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala @@ -13,7 +13,6 @@ import io.iohk.atala.pollux.core.service.URIDereferencer import zio.* import zio.json.* import zio.json.ast.Json -import zio.prelude.Validation import java.net.URI import java.time.{OffsetDateTime, ZoneOffset} @@ -125,17 +124,19 @@ object CredentialSchema { for { uri <- ZIO.attempt(new URI(schemaId)).mapError(t => URISyntaxError(t.getMessage)) content <- uriDereferencer.dereference(uri).mapError(err => UnexpectedError(err.toString)) - vcSchema <- parseCredentialSchema(content) - resolvedSchemaType <- resolveCredentialSchemaType(vcSchema.`type`) - _ <- - Validation - .fromPredicateWith( - CredentialSchemaParsingError( - s"Only ${CredentialJsonSchemaType.`type`} schema type can be used to verify claims" - ) - )(resolvedSchemaType.`type`)(`type` => `type` == CredentialJsonSchemaType.`type`) - .toZIO - schemaValidator <- JsonSchemaValidatorImpl.from(vcSchema.schema).mapError(SchemaError.apply) + json <- ZIO + .fromEither(content.fromJson[Json]) + .mapError(error => + CredentialSchemaError.CredentialSchemaParsingError(s"Failed to parse resolved schema content as Json: $error") + ) + schemaValidator <- JsonSchemaValidatorImpl + .from(json) + .orElse( + ZIO + .fromEither(json.as[CredentialSchema]) + .mapError(error => CredentialSchemaParsingError(s"Failed to parse schema content as Json or OEA: $error")) + .flatMap(cs => JsonSchemaValidatorImpl.from(cs.schema).mapError(SchemaError.apply)) + ) _ <- schemaValidator.validate(claims).mapError(SchemaError.apply) } yield () } @@ -148,20 +149,10 @@ object CredentialSchema { for { uri <- ZIO.attempt(new URI(schemaId)).mapError(t => URISyntaxError(t.getMessage)) content <- uriDereferencer.dereference(uri).mapError(err => UnexpectedError(err.toString)) - vcSchema <- parseCredentialSchema(content) - resolvedSchemaType <- resolveCredentialSchemaType(vcSchema.`type`) - _ <- - Validation - .fromPredicateWith( - CredentialSchemaParsingError( - s"Only ${CredentialJsonSchemaType.`type`} schema type can be used to verify claims" - ) - )(resolvedSchemaType.`type`)(`type` => `type` == AnoncredSchemaType.`type`) - .toZIO validAttrNames <- ZIO - .fromEither(vcSchema.schema.as[AnoncredSchemaSerDesV1]) + .fromEither(content.fromJson[AnoncredSchemaSerDesV1]) + .mapError(error => CredentialSchemaParsingError(s"AnonCreds Schema parsing error: $error")) .map(_.attrNames) - .mapError(err => UnexpectedError(err)) jsonClaims <- ZIO.fromEither(claims.fromJson[Json]).mapError(err => UnexpectedError(err)) _ <- jsonClaims match case Json.Obj(fields) => @@ -193,8 +184,4 @@ object CredentialSchema { } yield () } - def parseCredentialSchema(vcSchemaString: String): IO[CredentialSchemaError, CredentialSchema] = - ZIO - .fromEither(vcSchemaString.fromJson[CredentialSchema]) - .mapError(error => CredentialSchemaParsingError(s"VC Schema parsing error: $error")) } diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialDefinitionServiceImpl.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialDefinitionServiceImpl.scala index 7aca15f038..a7ec38bb81 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialDefinitionServiceImpl.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialDefinitionServiceImpl.scala @@ -5,11 +5,10 @@ import io.iohk.atala.agent.walletapi.storage.GenericSecretStorage import io.iohk.atala.pollux.anoncreds.{AnoncredLib, SchemaDef} import io.iohk.atala.pollux.core.model.error.CredentialSchemaError import io.iohk.atala.pollux.core.model.error.CredentialSchemaError.URISyntaxError +import io.iohk.atala.pollux.core.model.schema.CredentialDefinition import io.iohk.atala.pollux.core.model.schema.CredentialDefinition.{Filter, FilteredEntries} -import io.iohk.atala.pollux.core.model.schema.CredentialSchema.parseCredentialSchema import io.iohk.atala.pollux.core.model.schema.`type`.anoncred.AnoncredSchemaSerDesV1 import io.iohk.atala.pollux.core.model.schema.validator.JsonSchemaError -import io.iohk.atala.pollux.core.model.schema.{CredentialDefinition, CredentialSchema} import io.iohk.atala.pollux.core.model.secret.CredentialDefinitionSecret import io.iohk.atala.pollux.core.repository.CredentialDefinitionRepository import io.iohk.atala.pollux.core.repository.Repository.SearchQuery @@ -36,8 +35,7 @@ class CredentialDefinitionServiceImpl( for { uri <- ZIO.attempt(new URI(in.schemaId)) content <- uriDereferencer.dereference(uri) - vcSchema <- parseCredentialSchema(content) - anoncredSchema <- AnoncredSchemaSerDesV1.schemaSerDes.deserialize(vcSchema.schema) + anoncredSchema <- AnoncredSchemaSerDesV1.schemaSerDes.deserialize(content) anoncredLibSchema = SchemaDef( in.schemaId, diff --git a/pollux/lib/core/src/test/resources/anoncred-schema-example.json b/pollux/lib/core/src/test/resources/anoncred-schema-example.json index bc6bea286d..8507b68529 100644 --- a/pollux/lib/core/src/test/resources/anoncred-schema-example.json +++ b/pollux/lib/core/src/test/resources/anoncred-schema-example.json @@ -1,28 +1,12 @@ { - "guid": "1631026d-5d55-3285-8ccd-bd70480cfbdc", - "id": "329da384-b2bb-497f-a605-4118dec75d31", - "longId": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff/329da384-b2bb-497f-a605-4118dec75d31?version=5.0.0", - "name": "DrivingLicense", - "version": "5.0.0", - "tags": [ - "string" + "name": "Driving licence Anoncred Schema", + "version": "1.0", + "attrNames": [ + "emailAddress", + "familyName", + "dateOfIssuance", + "drivingLicenseID", + "drivingClass" ], - "description": "Simple credential schema for the driving licence verifiable credential.", - "type": "AnoncredSchemaV1", - "schema": { - "name": "Driving licence Anoncred Schema", - "version": "1.0", - "attrNames": [ - "emailAddress", - "familyName", - "dateOfIssuance", - "drivingLicenseID", - "drivingClass" - ], - "issuerId": "http://www.example.com/issuer" - }, - "author": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff", - "authored": "2023-04-06T08:48:01.654162Z", - "kind": "CredentialSchema", - "self": "/schema-registry/schemas/1631026d-5d55-3285-8ccd-bd70480cfbdc" + "issuerId": "http://www.example.com/issuer" } diff --git a/pollux/lib/core/src/test/resources/vc-schema-example.json b/pollux/lib/core/src/test/resources/vc-schema-example.json index 9b0e106826..cc2b777de8 100644 --- a/pollux/lib/core/src/test/resources/vc-schema-example.json +++ b/pollux/lib/core/src/test/resources/vc-schema-example.json @@ -1,60 +1,44 @@ { - "guid": "1631026d-5d55-3285-8ccd-bd70480cfbdc", - "id": "329da384-b2bb-497f-a605-4118dec75d31", - "longId": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff/329da384-b2bb-497f-a605-4118dec75d31?version=5.0.0", - "name": "DrivingLicense", - "version": "5.0.0", - "tags": [ - "string" - ], - "description": "Simple credential schema for the driving licence verifiable credential.", - "type": "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "Driving License", - "type": "object", - "properties": { - "credentialSubject": { - "type": "object", - "properties": { - "emailAddress": { - "type": "string", - "format": "email" - }, - "givenName": { - "type": "string" - }, - "familyName": { - "type": "string" - }, - "dateOfIssuance": { - "type": "string", - "format": "date-time" - }, - "drivingLicenseID": { - "type": "string" - }, - "drivingClass": { - "type": "integer" - } + "$schema": "https://json-schema.org/draft/2020-12/schema", + "description": "Driving License", + "type": "object", + "properties": { + "credentialSubject": { + "type": "object", + "properties": { + "emailAddress": { + "type": "string", + "format": "email" + }, + "givenName": { + "type": "string" + }, + "familyName": { + "type": "string" }, - "required": [ - "emailAddress", - "familyName", - "dateOfIssuance", - "drivingLicenseID", - "drivingClass" - ], - "additionalProperties": false - } - }, - "required": [ - "credentialSubject" - ], - "additionalProperties": false + "dateOfIssuance": { + "type": "string", + "format": "date-time" + }, + "drivingLicenseID": { + "type": "string" + }, + "drivingClass": { + "type": "integer" + } + }, + "required": [ + "emailAddress", + "familyName", + "dateOfIssuance", + "drivingLicenseID", + "drivingClass" + ], + "additionalProperties": false + } }, - "author": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff", - "authored": "2023-04-06T08:48:01.654162Z", - "kind": "CredentialSchema", - "self": "/schema-registry/schemas/1631026d-5d55-3285-8ccd-bd70480cfbdc" -} + "required": [ + "credentialSubject" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryEndpoints.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryEndpoints.scala index 94b52a55d4..b3fd988a93 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryEndpoints.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryEndpoints.scala @@ -17,6 +17,7 @@ import io.iohk.atala.pollux.credentialschema.http.{ import sttp.apispec.{ExternalDocumentation, Tag} import sttp.model.StatusCode import sttp.tapir.json.zio.jsonBody +import sttp.tapir.json.zio.schemaForZioJsonValue import sttp.tapir.{ Endpoint, EndpointInput, @@ -28,6 +29,7 @@ import sttp.tapir.{ statusCode, stringToPath } +import zio.json.ast.Json import java.util.UUID @@ -161,6 +163,26 @@ object SchemaRegistryEndpoints { ) .tag(tagName) + val getRawSchemaByIdEndpoint: PublicEndpoint[ + (RequestContext, UUID), + ErrorResponse, + Json, // changed to generic Json type + Any + ] = + endpoint.get + .in(extractFromRequest[RequestContext](RequestContext.apply)) + .in( + "schema-registry" / "schemas" / path[UUID]("guid") / "schema".description( + "Globally unique identifier of the credential schema record" + ) + ) + .out(jsonBody[Json].description("Raw JSON response of the CredentialSchema")) // changed to Json + .errorOut(basicFailuresAndNotFound) + .name("getRawSchemaById") + .summary("Fetch the schema from the registry by `guid`") + .description("Fetch the credential schema by the unique identifier") + .tag("Schema Registry") + private val credentialSchemaFilterInput: EndpointInput[FilterInput] = EndpointInput.derived[FilterInput] private val paginationInput: EndpointInput[PaginationInput] = EndpointInput.derived[PaginationInput] val lookupSchemasByQueryEndpoint: Endpoint[ diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryServerEndpoints.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryServerEndpoints.scala index 5572ae6325..0493950bc3 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryServerEndpoints.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/SchemaRegistryServerEndpoints.scala @@ -1,12 +1,9 @@ package io.iohk.atala.pollux.credentialschema import io.iohk.atala.agent.walletapi.model.BaseEntity +import io.iohk.atala.api.http.RequestContext import io.iohk.atala.api.http.model.{Order, PaginationInput} -import io.iohk.atala.api.http.{ErrorResponse, RequestContext} -import io.iohk.atala.iam.authentication.Authenticator -import io.iohk.atala.iam.authentication.Authorizer -import io.iohk.atala.iam.authentication.DefaultAuthenticator -import io.iohk.atala.iam.authentication.SecurityLogic +import io.iohk.atala.iam.authentication.{Authenticator, Authorizer, DefaultAuthenticator, SecurityLogic} import io.iohk.atala.pollux.credentialschema.SchemaRegistryEndpoints.* import io.iohk.atala.pollux.credentialschema.controller.CredentialSchemaController import io.iohk.atala.pollux.credentialschema.http.{CredentialSchemaInput, FilterInput} @@ -21,14 +18,11 @@ class SchemaRegistryServerEndpoints( authenticator: Authenticator[BaseEntity], authorizer: Authorizer[BaseEntity] ) { - def throwableToInternalServerError(throwable: Throwable) = - ZIO.fail[ErrorResponse](ErrorResponse.internalServerError(detail = Option(throwable.getMessage))) - val createSchemaServerEndpoint: ZServerEndpoint[Any, Any] = createSchemaEndpoint .zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer)) - .serverLogic { - case wac => { case (ctx: RequestContext, schemaInput: CredentialSchemaInput) => + .serverLogic { wac => + { case (ctx: RequestContext, schemaInput: CredentialSchemaInput) => credentialSchemaController .createSchema(schemaInput)(ctx) .provideSomeLayer(ZLayer.succeed(wac)) @@ -38,8 +32,8 @@ class SchemaRegistryServerEndpoints( val updateSchemaServerEndpoint: ZServerEndpoint[Any, Any] = updateSchemaEndpoint .zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer)) - .serverLogic { - case wac => { case (ctx: RequestContext, author: String, id: UUID, schemaInput: CredentialSchemaInput) => + .serverLogic { wac => + { case (ctx: RequestContext, author: String, id: UUID, schemaInput: CredentialSchemaInput) => credentialSchemaController .updateSchema(author, id, schemaInput)(ctx) .provideSomeLayer(ZLayer.succeed(wac)) @@ -52,11 +46,17 @@ class SchemaRegistryServerEndpoints( credentialSchemaController.getSchemaByGuid(guid)(ctx) } + val getRawSchemaByIdServerEndpoint: ZServerEndpoint[Any, Any] = + getRawSchemaByIdEndpoint + .zServerLogic { case (ctx: RequestContext, guid: UUID) => + credentialSchemaController.getSchemaJsonByGuid(guid)(ctx) + } + val lookupSchemasByQueryServerEndpoint: ZServerEndpoint[Any, Any] = lookupSchemasByQueryEndpoint .zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer)) - .serverLogic { - case wac => { + .serverLogic { wac => + { case ( ctx: RequestContext, filter: FilterInput, @@ -78,6 +78,7 @@ class SchemaRegistryServerEndpoints( createSchemaServerEndpoint, updateSchemaServerEndpoint, getSchemaByIdServerEndpoint, + getRawSchemaByIdServerEndpoint, lookupSchemasByQueryServerEndpoint ) } diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaController.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaController.scala index 0f2149e114..41d92ec6fc 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaController.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaController.scala @@ -11,10 +11,11 @@ import io.iohk.atala.pollux.credentialschema.http.{ FilterInput } import zio.* -import scala.language.implicitConversions +import scala.language.implicitConversions import java.util.UUID import io.iohk.atala.shared.models.WalletAccessContext +import zio.json.ast.Json trait CredentialSchemaController { def createSchema(in: CredentialSchemaInput)(implicit @@ -29,6 +30,10 @@ trait CredentialSchemaController { rc: RequestContext ): IO[ErrorResponse, CredentialSchemaResponse] + def getSchemaJsonByGuid(id: UUID)(implicit + rc: RequestContext + ): IO[ErrorResponse, Json] + def delete(guid: UUID)(implicit rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, CredentialSchemaResponse] diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaControllerImpl.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaControllerImpl.scala index 22106795ef..6aef51728c 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaControllerImpl.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/credentialschema/controller/CredentialSchemaControllerImpl.scala @@ -17,10 +17,11 @@ import io.iohk.atala.pollux.credentialschema.http.{ CredentialSchemaResponsePage, FilterInput } +import io.iohk.atala.shared.models.WalletAccessContext import zio.* +import zio.json.ast.Json import java.util.UUID -import io.iohk.atala.shared.models.WalletAccessContext class CredentialSchemaControllerImpl(service: CredentialSchemaService, managedDIDService: ManagedDIDService) extends CredentialSchemaController { @@ -65,6 +66,16 @@ class CredentialSchemaControllerImpl(service: CredentialSchemaService, managedDI ) } + override def getSchemaJsonByGuid(guid: UUID)(implicit + rc: RequestContext + ): IO[ErrorResponse, Json] = { + service + .getByGUID(guid) + .map( + _.schema + ) + } + override def delete(guid: UUID)(implicit rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, CredentialSchemaResponse] = { diff --git a/prism-agent/service/server/src/test/resources/anoncred-schema-example.json b/prism-agent/service/server/src/test/resources/anoncred-schema-example.json index bc6bea286d..dab13b547a 100644 --- a/prism-agent/service/server/src/test/resources/anoncred-schema-example.json +++ b/prism-agent/service/server/src/test/resources/anoncred-schema-example.json @@ -1,28 +1,12 @@ { - "guid": "1631026d-5d55-3285-8ccd-bd70480cfbdc", - "id": "329da384-b2bb-497f-a605-4118dec75d31", - "longId": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff/329da384-b2bb-497f-a605-4118dec75d31?version=5.0.0", - "name": "DrivingLicense", - "version": "5.0.0", - "tags": [ - "string" + "name": "Driving licence Anoncred Schema", + "version": "1.0", + "attrNames": [ + "emailAddress", + "familyName", + "dateOfIssuance", + "drivingLicenseID", + "drivingClass" ], - "description": "Simple credential schema for the driving licence verifiable credential.", - "type": "AnoncredSchemaV1", - "schema": { - "name": "Driving licence Anoncred Schema", - "version": "1.0", - "attrNames": [ - "emailAddress", - "familyName", - "dateOfIssuance", - "drivingLicenseID", - "drivingClass" - ], - "issuerId": "http://www.example.com/issuer" - }, - "author": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff", - "authored": "2023-04-06T08:48:01.654162Z", - "kind": "CredentialSchema", - "self": "/schema-registry/schemas/1631026d-5d55-3285-8ccd-bd70480cfbdc" -} + "issuerId": "http://www.example.com/issuer" +} \ No newline at end of file diff --git a/prism-agent/service/server/src/test/resources/vc-schema-example.json b/prism-agent/service/server/src/test/resources/vc-schema-example.json index 9b0e106826..cc2b777de8 100644 --- a/prism-agent/service/server/src/test/resources/vc-schema-example.json +++ b/prism-agent/service/server/src/test/resources/vc-schema-example.json @@ -1,60 +1,44 @@ { - "guid": "1631026d-5d55-3285-8ccd-bd70480cfbdc", - "id": "329da384-b2bb-497f-a605-4118dec75d31", - "longId": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff/329da384-b2bb-497f-a605-4118dec75d31?version=5.0.0", - "name": "DrivingLicense", - "version": "5.0.0", - "tags": [ - "string" - ], - "description": "Simple credential schema for the driving licence verifiable credential.", - "type": "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "Driving License", - "type": "object", - "properties": { - "credentialSubject": { - "type": "object", - "properties": { - "emailAddress": { - "type": "string", - "format": "email" - }, - "givenName": { - "type": "string" - }, - "familyName": { - "type": "string" - }, - "dateOfIssuance": { - "type": "string", - "format": "date-time" - }, - "drivingLicenseID": { - "type": "string" - }, - "drivingClass": { - "type": "integer" - } + "$schema": "https://json-schema.org/draft/2020-12/schema", + "description": "Driving License", + "type": "object", + "properties": { + "credentialSubject": { + "type": "object", + "properties": { + "emailAddress": { + "type": "string", + "format": "email" + }, + "givenName": { + "type": "string" + }, + "familyName": { + "type": "string" }, - "required": [ - "emailAddress", - "familyName", - "dateOfIssuance", - "drivingLicenseID", - "drivingClass" - ], - "additionalProperties": false - } - }, - "required": [ - "credentialSubject" - ], - "additionalProperties": false + "dateOfIssuance": { + "type": "string", + "format": "date-time" + }, + "drivingLicenseID": { + "type": "string" + }, + "drivingClass": { + "type": "integer" + } + }, + "required": [ + "emailAddress", + "familyName", + "dateOfIssuance", + "drivingLicenseID", + "drivingClass" + ], + "additionalProperties": false + } }, - "author": "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff", - "authored": "2023-04-06T08:48:01.654162Z", - "kind": "CredentialSchema", - "self": "/schema-registry/schemas/1631026d-5d55-3285-8ccd-bd70480cfbdc" -} + "required": [ + "credentialSubject" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaBasicSpec.scala b/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaBasicSpec.scala index 083a57eeb3..eae3d76e7f 100644 --- a/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaBasicSpec.scala +++ b/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaBasicSpec.scala @@ -77,6 +77,7 @@ object CredentialSchemaBasicSpec extends ZIOSpecDefault with CredentialSchemaTes .response(asJsonAlways[CredentialSchemaResponse]) .send(backend) } yield response + def getSchemaZIO(uuid: UUID) = for { backend <- backendZIO response <- basicRequest @@ -87,6 +88,16 @@ object CredentialSchemaBasicSpec extends ZIOSpecDefault with CredentialSchemaTes fetchedSchema <- fromEither(response.body) } yield fetchedSchema + def getRawSchemaZIO(uuid: UUID) = for { + backend <- backendZIO + response <- basicRequest + .get(credentialSchemaUriBase.addPath(uuid.toString).addPath("schema")) + .response(asJson) + .send(backend) + + fetchedSchema <- fromEither(response.body) + } yield fetchedSchema + suite("schema-registry create and get by ID operations logic")( test("create the new schema") { for { @@ -108,9 +119,12 @@ object CredentialSchemaBasicSpec extends ZIOSpecDefault with CredentialSchemaTes fetchedSchema <- getSchemaZIO(credentialSchema.guid) + fetchedRawSchema <- getRawSchemaZIO(credentialSchema.guid) + credentialSchemaIsFetched = assert(fetchedSchema)(equalTo(credentialSchema)) + rawCredentialSchemaIsFetched = assert(fetchedRawSchema)(equalTo(credentialSchema.schema)) - } yield statusCodeIs201 && credentialSchemaIsCreated && credentialSchemaIsFetched + } yield statusCodeIs201 && credentialSchemaIsCreated && credentialSchemaIsFetched && rawCredentialSchemaIsFetched }, test("get the schema by the wrong id") { for { diff --git a/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaTestTools.scala b/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaTestTools.scala index fab4e09bf5..68eb1327a1 100644 --- a/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaTestTools.scala +++ b/prism-agent/service/server/src/test/scala/io/iohk/atala/pollux/schema/CredentialSchemaTestTools.scala @@ -99,6 +99,8 @@ trait CredentialSchemaTestTools extends PostgresTestContainerSupport { .thenRunLogic() .whenServerEndpoint(schemaRegistryEndpoints.getSchemaByIdServerEndpoint) .thenRunLogic() + .whenServerEndpoint(schemaRegistryEndpoints.getRawSchemaByIdServerEndpoint) + .thenRunLogic() .whenServerEndpoint( schemaRegistryEndpoints.lookupSchemasByQueryServerEndpoint ) diff --git a/tests/integration-tests/src/test/kotlin/features/credentials/IssueCredentialsSteps.kt b/tests/integration-tests/src/test/kotlin/features/credentials/IssueCredentialsSteps.kt index 595bb64060..e504943c5a 100644 --- a/tests/integration-tests/src/test/kotlin/features/credentials/IssueCredentialsSteps.kt +++ b/tests/integration-tests/src/test/kotlin/features/credentials/IssueCredentialsSteps.kt @@ -100,7 +100,7 @@ class IssueCredentialsSteps { CredentialDefinitionInput( name = "StudentCredential", version = "1.0.0", - schemaId = "$schemaRegistryUrl/${issuer.recall("anoncredsSchema").guid}", + schemaId = "$schemaRegistryUrl/${issuer.recall("anoncredsSchema").guid}/schema", description = "Simple student credentials definition", author = issuer.recall("shortFormDid"), signatureType = "CL",