Skip to content
Snippets Groups Projects
Commit c6f1fa3c authored by Rosen Georgiev's avatar Rosen Georgiev
Browse files

Merge branch 'connectionManager' into 'main'

added tests for creds

See merge request !14
parents 9a1ec2cd f8fb2d9d
No related branches found
No related tags found
1 merge request!14added tests for creds
Pipeline #52492 passed with stage
in 1 minute and 47 seconds
Showing
with 978 additions and 1 deletion
......@@ -17,11 +17,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package api.test.rest;
import api.test.rest.pojo.connection.Connection;
import api.test.rest.pojo.credentialDef.CredentialDef;
import api.test.rest.pojo.schema.Schema;
public class RestSessionContainer {
private Schema currentSchema;
private CredentialDef currentCredentialDef;
private Connection currentConnection;
public Connection getCurrentConnection() {
return currentConnection;
}
public void setCurrentConnection(Connection currentConnection) {
this.currentConnection = currentConnection;
}
public CredentialDef getCurrentCredentialDef() {
return currentCredentialDef;
}
public void setCurrentCredentialDef(CredentialDef currentCredentialDef) {
this.currentCredentialDef = currentCredentialDef;
}
public Schema getCurrentSchema() {
return currentSchema;
......
package api.test.rest.pojo.connection;
import com.google.gson.annotations.Expose;
public class Authentication {
@Expose
private String publicKey;
@Expose
private String type;
public String getPublicKey() {
return publicKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package api.test.rest.pojo.connection;
import com.google.gson.annotations.Expose;
public class Connection {
@Expose
private api.test.rest.pojo.connection._tags _tags;
@Expose
private String alias;
@Expose
private String createdAt;
@Expose
private Data data;
@Expose
private String did;
@Expose
private DidDoc didDoc;
@Expose
private String id;
@Expose
private Invitation invitation;
@Expose
private String message;
@Expose
private Metadata metadata;
@Expose
private Boolean multiUseInvitation;
@Expose
private String role;
@Expose
private String state;
@Expose
private Long statusCode;
@Expose
private String verkey;
public api.test.rest.pojo.connection._tags get_tags() {
return _tags;
}
public void set_tags(api.test.rest.pojo.connection._tags _tags) {
this._tags = _tags;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public String getDid() {
return did;
}
public void setDid(String did) {
this.did = did;
}
public DidDoc getDidDoc() {
return didDoc;
}
public void setDidDoc(DidDoc didDoc) {
this.didDoc = didDoc;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Invitation getInvitation() {
return invitation;
}
public void setInvitation(Invitation invitation) {
this.invitation = invitation;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Metadata getMetadata() {
return metadata;
}
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
public Boolean getMultiUseInvitation() {
return multiUseInvitation;
}
public void setMultiUseInvitation(Boolean multiUseInvitation) {
this.multiUseInvitation = multiUseInvitation;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Long getStatusCode() {
return statusCode;
}
public void setStatusCode(Long statusCode) {
this.statusCode = statusCode;
}
public String getVerkey() {
return verkey;
}
public void setVerkey(String verkey) {
this.verkey = verkey;
}
}
package api.test.rest.pojo.connection;
import com.google.gson.annotations.Expose;
public class Data {
@Expose
private Connection connection;
@Expose
private Invitation invitation;
@Expose
private String invitationUrl;
public Connection getConnection() {
return connection;
}
public void setConnection(Connection connection) {
this.connection = connection;
}
public Invitation getInvitation() {
return invitation;
}
public void setInvitation(Invitation invitation) {
this.invitation = invitation;
}
public String getInvitationUrl() {
return invitationUrl;
}
public void setInvitationUrl(String invitationUrl) {
this.invitationUrl = invitationUrl;
}
}
package api.test.rest.pojo.connection;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class DidDoc {
@Expose
private List<Authentication> authentication;
@SerializedName("@context")
private String context;
@Expose
private String id;
@Expose
private List<PublicKey> publicKey;
@Expose
private List<Service> service;
public List<Authentication> getAuthentication() {
return authentication;
}
public void setAuthentication(List<Authentication> authentication) {
this.authentication = authentication;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<PublicKey> getPublicKey() {
return publicKey;
}
public void setPublicKey(List<PublicKey> publicKey) {
this.publicKey = publicKey;
}
public List<Service> getService() {
return service;
}
public void setService(List<Service> service) {
this.service = service;
}
}
package api.test.rest.pojo.connection;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Invitation {
@SerializedName("@id")
private String id;
@Expose
private String label;
@Expose
private List<String> recipientKeys;
@Expose
private List<Object> routingKeys;
@Expose
private String serviceEndpoint;
@SerializedName("@type")
private String type;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<String> getRecipientKeys() {
return recipientKeys;
}
public void setRecipientKeys(List<String> recipientKeys) {
this.recipientKeys = recipientKeys;
}
public List<Object> getRoutingKeys() {
return routingKeys;
}
public void setRoutingKeys(List<Object> routingKeys) {
this.routingKeys = routingKeys;
}
public String getServiceEndpoint() {
return serviceEndpoint;
}
public void setServiceEndpoint(String serviceEndpoint) {
this.serviceEndpoint = serviceEndpoint;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package api.test.rest.pojo.connection;
public class Metadata {
}
package api.test.rest.pojo.connection;
import com.google.gson.annotations.Expose;
public class PublicKey {
@Expose
private String controller;
@Expose
private String id;
@Expose
private String publicKeyBase58;
@Expose
private String type;
public String getController() {
return controller;
}
public void setController(String controller) {
this.controller = controller;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPublicKeyBase58() {
return publicKeyBase58;
}
public void setPublicKeyBase58(String publicKeyBase58) {
this.publicKeyBase58 = publicKeyBase58;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package api.test.rest.pojo.connection;
import java.util.List;
import com.google.gson.annotations.Expose;
public class Service {
@Expose
private String id;
@Expose
private Long priority;
@Expose
private List<String> recipientKeys;
@Expose
private List<Object> routingKeys;
@Expose
private String serviceEndpoint;
@Expose
private String type;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Long getPriority() {
return priority;
}
public void setPriority(Long priority) {
this.priority = priority;
}
public List<String> getRecipientKeys() {
return recipientKeys;
}
public void setRecipientKeys(List<String> recipientKeys) {
this.recipientKeys = recipientKeys;
}
public List<Object> getRoutingKeys() {
return routingKeys;
}
public void setRoutingKeys(List<Object> routingKeys) {
this.routingKeys = routingKeys;
}
public String getServiceEndpoint() {
return serviceEndpoint;
}
public void setServiceEndpoint(String serviceEndpoint) {
this.serviceEndpoint = serviceEndpoint;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package api.test.rest.pojo.connection;
public class _tags {
}
package api.test.rest.pojo.credentialDef;
import com.google.gson.annotations.Expose;
@SuppressWarnings("unused")
public class CredentialDef {
@Expose
private Data data;
@Expose
private String message;
@Expose
private Long statusCode;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Long getStatusCode() {
return statusCode;
}
public void setStatusCode(Long statusCode) {
this.statusCode = statusCode;
}
}
package api.test.rest.pojo.credentialDef;
import com.google.gson.annotations.Expose;
public class Data {
@Expose
private String createdBy;
@Expose
private String createdDate;
@Expose
private String credDefId;
@Expose
private String expiryHours;
@Expose
private String id;
@Expose
private Boolean isAutoIssue;
@Expose
private Boolean isRevokable;
@Expose
private String name;
@Expose
private String schemaID;
@Expose
private String updatedBy;
@Expose
private String updatedDate;
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
public String getCredDefId() {
return credDefId;
}
public void setCredDefId(String credDefId) {
this.credDefId = credDefId;
}
public String getExpiryHours() {
return expiryHours;
}
public void setExpiryHours(String expiryHours) {
this.expiryHours = expiryHours;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Boolean getIsAutoIssue() {
return isAutoIssue;
}
public void setIsAutoIssue(Boolean isAutoIssue) {
this.isAutoIssue = isAutoIssue;
}
public Boolean getIsRevokable() {
return isRevokable;
}
public void setIsRevokable(Boolean isRevokable) {
this.isRevokable = isRevokable;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSchemaID() {
return schemaID;
}
public void setSchemaID(String schemaID) {
this.schemaID = schemaID;
}
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
public String getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(String updatedDate) {
this.updatedDate = updatedDate;
}
}
{
"successful_creation": {
"name": "Automation_CredDef_001",
"isRevokable": false,
"isAutoIssue": false,
"schemaID": "123456",
"createdBy": "acceptsAnyString",
"expiryHours": "24"
}
}
\ No newline at end of file
{
"successful_creation": {
"comment": "Created",
"attributes": [
{
"name": "fName",
"value": "test_fname_3"
},
{
"name": "lName",
"value": "test_lname_3"
},
{
"name": "gender",
"value": "test_gender_3"
}
],
"autoAcceptCredential": "never"
}
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"statusCode": {
"type": "integer"
},
"message": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"schemaID": {
"type": "string"
},
"name": {
"type": "string"
},
"credDefId": {
"type": "string"
},
"isAutoIssue": {
"type": "boolean"
},
"isRevokable": {
"type": "boolean"
},
"expiryHours": {
"type": "string"
},
"createdBy": {
"type": "string"
},
"createdDate": {
"type": "string"
},
"updatedBy": {
"type": "string"
},
"updatedDate": {
"type": "string"
}
},
"required": [
"id",
"schemaID",
"name",
"credDefId",
"isAutoIssue",
"isRevokable",
"expiryHours",
"createdBy",
"createdDate",
"updatedBy",
"updatedDate"
]
}
},
"required": [
"statusCode",
"message",
"data"
]
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ package api.test.rest.ocm.attestation;
import api.test.core.BaseStepDefinitions;
import api.test.rest.RestSessionContainer;
import api.test.rest.pojo.credentialDef.CredentialDef;
import api.test.rest.pojo.schema.Schema;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
......@@ -122,4 +123,68 @@ public class AttestationStepDefinitions extends BaseStepDefinitions {
public void I_get_the_current_Schema_via_OCM_api() {
I_get_schema_with_schemaID_via_OCM_Api(restSessionContainer.getCurrentSchema().getData().getSchemaID());
}
@Then("^I create a new credential definition via OCM Api")
public void I_create_a_new_credential_definition_OCM_Api() {
currentRequest.setPath("/attestation/v1/credentialDef");
Response response = RestClient.post(currentRequest);
addRequest(currentRequest);
addResponse(response);
if (getLastResponse() != null && getLastResponse().getStatusCode() == 201) {
restSessionContainer.setCurrentCredentialDef(JsonUtils.getResourceFromResponse(getLastResponse(), CredentialDef.class));
}
}
@Then("^I create a new credential definition with the current schemaId via OCM Api")
public void I_create_a_new_credential_definition_with_the_current_schemaId_via_OCM_Api() {
Gson gson = new Gson();
JsonElement jsonElement = gson.fromJson(currentRequest.getBody(), JsonElement.class);
// only try to load body as JsonObject if it is not null.
JsonObject jsonObject = new JsonObject();
if (jsonElement != null) jsonObject = jsonElement.getAsJsonObject();;
jsonObject.addProperty("schemaID", restSessionContainer.getCurrentSchema().getData().getSchemaID());
currentRequest.setBody(gson.toJson(jsonObject));
I_create_a_new_credential_definition_OCM_Api();
}
@Given("^I create an offer credential with connectionId \\{(.*?)\\} via OCM Api")
public void I_create_an_offer_credential_with_connectionId_via_OCM_Api(String connectionId) {
Gson gson = new Gson();
JsonElement jsonElement = gson.fromJson(currentRequest.getBody(), JsonElement.class);
// only try to load body as JsonObject if it is not null.
JsonObject jsonObject = new JsonObject();
if (jsonElement != null) jsonObject = jsonElement.getAsJsonObject();;
jsonObject.addProperty("connectionId", connectionId);
jsonObject.addProperty("credentialDefinitionId", restSessionContainer.getCurrentCredentialDef().getData().getCredDefId());
currentRequest.setBody(gson.toJson(jsonObject));
I_create_an_offer_credential_via_OCM_Api();
}
@Given("^I create an offer credential via OCM Api")
public void I_create_an_offer_credential_via_OCM_Api() {
currentRequest.setPath("/attestation/v1/create-offer-credential/");
Response response = RestClient.post(currentRequest);
addRequest(currentRequest);
addResponse(response);
}
@Given("^I create an offer credential for the current Connection and Schema via OCM Api")
public void I_create_an_offer_credential_for_the_current_Connection_and_SchemaVia_OCM_Api() {
Gson gson = new Gson();
JsonElement jsonElement = gson.fromJson(currentRequest.getBody(), JsonElement.class);
// only try to load body as JsonObject if it is not null.
JsonObject jsonObject = new JsonObject();
if (jsonElement != null) jsonObject = jsonElement.getAsJsonObject();;
jsonObject.addProperty("connectionId", restSessionContainer.getCurrentConnection().getData().getConnection().getId());
jsonObject.addProperty("credentialDefinitionId", restSessionContainer.getCurrentCredentialDef().getData().getCredDefId());
currentRequest.setBody(gson.toJson(jsonObject));
I_create_an_offer_credential_via_OCM_Api();
}
}
\ No newline at end of file
......@@ -19,6 +19,8 @@ package api.test.rest.ocm.connection;
import api.test.core.BaseStepDefinitions;
import api.test.rest.RestSessionContainer;
import api.test.rest.pojo.connection.Connection;
import api.test.rest.pojo.credentialDef.CredentialDef;
import com.github.fge.jackson.JsonLoader;
import com.google.gson.*;
import com.jayway.jsonpath.Configuration;
......@@ -71,6 +73,10 @@ public class ConnectionStepDefinitions extends BaseStepDefinitions {
Response response = RestClient.post(currentRequest);
addRequest(currentRequest);
addResponse(response);
if (getLastResponse() != null && getLastResponse().getStatusCode() == 201) {
restSessionContainer.setCurrentConnection(JsonUtils.getResourceFromResponse(getLastResponse(), Connection.class));
}
}
@Given("^we call the health check for connection manager via OCM api")
......
#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/>.
#http://localhost/ocm/attestation/v1/create-offer-credential
#Author: Rosen Georgiev rosen.georgiev@vereign.com
@rest @all @ocm @attestation
Feature: API - OCM - attestation - v1 - create-offer-credential POST
A message sent by the Issuer to the potential Holder, describing the credential they intend to offer.
In Hyperledger Indy, this message is required, because it forces the Issuer to make a cryptographic commitment to the set of
fields in the final credential and thus prevents Issuers from inserting spurious data.
Background:
Given we are testing the OCM Api
@cred @negative
Scenario: OCM - Attestation - Try to Create offer of the currently created credential for untrusted connection - Negative
#Create a new member process connection
Given an administrator generates a QR code by creating a connection with alias {member} via OCM api
Then the field {statusCode} contains the value {200}
And the status code should be {201}
#Creation of the schema
And I clear the query parameters
And I clear the request body
Given I load the REST request {AttestationCreateSchemas.json} with profile {successful_creation}
Then I create a new schema with random version via Attestation Manager in OCM api
And the status code should be {201}
#Creation of the Credential definition
And I clear the request body
Given I load the REST request {AttestationCreateCredentialDef.json} with profile {successful_creation}
Then I create a new credential definition with the current schemaId via OCM Api
And the status code should be {201}
#Create offer credential
And I clear the request body
Given I load the REST request {AttestationCreateOfferDef.json} with profile {successful_creation}
Given I create an offer credential for the current Connection and Schema via OCM Api
And the status code should be {400}
Then the field {statusCode} contains the value {400}
Then the field {message} contains the value {Connection is not trusted}
@cred @negative
Scenario Outline: OCM - Attestation - Try to Create offer of the currently created credential with invalid connectionid <connId> - Negative
#Create a new member process connection
Given an administrator generates a QR code by creating a connection with alias {member} via OCM api
Then the field {statusCode} contains the value {200}
And the status code should be {201}
#Creation of the schema
And I clear the request body
Given I load the REST request {AttestationCreateSchemas.json} with profile {successful_creation}
Then I create a new schema with random version via Attestation Manager in OCM api
And the status code should be {201}
#Creation of the Credential definition
And I clear the request body
Given I load the REST request {AttestationCreateCredentialDef.json} with profile {successful_creation}
Then I create a new credential definition with the current schemaId via OCM Api
And the status code should be {201}
#Create offer credential
And I clear the request body
Given I load the REST request {AttestationCreateOfferDef.json} with profile {successful_creation}
Given I create an offer credential with connectionId {<connId>} via OCM Api
And the status code should be {400}
Then the field {statusCode} contains the value {<status>}
Then the field {message} contains the value {<msg>}
Examples:
| connId | status | msg |
| | 400 | offer credentials required following attributes ( connectionId, credentialDefinitionId, attributes, autoAcceptCredential) |
\ No newline at end of file
#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/>.
#http://localhost/ocm/attestation/v1/credentialDef
#Author: Rosen Georgiev rosen.georgiev@vereign.com
@rest @all @ocm @attestation
Feature: API - OCM - attestation - v1 - credentialDef POST
It is used to create the Credential Definition.
A credential definition is a particular issuer's template based on an existing schema to issue credentials from.
Background:
Given we are testing the OCM Api
@cred
Scenario: OCM - Attestation - Creation of credential definition based on a newly created schema - Positive
#Creation of the schema
Given I load the REST request {AttestationCreateSchemas.json} with profile {successful_creation}
Then I create a new schema with random version via Attestation Manager in OCM api
Then the field {statusCode} contains the value {201}
And the status code should be {201}
#Creation of the Credential definition
And I clear the request body
Given I load the REST request {AttestationCreateCredentialDef.json} with profile {successful_creation}
Then I create a new credential definition with the current schemaId via OCM Api
And the status code should be {201}
And the response is valid according to the {Attestation_POST_credentialDef.json} REST schema
And the field {message} contains the value {Credential definition created successfully}
And the field {statusCode} contains the value {201}
And the field {$.data.name} contains the value {Automation_CredDef_001}
And the field {$.data.isAutoIssue} contains the value {false}
And the field {$.data.isRevokable} contains the value {false}
And the field {$.data.expiryHours} contains the value {24}
And the field {$.data.name} contains the value {Automation_CredDef_001}
\ No newline at end of file
......@@ -47,5 +47,4 @@ Feature: API - OCM - attestation - v1 - schemas GET
And the status code should be {200}
And the response is valid according to the {Attestation_GET_schemas.json} REST schema
And the field {message} contains the value {Schemas fetch successfully}
And the field {$..count} contains the value {1}
And the field {$.data.records} contains {1} elements
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment