diff --git a/README.md b/README.md index 9346c8c88654e115f1cd94e92787514ae5e6f202..2a788b45336a4478ba395e3ec78b6977176a781f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,12 @@ This repository holds the test automation framework based on Java and used for t ### Running -- Run the tests on a remote env: ```gradle regressionSuite -PbaseUrl=https://TestEnv -Dcucumber.tags="@rest, ~@wip" -Dcourgette.threads=10 -Dcourgette.runLevel=Scenario -Dcourgette.rerunFailedScenarios=false -Dcourgette.rerunAttempts=1``` +- Run the tests on a remote env: ```gradle regressionSuite -PbaseUrl={BASE_URL} -Dcucumber.tags="@tsa, not @wip" -Dcourgette.threads=1 -Dcourgette.runLevel=Scenario -Dcourgette.rerunFailedScenarios=false -Dcourgette.rerunAttempts=1 -DmongoUrl={MONGO_PATH}``` +_{BASE_URL} - should be replaced with the path where the services are deployed: +example: http://localhost_ + +_{MONGO_PATH}_ - should be replaced with the address of the MongoDB instance: +example: mongodb://user:pass@localhost:27017 # Manual execution To simplify manual tests execution we have a postman collection with the list of supported endpoints, you can find [here](postman/TSA.postman_collection.json) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 64944b04b97227671eda82ca64cf7ba5cbc02abb..906dafac18df97e62bb3bfe8afc317589d0cd3ff 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,11 @@ if (project.hasProperty("baseUrl")) { baseUrl = project.property("baseUrl") } +def mongoUrl +if (project.hasProperty("mongoUrl")) { + mongoUrl = project.property("mongoUrl") +} + tasks.withType(Test) { systemProperties = System.getProperties() @@ -55,6 +60,7 @@ task regressionSuite(type: Test) { } systemProperty "file.encoding", "utf-8" systemProperty "baseUrl", "${baseUrl}" + systemProperty "mongoUrl", "${mongoUrl}" systemProperties System.getProperties() diff --git a/src/main/java/core/JsonUtils.java b/src/main/java/core/JsonUtils.java index 2b63d39188e43990999974d9a72a0d674f4f213d..2c6828a91eebfe9f026bf24309c7f392ef84e7d6 100644 --- a/src/main/java/core/JsonUtils.java +++ b/src/main/java/core/JsonUtils.java @@ -233,7 +233,7 @@ public class JsonUtils { * @return the uri */ public static String getTSAPolicy() { - return System.getProperty("baseUrl") + ":8081/policy"; + return System.getProperty("baseUrl") + "/policy"; } /** @@ -241,7 +241,7 @@ public class JsonUtils { * @return the uri */ public static String getTSACache() { - return System.getProperty("baseUrl") + ":8083/v1/cache"; + return System.getProperty("baseUrl") + "/cache"; } /** @@ -249,7 +249,7 @@ public class JsonUtils { * @return the uri */ public static String getTSATask() { - return System.getProperty("baseUrl") + ":8082/v1"; + return System.getProperty("baseUrl") + "/task"; } /** diff --git a/src/main/resources/REST/json/Cache.json b/src/main/resources/REST/json/Cache.json index 3e6d6c88f6bd09741c5635abcba33ee950386e44..fdf284a5dcce87927fbb32bf6767c8d9e7993b13 100644 --- a/src/main/resources/REST/json/Cache.json +++ b/src/main/resources/REST/json/Cache.json @@ -1,5 +1,7 @@ { "successful_set": { "msg": "successful setting the cache" + }, + "missing_body": { } } \ No newline at end of file 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 fb270b27c51e2d142d9bb1a2afbd010a4df24f21..77b1a6c08e047239d86d16c6baa6ffaf899ddc8b 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -48,7 +48,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); // MONGO_PATH environment variable should be set to point to the MonoDB instance - public static final String mongoConnection = System.getenv("MONGO_PATH"); + public static final String mongoConnection = System.getProperty("mongoUrl"); RestSessionContainer restSessionContainer; Request currentRequest; diff --git a/src/test/resources/features/tsa/v1/cache/POST.feature b/src/test/resources/features/tsa/cache/v1/cache/GET.feature similarity index 76% rename from src/test/resources/features/tsa/v1/cache/POST.feature rename to src/test/resources/features/tsa/cache/v1/cache/GET.feature index 1b3995ea93447c6b9fe65723a94bc412178a3873..cbc8a8c30749693b8887634b5f86cb960a337b7d 100644 --- a/src/test/resources/features/tsa/v1/cache/POST.feature +++ b/src/test/resources/features/tsa/cache/v1/cache/GET.feature @@ -13,11 +13,11 @@ #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 +#http://gaiax.vereign.com/tsa/cache/v1/cache #Author: Georgi Michev georgi.michev@vereign.com @rest @all @tsa @cache -Feature: API -TSA - Cache - v1/cache POST +Feature: API -TSA - Cache - v1/cache GET As policy administrator I want to have distributed cache feature provided So I am able to use cache functionality in my custom policies @@ -34,10 +34,10 @@ Feature: API -TSA - Cache - v1/cache POST 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 I send the current request as POST to endpoint {/v1/cache} And the status code should be {201} Then I clear the request body - And I send the current request as GET to endpoint {} + And I send the current request as GET to endpoint {/v1/cache} Then the status code should be {200} And the field {msg} has the value {successful setting the cache} @@ -45,7 +45,14 @@ Feature: API -TSA - Cache - v1/cache POST 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 {} + Given I send the current request as GET to endpoint {/v1/cache} 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} + + @negative + Scenario: TSA - Access Cache without header x-cache-key - Negative + Given I send the current request as GET to endpoint {/v1/cache} + Then the status code should be {400} + And the response is valid according to the {Cache_negative_schema.json} REST schema + And the field {message} has the value {"x-cache-key" is missing from header} diff --git a/src/test/resources/features/tsa/cache/v1/cache/POST.feature b/src/test/resources/features/tsa/cache/v1/cache/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..f3758f531e21a75abd73dc70376ab1ef4e218a72 --- /dev/null +++ b/src/test/resources/features/tsa/cache/v1/cache/POST.feature @@ -0,0 +1,53 @@ +#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/cache/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 - Setting 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 {/v1/cache} + And the status code should be {201} + + @negative + Scenario: TSA - Setting Cache with missing header - x-cache-key - Negative + Given I load the REST request {Cache.json} with profile {missing_body} + And I send the current request as POST to endpoint {/v1/cache} + Then the status code should be {400} + And the response is valid according to the {Cache_negative_schema.json} REST schema + And the field {message} has the value {"x-cache-key" is missing from header} + + @negative + Scenario: TSA - Setting Cache with missing body - Negative + And I send the current request as POST to endpoint {/v1/cache} + Then the status code should be {400} + And the response is valid according to the {Cache_negative_schema.json} REST schema + And the field {message} has the value {missing required payload} diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature similarity index 87% rename from src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature rename to src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature index d021432d54b5940ee5a8ed8b7483f3a1bbf2dbc1..080bb9e791181a04edd71127c70cec8157687806 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -13,7 +13,7 @@ #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:8081/policy/:group/:name/:version/evaluation +#https://gaiax.vereign.com/tsa/policy/policy/:group/:name/:version/evaluation #Author: Georgi Michev georgi.michev@vereign.com @rest @all @tsa @policy @@ -33,16 +33,17 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST Scenario: TSA - Evaluate policy synchronously - Positive Given I upload a policy {test1} to repository Then I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/testable/test1/2.0/evaluation} + And I execute the policy {/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 {result.allow} has the value {true} And delete policy {test1} from repository + @bug @issue-35 Scenario: TSA - DID resolution - Positive Given I upload a DID resolver policy to repository Then I load the REST request {Policy.json} with profile {didResolve_evaluate} - And I execute the policy {/example/resolve/1.0/evaluation} + And I execute the policy {/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 {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} @@ -52,7 +53,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST Scenario: TSA - Evaluate policy with incorrect value - Negative Given I upload a policy {test6} to repository Then I load the REST request {Policy.json} with profile {unsuccessful_evaluate} - And I execute the policy {/testable/test6/2.0/evaluation} + And I execute the policy {/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 {result.allow} has the value {false} @@ -61,7 +62,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative Scenario: TSA - Evaluate policy with missing body- Negative Given I upload a policy {test7} to repository - And I execute the policy {/testable/test7/2.0/evaluation} + And I execute the policy {/policy/testable/test7/2.0/evaluation} Then the status code should be {400} And the response is valid according to the {Policy_Evaluate_negative_schema.json} REST schema And the field {message} has the value {missing required payload} @@ -70,16 +71,16 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative Scenario: TSA - Evaluate missing policy - Negative Then I load the REST request {Policy.json} with profile {successful_evaluate} - Given I execute the policy {/testable/test0/1.0/evaluation} + Given I execute the policy {/policy/testable/test0/1.0/evaluation} Then the status code should be {404} And the response is valid according to the {Policy_Evaluate_negative_schema.json} REST schema And the field {message} has the value {error evaluating policy} - @negative + @negative @bug @issue-35 Scenario: TSA - DID resolution with incorrect did - Negative Given I upload a DID resolver policy to repository Then I load the REST request {Policy.json} with profile {didResolve_missing_method} - And I execute the policy {/example/resolve/1.0/evaluation} + And I execute the policy {/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 {result.data.didResolutionMetadata.error} has the value {notFound} diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature similarity index 83% rename from src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature rename to src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature index f9edd19a7adf1130419e7bf03f6ce88f2c661e4e..7de3e01dd6b94174a6d1f78f6a149d2426090424 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature @@ -13,7 +13,7 @@ #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:8081/policy/:group/:name/:version/lock +#https://gaiax.vereign.com/policy/policy/:group/:name/:version/lock #Author: Georgi Michev georgi.michev@vereign.com @rest @all @tsa @policy @lock @@ -27,13 +27,13 @@ Feature: API - TSA - Policy - :group/:name/:version/lock DELETE Scenario: TSA - Unlock policy - Positive Given I upload a policy {test4} to repository - When I lock the policy {/testable/test4/2.0/lock} - And I unlock the policy {/testable/test4/2.0/lock} + When I lock the policy {/policy/testable/test4/2.0/lock} + And I unlock the policy {/policy/testable/test4/2.0/lock} And the status code should be {200} And delete policy {test4} from repository @negative Scenario: TSA - Unlock none existing policy - Negative - When I unlock the policy {/testable/test8/2.0/lock} + When I unlock the policy {/policy/testable/test8/2.0/lock} And the status code should be {404} And the field {message} has the value {policy not found} diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature similarity index 78% rename from src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature rename to src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature index 153569a8098a26788fe9f630367af21b5bc57f96..6496e9b6a2eabfdb638465ac2967a5d2b8a00457 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature @@ -13,7 +13,7 @@ #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:8081/policy/:group/:name/:version/lock +#https://gaiax.vereign.com/policy/policy/:group/:name/:version/lock #Author: Georgi Michev georgi.michev@vereign.com @rest @all @tsa @policy @lock @@ -32,23 +32,23 @@ Feature: API - TSA -Policy - :group/:name/:version/lock POST Scenario: TSA - Lock policy - Positive Given I upload a policy {test2} to repository - When I lock the policy {/testable/test2/2.0/lock} + When I lock the policy {/policy/testable/test2/2.0/lock} Then the status code should be {200} When I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/testable/test2/2.0/evaluation} + And I execute the policy {/policy/testable/test2/2.0/evaluation} Then the status code should be {403} - And I lock the policy {/testable/test2/2.0/lock} + And I lock the policy {/policy/testable/test2/2.0/lock} And the status code should be {403} And the field {message} has the value {policy is already locked} - And I unlock the policy {/testable/test2/2.0/lock} + And I unlock the policy {/policy/testable/test2/2.0/lock} And delete policy {test2} from repository @negative Scenario: TSA - Lock already locked policy - Negative Given I upload a policy {test3} to repository - When I lock the policy {/testable/test3/2.0/lock} - And I lock the policy {/testable/test3/2.0/lock} + When I lock the policy {/policy/testable/test3/2.0/lock} + And I lock the policy {/policy/testable/test3/2.0/lock} And the status code should be {403} And the field {message} has the value {policy is already locked} - And I unlock the policy {/testable/test3/2.0/lock} + And I unlock the policy {/policy/testable/test3/2.0/lock} And delete policy {test3} from repository diff --git a/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature b/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature new file mode 100644 index 0000000000000000000000000000000000000000..0fdc7bb5bf486c2da2f041fa61f36dc9ef9cb043 --- /dev/null +++ b/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature @@ -0,0 +1,56 @@ +#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://gaiax.vereign.com/tsa/task/v1/task +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @task +Feature: API -TSA - Task - v1/task GET + 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 + + @bug @issue-35 + Scenario: TSA - Executing Task with DID resolver and Evaluate the Cache - 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 {/v1/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 \ No newline at end of file diff --git a/src/test/resources/features/tsa/v1/task/{taskName}/POST.feature b/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature similarity index 77% rename from src/test/resources/features/tsa/v1/task/{taskName}/POST.feature rename to src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature index 466118af5246c4f8ccb301ca3da5ef5d492e7f9a..84ecc844d3d82fcd8161a5d43c293c19b4ecb2e7 100644 --- a/src/test/resources/features/tsa/v1/task/{taskName}/POST.feature +++ b/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature @@ -13,7 +13,7 @@ #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 +#http://gaiax.vereign.com/tsa/task/v1/task #Author: Georgi Michev georgi.michev@vereign.com @rest @all @tsa @task @@ -30,14 +30,14 @@ Feature: API -TSA - Task - v1/task POST Background: Given we are testing the TSA Task Api + @bug @issue-35 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} + And I send the current request as POST to endpoint {/v1/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 @@ -45,20 +45,12 @@ Feature: API -TSA - Task - v1/task POST 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} + And I send the current request as POST to endpoint {/v1/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