diff --git a/src/main/resources/REST/json/Data.json b/src/main/resources/REST/json/Data.json new file mode 100644 index 0000000000000000000000000000000000000000..cafc6ebc7d83102ae2a03d78c42068aee8edfdce --- /dev/null +++ b/src/main/resources/REST/json/Data.json @@ -0,0 +1,57 @@ +{ + "single": { + "data": [ + { + "age": 21, + "over18": true + } + ] + }, + "multi": { + "data": [ + { + "dataOfBirth": "-0571-01-01T07:53:06.234142119Z", + "age": 2592, + "over18": true + }, + { + "fName": "Pythagoras", + "lName": "of Samos" + } + ] + }, + "context": { + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/security/suites/jws-2020/v1", + "https://schema.org" + ], + "data": [ + { + "dataOfBirth": "-0571-01-01T07:53:06.234142119Z", + "age": 2592, + "over18": true + }, + { + "fName": "Pythagoras", + "lName": "of Samos" + } + ] + }, + "blank": { + }, + "missing_data": { + "not_data": [ + { + "age": 21, + "over18": true + } + ] + }, + "blank_data": { + "data": [] + }, + "data_format": { + "data": "different format" + } +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Signer_JSON_context_schema.json b/src/main/resources/REST/schemas/Signer_JSON_context_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..3ceb89060404a997cb72193abfaff74e089b0058 --- /dev/null +++ b/src/main/resources/REST/schemas/Signer_JSON_context_schema.json @@ -0,0 +1,169 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "id": { + "type": "string" + }, + "proof": { + "type": "object", + "properties": { + "created": { + "type": "string" + }, + "jws": { + "type": "string" + }, + "proofPurpose": { + "type": "string" + }, + "type": { + "type": "string" + }, + "verificationMethod": { + "type": "string" + } + }, + "required": [ + "created", + "jws", + "proofPurpose", + "type", + "verificationMethod" + ] + }, + "type": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "credentialSubject": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "dataOfBirth": { + "type": "string" + }, + "over18": { + "type": "boolean" + } + }, + "required": [ + "age", + "dataOfBirth", + "over18" + ] + }, + "issuanceDate": { + "type": "string" + }, + "issuer": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "type" + ] + }, + { + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "credentialSubject": { + "type": "object", + "properties": { + "fName": { + "type": "string" + }, + "lName": { + "type": "string" + } + }, + "required": [ + "fName", + "lName" + ] + }, + "issuanceDate": { + "type": "string" + }, + "issuer": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "type" + ] + } + ] + } + }, + "required": [ + "@context", + "id", + "proof", + "type", + "verifiableCredential" + ] +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Signer_JSON_multi_schema.json b/src/main/resources/REST/schemas/Signer_JSON_multi_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..3ceb89060404a997cb72193abfaff74e089b0058 --- /dev/null +++ b/src/main/resources/REST/schemas/Signer_JSON_multi_schema.json @@ -0,0 +1,169 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "id": { + "type": "string" + }, + "proof": { + "type": "object", + "properties": { + "created": { + "type": "string" + }, + "jws": { + "type": "string" + }, + "proofPurpose": { + "type": "string" + }, + "type": { + "type": "string" + }, + "verificationMethod": { + "type": "string" + } + }, + "required": [ + "created", + "jws", + "proofPurpose", + "type", + "verificationMethod" + ] + }, + "type": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "credentialSubject": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "dataOfBirth": { + "type": "string" + }, + "over18": { + "type": "boolean" + } + }, + "required": [ + "age", + "dataOfBirth", + "over18" + ] + }, + "issuanceDate": { + "type": "string" + }, + "issuer": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "type" + ] + }, + { + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "credentialSubject": { + "type": "object", + "properties": { + "fName": { + "type": "string" + }, + "lName": { + "type": "string" + } + }, + "required": [ + "fName", + "lName" + ] + }, + "issuanceDate": { + "type": "string" + }, + "issuer": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "type" + ] + } + ] + } + }, + "required": [ + "@context", + "id", + "proof", + "type", + "verifiableCredential" + ] +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Signer_JSON_single_schema.json b/src/main/resources/REST/schemas/Signer_JSON_single_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..2827575c1e26db31e5dea33b3ae8ab0322579dd0 --- /dev/null +++ b/src/main/resources/REST/schemas/Signer_JSON_single_schema.json @@ -0,0 +1,115 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "id": { + "type": "string" + }, + "proof": { + "type": "object", + "properties": { + "created": { + "type": "string" + }, + "jws": { + "type": "string" + }, + "proofPurpose": { + "type": "string" + }, + "type": { + "type": "string" + }, + "verificationMethod": { + "type": "string" + } + }, + "required": [ + "created", + "jws", + "proofPurpose", + "type", + "verificationMethod" + ] + }, + "type": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + }, + "credentialSubject": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "over18": { + "type": "boolean" + } + }, + "required": [ + "age", + "over18" + ] + }, + "issuanceDate": { + "type": "string" + }, + "issuer": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "type" + ] + } + ] + } + }, + "required": [ + "@context", + "id", + "proof", + "type", + "verifiableCredential" + ] +} \ No newline at end of file diff --git a/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java index 551ed9df6f857b2be19a8c1eeebbd4b9fd912d6e..5db6ba49cccdd450f27bd8ed8051d377631a7ff9 100644 --- a/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java @@ -44,6 +44,14 @@ public class SignerStepDefinitions extends BaseStepDefinitions { addResponse(response); } + @When("I create presentation from JSON via TSA Signer API") + public void iCreatePresentationFromJSONViaTSASignerAPI() { + currentRequest.setPath("/v1/presentation"); + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + } + @When("I create presentation proof via TSA Signer API") public void iCreatePresentationProofViaTSASignerAPI() { currentRequest.setPath("/v1/presentation/proof"); diff --git a/src/test/resources/features/tsa/signer/v1/presentation/POST.feature b/src/test/resources/features/tsa/signer/v1/presentation/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..28720e063d6bfd600f3a28a47ee7d2fdbeabbfb8 --- /dev/null +++ b/src/test/resources/features/tsa/signer/v1/presentation/POST.feature @@ -0,0 +1,62 @@ +#Copyright (c) 2018 Vereign AG [https://www.vereign.com] +# +#This is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as +#published by the Free Software Foundation, either version 3 of the +#License, or (at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU Affero General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see <http://www.gnu.org/licenses/>. + +#https://gaiax.vereign.com/tsa/signer/v1/presentation +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @signer +Feature: API - TSA - Signer create presentation from JSON - v1/presentation POST + As user + I want to create verifiable presentation from JSON + So the presentation can be verified + + Background: + Given we are testing the TSA Signer Api + + Scenario Outline: TSA - create presentation from JSON <labelSuffix> - Positive + When I load the REST request {Data.json} with profile {<profileOption>} + And I create presentation from JSON via TSA Signer API + Then the status code should be {200} + And the response is valid according to the {<schema>} REST schema + And the field {proof.verificationMethod} has the value {did:web:gaiax.vereign.com:tsa:policy:policy:example:returnDID:1.0:evaluation#key1} + + Examples: + | labelSuffix | profileOption | schema | + | single data | single | Signer_JSON_single_schema.json | + | multi data | multi | Signer_JSON_multi_schema.json | + | with context | context | Signer_JSON_context_schema.json | + + @negative + Scenario Outline: TSA - create presentation from JSON <labelSuffix> - Negative + When I load the REST request {Data.json} with profile {<profileOption>} + And I create presentation from JSON via TSA Signer API + Then the status code should be {400} + And the response is valid according to the {Signer_GetKey_negative_schema.json} REST schema + And the field {message} contains the value {<errMessage>} + + Examples: + | labelSuffix | profileOption | errMessage | + | blank | blank | "data" is missing from body | + | missing data field | missing_data | "data" is missing from body | + | blank data | blank_data | invalid or missing credentials data | + | wrong format | data_format | json: cannot unmarshal string into Go struct field | + + @negative + Scenario: TSA - create presentation from JSON with invalid body - Negative + When I set the following request body {{"data":[{"text": "some text"}}} + And I create presentation from JSON via TSA Signer API + Then the status code should be {400} + And the response is valid according to the {Signer_GetKey_negative_schema.json} REST schema + And the field {message} contains the value {invalid character}