diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json index f91bc352f2bbd9a65cac8853cf5f6d400b711d87..b2dcc0f912beac65c0219f98135cdc3bc96330ba 100644 --- a/src/main/resources/REST/json/Policy.json +++ b/src/main/resources/REST/json/Policy.json @@ -14,5 +14,11 @@ "did_missing_method": { "did":"did:idunion:BDrEcHc8Tb4Lb2VyQZWEDE" }, - "empty": {} + "empty": {}, + "valid_schema_output": { + "foo": "barbaz" + }, + "invalid_schema_output": { + "foo": "bar" + } } \ 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 37f5a03993c1b691a4550116a852e04d536de85b..55162d1339d71c86dcfd96b1de2d43b749679747 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -11,8 +11,6 @@ import cucumber.api.java.en.When; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.*; - public class PolicyStepDefinitions extends BaseStepDefinitions { private static final Logger logger = @@ -95,10 +93,25 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { @When("^I Export Policy group \\{(.*)\\} name \\{(.*)\\} version \\{(.*)\\}$") public void iExportPolicyGroupExampleNameExamplePolicyVersion( - String group, String name, String version) throws IOException { + String group, String name, String version) { currentRequest.setPath("/policy/policies/" + group + "/" + name + "/" + version + "/export"); Response response = RestClient.get(currentRequest); addRequest(currentRequest); addResponse(response); } + + @When("^I validate the output of policy using (GET|POST) with group \\{(.*)\\} name \\{(.*)\\} version \\{(.*)\\} by JSON schema$") + public void iValidateTheOutputOfPolicyWithGroupExampleNameTestVersionByJSONSchema(String method, String group, String name, String version) { + currentRequest.setPath("/policy/policies/" + group + "/" + name + "/" + version + "/validation"); + + addRequest(currentRequest); + + if (method.equals("GET")) { + Response response = RestClient.get(currentRequest); + addResponse(response); + } else if (method.equals("POST")) { + Response response = RestClient.post(currentRequest); + addResponse(response); + } + } } diff --git a/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/validation/POST.feature b/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/validation/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..c62aa9479541502d67145020b03324276974907f --- /dev/null +++ b/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/validation/POST.feature @@ -0,0 +1,30 @@ +#Copyright (c) 2023 Vereign AG [https://www.vereign.com] + +@rest @all @tsa @policy @phase2 @IDM.TSA.E1.00009 +Feature: API - TSA -Policy - {repository}/{group}/{name}/{version}/validation POST + As user + I want to be able to evaluate a policy output by JSON schema + So I know if the output is as expected + + Background: + Given we are testing the TSA Policy Api + + Scenario: TSA - Validate policy output by JSON schema - Positive + When I load the REST request {Policy.json} with profile {valid_schema_output} + When I validate the output of policy using POST with group {example} name {examplePolicy} version {1.4} by JSON schema + Then the status code should be {200} + And the field {foo} has the value {barbaz} + + @negative @bug-https://gitlab.eclipse.org/eclipse/xfsc/tsa/policy/-/issues/53 + Scenario: TSA - Validate invalid policy output by JSON schema - Negative + When I load the REST request {Policy.json} with profile {invalid_schema_output} + When I validate the output of policy using POST with group {example} name {examplePolicy} version {1.4} by JSON schema + Then the status code should be {400} + And the field {message} has the value {policy output schema validation failed} + + @negative + Scenario: TSA - Validate invalid policy output by JSON schema - Negative + When I load the REST request {Policy.json} with profile {invalid_schema_output} + When I validate the output of policy using POST with group {example} name {examplePolicy} version {1.2} by JSON schema + Then the status code should be {400} + And the field {message} has the value {validation schema for policy output is not found}