diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json index d7a8debb80dd680e0e10894c5eed8a2e8a5a058d..e1f37e85c589de4b458f6b1a55986a178cfa487a 100644 --- a/src/main/resources/REST/json/Policy.json +++ b/src/main/resources/REST/json/Policy.json @@ -1,17 +1,17 @@ { - "successful_evaluate": { + "successful_message": { "message": "hello world" }, - "unsuccessful_evaluate": { + "incorrect_message": { "message": "wrong value!" }, - "didResolve_indy_evaluate": { + "did_indy": { "did":"did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE" }, - "didResolve_evaluate": { + "did_key": { "did":"did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6" }, - "didResolve_missing_method": { + "did_missing_method": { "did":"did:idunion:BDrEcHc8Tb4Lb2VyQZWEDE" } } \ No newline at end of file diff --git a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java index 7f854a018d177aa6331668d1bec26f2f575b680f..546371ec782f876f7ae01e268156d770fbefb235 100644 --- a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java @@ -3,11 +3,10 @@ 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 core.*; +import cucumber.api.java.en.And; import cucumber.api.java.en.Given; +import exceptions.RAFException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,6 +21,26 @@ public class CacheStepDefinitions extends BaseStepDefinitions { this.currentRequest = currentRequest; } + @Given("^I load the body of my Cache request with \\{(.*)\\} from \\{(.*)\\}$") + public void iLoadTheBodyOfMyPolicyRequestWithDataFromFile(String profileName, String jsonName) throws Throwable { + logger.info("Loading REST json into current request body. Json file= [{}] , profile= [{}]", jsonName, profileName); + String loadedProfileData = JsonUtils.getProfileFromJson("/REST/json/" + jsonName, profileName); + if (!loadedProfileData.equals("null")) { + currentRequest.setBody(loadedProfileData); + logger.info("SUCCESS - profile loaded."); + } else { + throw new RAFException(String.format("Profile loading FAILED. Value is \"null\". File= [%s] , profile= [%s]", + jsonName, + profileName) + , RestGeneralStepDefinitions.class); + } + } + + @And("^I load value \\{(.*)\\} into current request HEADER \\{(.*)\\}$") + public void iLoadValueFromTheResponseIntoCurrentRequestHEADER(String value, String headerName) throws Throwable { + currentRequest.getHeaders().put(headerName, value); + } + @Given("we are testing the TSA Cache Api") public void weAreTestingTheTSACacheApi() { RestClient.setDefaultEncoding("UTF8"); @@ -31,4 +50,18 @@ public class CacheStepDefinitions extends BaseStepDefinitions { currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); currentRequest.setContentType("application/json"); } + @And("^I send the Cache (POST|GET) request$") + public void iSendTheCachePOSTRequest(String method) { + currentRequest.setPath("/v1/cache"); + + if (method.equals("POST")) { + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + } else if (method.equals("GET")) { + Response response = RestClient.get(currentRequest); + addRequest(currentRequest); + addResponse(response); + } + } } 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 13aa8332e45093c2ce49cda6738433fa6deb4762..cfee7ca1aa562f61c1098ec30165f3f9cc33d411 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -20,12 +20,11 @@ package api.test.rest.tsa.policy; import api.test.core.BaseStepDefinitions; import api.test.rest.RestGeneralStepDefinitions; import api.test.rest.RestSessionContainer; -import core.DataContainer; -import core.Request; -import core.Response; -import core.RestClient; +import core.*; import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; import cucumber.api.java.en.When; +import exceptions.RAFException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -41,9 +40,24 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { this.currentRequest = currentRequest; } + @Given("^I load the body of my Policy request with \\{(.*)\\} from \\{(.*)\\}$") + public void iLoadTheBodyOfMyPolicyRequestWithDataFromFile(String profileName, String jsonName) throws Throwable { + logger.info("Loading REST json into current request body. Json file= [{}] , profile= [{}]", jsonName, profileName); + String loadedProfileData = JsonUtils.getProfileFromJson("/REST/json/" + jsonName, profileName); + if (!loadedProfileData.equals("null")) { + currentRequest.setBody(loadedProfileData); + logger.info("SUCCESS - profile loaded."); + } else { + throw new RAFException(String.format("Profile loading FAILED. Value is \"null\". File= [%s] , profile= [%s]", + jsonName, + profileName) + , RestGeneralStepDefinitions.class); + } + } + @And("^I execute the policy \\{(.*)\\}$") public void iExecuteThePolicy(String path) throws Throwable { - currentRequest.setPath(path); + currentRequest.setPath("/policy/example/" + path + "/1.0/evaluation"); Response response = RestClient.post(currentRequest); addRequest(currentRequest); addResponse(response); @@ -51,7 +65,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { @When("^I lock the policy \\{(.*)\\}$") public void iLockThePolicy(String path) throws Throwable { - currentRequest.setPath(path); + currentRequest.setPath("/policy/example/" + path + "/1.0/lock"); Response response = RestClient.post(currentRequest); addRequest(currentRequest); addResponse(response); @@ -59,7 +73,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { @When("^I unlock the policy \\{(.*)\\}$") public void iUnlockThePolicy(String path) throws Throwable { - currentRequest.setPath(path); + currentRequest.setPath("/policy/example/" + path + "/1.0/lock"); Response response = RestClient.delete(currentRequest); addRequest(currentRequest); addResponse(response); diff --git a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java index 9cf0d8f4064220b9c8692e37f7fc7f25b2797d89..133733643c5b45b9e342a24f3ef4c80b100b528a 100644 --- a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java @@ -6,6 +6,7 @@ import api.test.rest.RestSessionContainer; import core.*; import cucumber.api.java.en.And; import cucumber.api.java.en.Given; +import exceptions.RAFException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -38,4 +39,36 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ addRequest(currentRequest); addResponse(response); } + + @Given("^I load the body of my Task request with \\{(.*)\\} from \\{(.*)\\}$") + public void iLoadTheBodyOfMyPolicyRequestWithDataFromFile(String profileName, String jsonName) throws Throwable { + logger.info("Loading REST json into current request body. Json file= [{}] , profile= [{}]", jsonName, profileName); + String loadedProfileData = JsonUtils.getProfileFromJson("/REST/json/" + jsonName, profileName); + if (!loadedProfileData.equals("null")) { + currentRequest.setBody(loadedProfileData); + logger.info("SUCCESS - profile loaded."); + } else { + throw new RAFException(String.format("Profile loading FAILED. Value is \"null\". File= [%s] , profile= [%s]", + jsonName, + profileName) + , RestGeneralStepDefinitions.class); + } + } + + @And("^I execute the Task \\{(.*)\\}$") + public void iExecuteThePolicy(String path) throws Throwable { + currentRequest.setPath("/v1/task/" + path); + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + } + + @And("^I get the Task result with key \\{(.*)\\}$") + public void iGetTheTaskResultWithKey(String suffix) { + currentRequest.setPath("v1/taskResult/"+ getDataContainer().getObject(suffix)); + + Response response = RestClient.get(currentRequest); + addRequest(currentRequest); + addResponse(response); + } } diff --git a/src/test/resources/features/tsa/cache/v1/cache/GET.feature b/src/test/resources/features/tsa/cache/v1/cache/GET.feature index cbc8a8c30749693b8887634b5f86cb960a337b7d..73840699f60535f263d85b54938f8b0c0bfd074f 100644 --- a/src/test/resources/features/tsa/cache/v1/cache/GET.feature +++ b/src/test/resources/features/tsa/cache/v1/cache/GET.feature @@ -31,28 +31,26 @@ Feature: API -TSA - Cache - v1/cache GET 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 {/v1/cache} + When I load the body of my Cache request with {successful_set} from {Cache.json} + And I load value {test} into current request HEADER {x-cache-key} + And I send the Cache POST request And the status code should be {201} Then I clear the request body - And I send the current request as GET to endpoint {/v1/cache} + And I send the Cache GET request 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 {/v1/cache} + Given I load value {NEGATIVE} into current request HEADER {x-cache-key} + And I send the Cache GET request 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} + Given I send the Cache GET request 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 index f3758f531e21a75abd73dc70376ab1ef4e218a72..a828b0466f7ac2e25553e13566328e97f8e7a1f2 100644 --- a/src/test/resources/features/tsa/cache/v1/cache/POST.feature +++ b/src/test/resources/features/tsa/cache/v1/cache/POST.feature @@ -31,23 +31,22 @@ Feature: API -TSA - Cache - v1/cache POST 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} + When I load the body of my Cache request with {successful_set} from {Cache.json} + And I load value {test} into current request HEADER {x-cache-key} + And I send the Cache POST request 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} + When I load the body of my Cache request with {missing_body} from {Cache.json} + And I send the Cache POST request 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} + When I send the Cache POST request 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/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature index 2e6ce3506865ae623ef1311ab5c2ba1b2259a02c..80301a2880f7942e0f8ede0a2376a7a0de561622 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -31,47 +31,46 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST Given we are testing the TSA Policy Api Scenario: TSA - Evaluate policy synchronously - Positive - Given I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/policy/example/test/1.0/evaluation} + When I load the body of my Policy request with {successful_message} from {Policy.json} + And I execute the policy {test} 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} - @bug-policy-35 Scenario: TSA - DID resolution - Positive - Given I load the REST request {Policy.json} with profile {didResolve_evaluate} - And I execute the policy {/policy/example/resolve/1.0/evaluation} + When I load the body of my Policy request with {did_key} from {Policy.json} + And I execute the policy {resolve} 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:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} @negative Scenario: TSA - Evaluate policy with incorrect value - Negative - Given I load the REST request {Policy.json} with profile {unsuccessful_evaluate} - And I execute the policy {/policy/example/test/1.0/evaluation} + When I load the body of my Policy request with {incorrect_message} from {Policy.json} + And I execute the policy {test} 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} @negative Scenario: TSA - Evaluate policy with missing body- Negative - Given I execute the policy {/policy/example/test/1.0/evaluation} + Given I execute the policy {test} 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} @negative Scenario: TSA - Evaluate missing policy - Negative - Then I load the REST request {Policy.json} with profile {successful_evaluate} - Given I execute the policy {/policy/testable/test0/1.0/evaluation} + When I load the body of my Policy request with {successful_message} from {Policy.json} + Given I execute the policy {missing} 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 @bug-policy-35 + @negative Scenario: TSA - DID resolution with incorrect did - Negative - Then I load the REST request {Policy.json} with profile {didResolve_missing_method} - And I execute the policy {/policy/example/resolve/1.0/evaluation} + When I load the body of my Policy request with {did_missing_method} from {Policy.json} + And I execute the policy {resolve} 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} diff --git a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature index 98592b36e4e7529297646de59512ac6ed8515d5b..bcb817a28d128e9074fa41c1ae54406fb6f48523 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature @@ -26,12 +26,16 @@ Feature: API - TSA - Policy - :group/:name/:version/lock DELETE Given we are testing the TSA Policy Api Scenario: TSA - Unlock policy - Positive - When I lock the policy {/policy/example/test/1.0/lock} - And I unlock the policy {/policy/example/test/1.0/lock} + When I lock the policy {test} + And I unlock the policy {test} And the status code should be {200} + # Check if the policy can be executed + When I load the body of my Policy request with {successful_message} from {Policy.json} + And I execute the policy {test} + Then the status code should be {200} @negative Scenario: TSA - Unlock none existing policy - Negative - When I unlock the policy {/policy/example/non_existing/1.0/lock} + When I unlock the policy {non_existing} 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/policy/{group}/{name}/{version}/lock/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature index 5aea20e16541f864122a3c069937c15306c0bbf7..6a0efd9042248f0af5323a11098853894ac232c5 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature @@ -31,20 +31,18 @@ Feature: API - TSA -Policy - :group/:name/:version/lock POST Given we are testing the TSA Policy Api Scenario: TSA - Lock policy - Positive - When I lock the policy {/policy/example/test/1.0/lock} + When I lock the policy {test} Then the status code should be {200} - When I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/policy/example/test/1.0/evaluation} + Then I load the body of my Policy request with {successful_message} from {Policy.json} + And I execute the policy {test} Then the status code should be {403} - And I lock the policy {/policy/example/test/1.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 {/policy/example/test/1.0/lock} + And the field {message} has the value {error evaluating policy} + And I unlock the policy {test} @negative Scenario: TSA - Lock already locked policy - Negative - When I lock the policy {/policy/example/test/1.0/lock} - And I lock the policy {/policy/example/test/1.0/lock} + When I lock the policy {test} + And I lock the policy {test} And the status code should be {403} And the field {message} has the value {policy is already locked} - And I unlock the policy {/policy/example/test/1.0/lock} + And I unlock the policy {test} 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 index 1ee887627188163aba4c2116b8d807e0427e1e2c..926774fa16eb241b5e737498f6c044cf9d3a23cf 100644 --- a/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature +++ b/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature @@ -30,17 +30,16 @@ Feature: API -TSA - Task - v1/task GET Background: Given we are testing the TSA Task Api - @bug-policy-35 Scenario: TSA - Executing Task with DID resolver and Evaluate the Cache - Positive - Given I load the REST request {Policy.json} with profile {didResolve_evaluate} - And I send the current request as POST to endpoint {/v1/task/didResolve} + When I load the body of my Task request with {did_key} from {Policy.json} + And I execute the 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 {v1/taskResult} with container value{taskID} + And I get the Task result with key {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 {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} diff --git a/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature b/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature index bd1a4e3550c980b6ec5045e1f31676f5a3ef53e1..c96d97c5c0dd59aa34a12f2ea66979201840ad5d 100644 --- a/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature +++ b/src/test/resources/features/tsa/task/v1/task/{taskName}/POST.feature @@ -30,23 +30,22 @@ Feature: API -TSA - Task - v1/task POST Background: Given we are testing the TSA Task Api - @bug-policy-35 Scenario: TSA - Executing Task with DID resolver - Positive - 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} + When I load the body of my Task request with {did_key} from {Policy.json} + And I execute the Task {didResolve} Then the status code should be {200} And the response is valid according to the {Task_Execute_schema.json} REST schema 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 {v1/taskResult} with container value{taskID} + And I get the Task result with key {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 {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} @negative Scenario: TSA - Executing Task with non existing task template - Negative - Then I load the REST request {Policy.json} with profile {didResolve_evaluate} - And I send the current request as POST to endpoint {/v1/task/resolve} + When I load the body of my Task request with {did_key} from {Policy.json} + And I execute the Task {non_existing} 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}