diff --git a/features/distributedCache.feature b/features/distributedCache.feature deleted file mode 100644 index 87aa9dbc07f45eac46aabdaaae045bfd9ae2c146..0000000000000000000000000000000000000000 --- a/features/distributedCache.feature +++ /dev/null @@ -1,20 +0,0 @@ -As policy administrator -I want to have distributed cache feature provided -So I am able to use cache functionality in my custom policies - -Scenario: Working with cache -Given one policy to set the value in the cache is uploaded to the system -And the second policy to get the value from the cache is uploaded to the system as well -When I evaluate policy to set the value in the cache -And get a successful response -When I evaluate policy to get the value from the cache -Then I get a successful response -And response body is not empty - - -Acceptance criteria: -- The plugin for rego language to get/set values is ready to use -- The working example how to use the plugin -- Green test based on example commited to the system - - diff --git a/features/executeTask.feature b/features/executeTask.feature index b2c90306f790bcf715ae26b47838dc0b1a56d0b1..933802a754cc5b519916eaafb38ae98456faedfa 100644 --- a/features/executeTask.feature +++ b/features/executeTask.feature @@ -1,12 +1,12 @@ As user -I want to evaluate the policy asyncronously +I want to evaluate the policy asynchronously So I am able to execute the developed Rego code in the future non-blocking Scenario: Execute the task during evaluating policy Given long running policy is uploaded to the system And the task template is uploaded to the system -When I evaluate the policy asyncronously -And the task template is specifyed as an input +When I evaluate the policy asynchronously +And the task template is specified as an input When I get successful response And the response contains taskId @@ -16,9 +16,9 @@ When I request the result of execution And request contains the taskId And the task has finished Then I get successful response -And esponse contains the result of execution of the policy +And response contains the result of execution of the policy Acceptance criteria: -- HTTP endpoints to evalute the policy asyncronously and get the result -- example of long-running policy commited to Git repo -- Green test based on example commited to the system +- HTTP endpoints to evaluate the policy asynchronously and get the result +- example of long-running policy committed to Git repo +- Green test based on example committed to the system diff --git a/features/persistance.feature b/features/persistance.feature index d77d0055a79b6d5d5bfcaca29ecff8ae72c8ff5d..e6f0c26754cfbae1d26ddd358a51c1b359a31d48 100644 --- a/features/persistance.feature +++ b/features/persistance.feature @@ -13,5 +13,5 @@ And response body is not empty Acceptance criteria: - plugin for rego language to set/query values is ready to use -- example of usage of the plugin commited to the system -- green tests based on example commited to the system \ No newline at end of file +- example of usage of the plugin committed to the system +- green tests based on example committed to the system \ No newline at end of file diff --git a/src/main/java/core/JsonUtils.java b/src/main/java/core/JsonUtils.java index ccbbd08330ffe29addff35b3be5f114cdd93f835..2b63d39188e43990999974d9a72a0d674f4f213d 100644 --- a/src/main/java/core/JsonUtils.java +++ b/src/main/java/core/JsonUtils.java @@ -233,7 +233,23 @@ public class JsonUtils { * @return the uri */ public static String getTSAPolicy() { - return System.getProperty("baseUrl") + "/policy"; + return System.getProperty("baseUrl") + ":8081/policy"; + } + + /** + * Get the url for "TSA Cache" + * @return the uri + */ + public static String getTSACache() { + return System.getProperty("baseUrl") + ":8083/v1/cache"; + } + + /** + * Get the url for "TSA Task" + * @return the uri + */ + public static String getTSATask() { + return System.getProperty("baseUrl") + ":8082/v1"; } /** diff --git a/src/main/resources/REST/json/Cache.json b/src/main/resources/REST/json/Cache.json new file mode 100644 index 0000000000000000000000000000000000000000..3e6d6c88f6bd09741c5635abcba33ee950386e44 --- /dev/null +++ b/src/main/resources/REST/json/Cache.json @@ -0,0 +1,5 @@ +{ + "successful_set": { + "msg": "successful setting the cache" + } +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Cache_negative_schema.json b/src/main/resources/REST/schemas/Cache_negative_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..2bb8c406d714067ca7ceb26e548c69aa0b82fc79 --- /dev/null +++ b/src/main/resources/REST/schemas/Cache_negative_schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "kind": { + "type": "integer" + }, + "message": { + "type": "string" + } + }, + "required": [ + "id", + "kind", + "message" + ] +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json b/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json index f8694063f96579419c3537036404d7c1f2c375f3..25fe0ec626a05ef9d7af9205348bd12541f4d408 100644 --- a/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json +++ b/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json @@ -2,47 +2,59 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "data": { + "evaluationID": { + "type": "string" + }, + "result": { "type": "object", "properties": { - "@context": { - "type": "string" - }, - "didDocument": { - "type": "null" - }, - "didDocumentMetadata": { - "type": "object" - }, - "didResolutionMetadata": { + "data": { "type": "object", "properties": { - "contentType": { + "@context": { "type": "string" }, - "error": { - "type": "string" + "didDocument": { + "type": "null" }, - "errorMessage": { - "type": "string" + "didDocumentMetadata": { + "type": "object" + }, + "didResolutionMetadata": { + "type": "object", + "properties": { + "contentType": { + "type": "string" + }, + "error": { + "type": "string" + }, + "errorMessage": { + "type": "string" + } + }, + "required": [ + "contentType", + "error", + "errorMessage" + ] } }, "required": [ - "contentType", - "error", - "errorMessage" + "@context", + "didDocument", + "didDocumentMetadata", + "didResolutionMetadata" ] } }, "required": [ - "@context", - "didDocument", - "didDocumentMetadata", - "didResolutionMetadata" + "data" ] } }, "required": [ - "data" + "evaluationID", + "result" ] } \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Policy_EvaluateDID_schema.json b/src/main/resources/REST/schemas/Policy_EvaluateDID_schema.json index 2e695fe995638b17a726ffc452e94e096f9f6a48..5366333a3446c34403ca7acc6f4c7545e518c2d3 100644 --- a/src/main/resources/REST/schemas/Policy_EvaluateDID_schema.json +++ b/src/main/resources/REST/schemas/Policy_EvaluateDID_schema.json @@ -1,80 +1,110 @@ { - "definitions": {}, - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/object1655293265.json", - "title": "Root", + "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", - "required": [ - "data" - ], "properties": { - "data": { - "$id": "#root/data", - "title": "Data", + "evaluationID": { + "type": "string" + }, + "result": { "type": "object", - "required": [ - "@context", - "didDocument", - "didResolutionMetadata" - ], "properties": { - "@context": { - "$id": "#root/data/@context", - "title": "@context", - "type": "string", - "default": "", - "pattern": "^.*$" - }, - "didDocument": { - "$id": "#root/data/didDocument", - "title": "Diddocument", + "data": { "type": "object", - "required": [ - "authentication", - "id", - "verificationMethod" - ], "properties": { - "authentication": { - "$id": "#root/data/didDocument/authentication", - "title": "Authentication", - "type": "array", - "default": [], - "items":{ - "$id": "#root/data/didDocument/authentication/items", - "title": "Items", - "type": "string", - "default": "", - "pattern": "^.*$" - } + "@context": { + "type": "string" }, - "id": { - "$id": "#root/data/didDocument/id", - "title": "Id", - "type": "string", - "default": "", - "pattern": "^.*$" + "didDocument": { + "type": "object", + "properties": { + "authentication": { + "type": "array", + "items": [ + { + "type": "string" + } + ] + }, + "id": { + "type": "string" + }, + "verificationMethod": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "controller": { + "type": "string" + }, + "id": { + "type": "string" + }, + "publicKeyBase58": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "controller", + "id", + "publicKeyBase58", + "type" + ] + } + ] + } + }, + "required": [ + "authentication", + "id", + "verificationMethod" + ] }, - "verificationMethod": { - "$id": "#root/data/didDocument/verificationMethod", - "title": "Verificationmethod", - "type": "array", - "default": [], - "items":{ - "$id": "#root/data/didDocument/verificationMethod/items", - "title": "Items", - "type": "object" - } + "didResolutionMetadata": { + "type": "object", + "properties": { + "did": { + "type": "object", + "properties": { + "didString": { + "type": "string" + }, + "method": { + "type": "string" + }, + "methodSpecificId": { + "type": "string" + } + }, + "required": [ + "didString", + "method", + "methodSpecificId" + ] + } + }, + "required": [ + "did" + ] } - } - } - , - "didResolutionMetadata": { - "$id": "#root/data/didResolutionMetadata", - "title": "Didresolutionmetadata", - "type": "object" + }, + "required": [ + "@context", + "didDocument", + "didResolutionMetadata" + ] } - } + }, + "required": [ + "data" + ] } - } -} + }, + "required": [ + "evaluationID", + "result" + ] +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Policy_Evaluate_schema.json b/src/main/resources/REST/schemas/Policy_Evaluate_schema.json index 2ba6dde47d0952c54ea726cc177b2d18ef3157b2..3acde7b9d7b5926fdcd44cdc043980c67725ca8b 100644 --- a/src/main/resources/REST/schemas/Policy_Evaluate_schema.json +++ b/src/main/resources/REST/schemas/Policy_Evaluate_schema.json @@ -1,16 +1,24 @@ { -"$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "allow": { - "type": "boolean" - }, - "taskID": { + "evaluationID": { "type": "string" + }, + "result": { + "type": "object", + "properties": { + "allow": { + "type": "boolean" + } + }, + "required": [ + "allow" + ] } }, "required": [ - "allow", - "taskID" + "evaluationID", + "result" ] } \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Task_ExecuteDID_schema.json b/src/main/resources/REST/schemas/Task_ExecuteDID_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..f0ce19fcd55525710d5acbe66d05262ab9efe1dc --- /dev/null +++ b/src/main/resources/REST/schemas/Task_ExecuteDID_schema.json @@ -0,0 +1,33 @@ +{ + "evaluationID": "1f5ba887-8360-46a5-a8af-7a4a8175582d", + "result": { + "doc": { + "@context": "https://w3id.org/did-resolution/v1", + "didDocument": { + "authentication": [ + "did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE#verkey" + ], + "id": "did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE", + "verificationMethod": [ + { + "controller": "did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE", + "id": "did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE#verkey", + "publicKeyBase58": "2HHAKDS8EZK5ZfgZTT7jJFjE5bqkZuFoUgHYAZLjFMbY", + "type": "Ed25519VerificationKey2018" + } + ] + }, + "didResolutionMetadata": { + "contentType": "application/did+ld+json", + "did": { + "didString": "did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE", + "method": "indy", + "methodSpecificId": "idunion:BDrEcHc8Tb4Lb2VyQZWEDE" + }, + "driverUrl": "http://indy-did-driver:8080/1.0/identifiers/$1", + "duration": 708, + "pattern": "^(did:indy:.+)$" + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Task_Execute_schema.json b/src/main/resources/REST/schemas/Task_Execute_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..74efa26decc8f1ee385e628ffa75216a0d8dd44f --- /dev/null +++ b/src/main/resources/REST/schemas/Task_Execute_schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "taskID": { + "type": "string" + } + }, + "required": [ + "taskID" + ] +} \ No newline at end of file diff --git a/src/test/java/api/test/core/GeneralStepDefinitions.java b/src/test/java/api/test/core/GeneralStepDefinitions.java index 71bb3a94a6d8b83e5c56e022a55c051f47806003..884f3822cac104194fbf185240d9c1ab8d734365 100644 --- a/src/test/java/api/test/core/GeneralStepDefinitions.java +++ b/src/test/java/api/test/core/GeneralStepDefinitions.java @@ -603,15 +603,6 @@ public class GeneralStepDefinitions extends BaseStepDefinitions { } } - @When("^I send the current request as GET to endpoint \\{(.*?)\\}$") - public void iSendTheCurrentRequestAsGETToEndpoint(String endpoint) throws Throwable { - currentRequest.setPath(endpoint); - Response response = RestClient.get(currentRequest); - - addRequest(currentRequest); - addResponse(response); - } - /** * Compares the values of a json array with the supplied cucumber table * diff --git a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java new file mode 100644 index 0000000000000000000000000000000000000000..7f854a018d177aa6331668d1bec26f2f575b680f --- /dev/null +++ b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java @@ -0,0 +1,34 @@ +package api.test.rest.tsa.cache; + +import api.test.core.BaseStepDefinitions; +import api.test.rest.RestGeneralStepDefinitions; +import api.test.rest.RestSessionContainer; +import core.DataContainer; +import core.JsonUtils; +import core.Request; +import core.RestClient; +import cucumber.api.java.en.Given; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class CacheStepDefinitions extends BaseStepDefinitions { + private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); + RestSessionContainer restSessionContainer; + Request currentRequest; + + public CacheStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { + super(dataContainer); + this.restSessionContainer = restSessionContainer; + this.currentRequest = currentRequest; + } + + @Given("we are testing the TSA Cache Api") + public void weAreTestingTheTSACacheApi() { + RestClient.setDefaultEncoding("UTF8"); + RestClient.setBaseURI(JsonUtils.getTSACache()); + RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); + currentRequest.clear(); + currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); + currentRequest.setContentType("application/json"); + } +} diff --git a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java index 866469f94077a5b56647587468fc3f0a577382d5..fb270b27c51e2d142d9bb1a2afbd010a4df24f21 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -41,13 +41,14 @@ import org.bson.Document; import org.bson.conversions.Bson; import org.bson.types.ObjectId; -import static api.test.core.GeneralStepDefinitions.the_field_has_the_value_; import static com.mongodb.client.model.Filters.eq; public class PolicyStepDefinitions extends BaseStepDefinitions { private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); - public static final String mongoConnection = "mongodb://root:root@localhost:27017"; + + // MONGO_PATH environment variable should be set to point to the MonoDB instance + public static final String mongoConnection = System.getenv("MONGO_PATH"); RestSessionContainer restSessionContainer; Request currentRequest; @@ -70,8 +71,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { .append("locked", false) .append("rego", "package testable."+ policy +"\n" + "default allow = false\n" + - "allow {input.message == \"hello world\"}\n" + - "taskID := \"0123456\""); + "allow {input.message == \"hello world\"}"); policies.insertOne(test); } @@ -87,8 +87,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { .append("version", "1.0") .append("locked", false) .append("rego", "package example.resolve\n" + - "data = did.resolve(input.did)\n" + - "taskID := \"01234567\""); + "data = did.resolve(input.did)"); policies.insertOne(test); } diff --git a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java new file mode 100644 index 0000000000000000000000000000000000000000..cd0362daa4230e6f2e2acd66c2b03631f19b2629 --- /dev/null +++ b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java @@ -0,0 +1,78 @@ +package api.test.rest.tsa.task; + +import api.test.core.BaseStepDefinitions; +import api.test.rest.RestGeneralStepDefinitions; +import api.test.rest.RestSessionContainer; +import com.mongodb.MongoException; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.result.DeleteResult; +import core.*; +import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.bson.types.ObjectId; + +import static api.test.rest.tsa.policy.PolicyStepDefinitions.mongoConnection; +import static com.mongodb.client.model.Filters.eq; + +public class TaskStepDefinitions extends BaseStepDefinitions{ + private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); + RestSessionContainer restSessionContainer; + Request currentRequest; + + public TaskStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { + super(dataContainer); + this.restSessionContainer = restSessionContainer; + this.currentRequest = currentRequest; + } + + @Given("we are testing the TSA Task Api") + public void weAreTestingTheTSATaskApi() { + RestClient.setDefaultEncoding("UTF8"); + RestClient.setBaseURI(JsonUtils.getTSATask()); + RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); + currentRequest.clear(); + currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); + currentRequest.setContentType("application/json"); + } + + @Given("^I upload a task template \\{(.*?)\\} to repository$") + public void iUploadATaskTemplateToRepository(String task) { + MongoClient client = MongoClients.create(mongoConnection); + MongoDatabase database = client.getDatabase("task"); + MongoCollection<Document> policies = database.getCollection("taskTemplates"); + Document test = new Document("_id", new ObjectId()) + .append("name", task) + .append("requestPolicy", "example/resolve/1.0"); + policies.insertOne(test); + } + + @And("^I send the current request to endpoint \\{(.*?)\\} with container value\\{(.*?)\\}$") + public void I_send_the_current_request_to_endpoint_with_container_value(String endpoint, String suffix) throws Throwable { + currentRequest.setPath(endpoint +"/"+ getDataContainer().getObject(suffix)); + + Response response = RestClient.get(currentRequest); + addRequest(currentRequest); + addResponse(response); + } + + @And("^delete task \\{(.*)\\} from repository$") + public void deletePolicyTestFromRepository(String task) { + MongoClient client = MongoClients.create(mongoConnection); + MongoDatabase database = client.getDatabase("task"); + MongoCollection<Document> policies = database.getCollection("taskTemplates"); + Bson query = eq("name", task); + try { + DeleteResult result = policies.deleteOne(query); + System.out.println("Deleted document count: " + result.getDeletedCount()); + } catch (MongoException me) { + System.err.println("Unable to delete due to an error: " + me); + } + } +} diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature index b0c336b88e13245d8a4809fae80d74da16651e1c..d021432d54b5940ee5a8ed8b7483f3a1bbf2dbc1 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -36,8 +36,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST And I execute the policy {/testable/test1/2.0/evaluation} Then the status code should be {200} And the response is valid according to the {Policy_Evaluate_schema.json} REST schema - And the field {allow} has the value {true} - And the field {taskID} has the value {0123456} + And the field {result.allow} has the value {true} And delete policy {test1} from repository Scenario: TSA - DID resolution - Positive @@ -46,8 +45,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST And I execute the policy {/example/resolve/1.0/evaluation} Then the status code should be {200} And the response is valid according to the {Policy_EvaluateDID_schema.json} REST schema - And the field {data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} - And the field {taskID} has the value {01234567} + And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} And delete policy {resolve} from repository @negative @@ -57,8 +55,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST And I execute the policy {/testable/test6/2.0/evaluation} Then the status code should be {200} And the response is valid according to the {Policy_Evaluate_schema.json} REST schema - And the field {allow} has the value {false} - And the field {taskID} has the value {0123456} + And the field {result.allow} has the value {false} And delete policy {test6} from repository @negative @@ -85,5 +82,5 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST And I execute the policy {/example/resolve/1.0/evaluation} Then the status code should be {200} And the response is valid according to the {Policy_EvaluateDID_negative_schema.json} REST schema - And the field {data.didResolutionMetadata.error} has the value {notFound} + And the field {result.data.didResolutionMetadata.error} has the value {notFound} And delete policy {resolve} from repository diff --git a/src/test/resources/features/tsa/v1/cache/POST.feature b/src/test/resources/features/tsa/v1/cache/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..1b3995ea93447c6b9fe65723a94bc412178a3873 --- /dev/null +++ b/src/test/resources/features/tsa/v1/cache/POST.feature @@ -0,0 +1,51 @@ +#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:8083/v1/cache +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @cache +Feature: API -TSA - Cache - v1/cache POST + As policy administrator + I want to have distributed cache feature provided + So I am able to use cache functionality in my custom policies + + Acceptance criteria: + - The plugin for rego language to get/set values is ready to use + - The working example how to use the plugin + - Green test based on example committed to the system + + Background: + Given we are testing the TSA Cache Api + + Scenario: TSA - Working with Cache - Positive + Given I load the REST request {Cache.json} with profile {successful_set} + And I store key {key_positive} with value {test} in the data container + And I load object with key {key_positive} from DataContainer into currentRequest HEADER {x-cache-key} + And I send the current request as POST to endpoint {} + And the status code should be {201} + Then I clear the request body + And I send the current request as GET to endpoint {} + Then the status code should be {200} + And the field {msg} has the value {successful setting the cache} + + @negative + Scenario: TSA - Access non existing Cache - Negative + And I store key {key_negative} with value {NEGATIVE} in the data container + And I load object with key {key_negative} from DataContainer into currentRequest HEADER {x-cache-key} + Given I send the current request as GET to endpoint {} + Then the status code should be {404} + And the response is valid according to the {Cache_negative_schema.json} REST schema + And the field {message} has the value {key not found in cache} diff --git a/src/test/resources/features/tsa/v1/task/{taskName}/POST.feature b/src/test/resources/features/tsa/v1/task/{taskName}/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..466118af5246c4f8ccb301ca3da5ef5d492e7f9a --- /dev/null +++ b/src/test/resources/features/tsa/v1/task/{taskName}/POST.feature @@ -0,0 +1,64 @@ +#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:8082/v1/task +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @task +Feature: API -TSA - Task - v1/task POST + As user + I want to evaluate the policy asynchronously + So I am able to execute the developed Rego code in the future non-blocking + + Acceptance criteria: + - HTTP endpoints to evaluate the policy asynchronously and get the result + - example of long-running policy committed to Git repo + - Green test based on example committed to the system + + Background: + Given we are testing the TSA Task Api + + Scenario: TSA - Executing Task with DID resolver - Positive + Given I upload a DID resolver policy to repository + And I upload a task template {didResolve} to repository + Then I load the REST request {Policy.json} with profile {didResolve_evaluate} + And I send the current request as POST to endpoint {task/didResolve} + Then the status code should be {200} + And the response is valid according to the {Task_Execute_schema.json} REST schema + # Test the Task Result + Then I get the value of {taskID} from the last response and store it in the DataContainer with key {taskID} + Then I clear the request body + And I wait for {2000} mseconds + And I send the current request to endpoint {taskResult} with container value{taskID} + Then the status code should be {200} + And the response is valid according to the {Task_ExecuteDID_schema.json} REST schema + And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} + # Test the Cache Service + Then I load object with key {taskID} from DataContainer into currentRequest HEADER {x-cache-key} + And I send the current request as GET to endpoint {http://localhost:8083/v1/cache} + And the status code should be {200} + And the response is valid according to the {Task_ExecuteDID_schema.json} REST schema + And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} + Then delete task {didResolve} from repository + And delete policy {resolve} from repository + + @negative + Scenario: TSA - Executing Task with non existing task template - Negative + Given I upload a DID resolver policy to repository + Then I load the REST request {Policy.json} with profile {didResolve_evaluate} + And I send the current request as POST to endpoint {task/resolve} + Then the response is valid according to the {Policy_Evaluate_negative_schema.json} REST schema + And the field {message} has the value {task template not found} + And delete policy {resolve} from repository