diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json index 676f909001d0dc929621263e98943ed3698710ed..0c1b8db037a6d5bfc52274a570166b41116e1e71 100644 --- a/src/main/resources/REST/json/Policy.json +++ b/src/main/resources/REST/json/Policy.json @@ -1,5 +1,8 @@ { "successful_evaluate": { "message": "hello world" + }, + "unsuccessful_evaluate": { + "message": "wrong value!" } } \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..2ba6dde47d0952c54ea726cc177b2d18ef3157b2 --- /dev/null +++ b/src/main/resources/REST/schemas/Policy_Evaluate_schema.json @@ -0,0 +1,16 @@ +{ +"$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "allow": { + "type": "boolean" + }, + "taskID": { + "type": "string" + } + }, + "required": [ + "allow", + "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 95917e0fc3ff2e3303cce3127a749976ecae3d9c..71bb3a94a6d8b83e5c56e022a55c051f47806003 100644 --- a/src/test/java/api/test/core/GeneralStepDefinitions.java +++ b/src/test/java/api/test/core/GeneralStepDefinitions.java @@ -27,6 +27,7 @@ import cucumber.api.java.After; import cucumber.api.java.Before; import cucumber.api.java.en.*; import exceptions.RAFException; +import org.apache.commons.collections.FactoryUtils; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -741,7 +742,6 @@ public class GeneralStepDefinitions extends BaseStepDefinitions { */ @And("^the field \\{(.*?)\\} is present and not empty$") public void the_field_is_present_and_not_empty(String jsonPath) throws Throwable { - Configuration conf = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build(); ReadContext responseContext = JsonPath.using(conf).parse(getLastResponse().getBody()); 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 ce0af623c209c42670fb581e53c8c7ae57e1fcb9..3e07882ecc4aeaaab66cbe0074022edebe9de1a6 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -67,7 +67,11 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { .append("group", "testable") .append("version", "2.0") .append("locked", false) - .append("rego", "package testable."+ policy +"\n\t\t\n allow {\n 1 == 1\n }\n\n taskID := \"0123456789abcdef\"\n "); + .append("rego", "package testable."+ policy +"\n" + + "default allow = false\n" + + "allow {input.message == \"hello world\"}\n" + + "taskID := \"0123456\""); +// .append("rego", "package testable."+ policy +"\n\t\t\n allow {\n 1 == 1\n }\n\n taskID := \"0123456789abcdef\"\n "); policies.insertOne(test); } @@ -114,7 +118,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { MongoCollection<Document> policies = database.getCollection("policies"); Bson query = eq("name", policy); try { - DeleteResult result = policies.deleteMany(query); + 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 new file mode 100644 index 0000000000000000000000000000000000000000..1ec52061f5aa9a3aeaf9bc3131dc72a0df239984 --- /dev/null +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -0,0 +1,55 @@ +#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:8081/policy +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @policy +Feature: As user + I want to evaluate the policy + So I am able to execute it in the future + + Acceptance criteria: + - HTTP endpoint to evaluate the policy + - example policy created and committed to Git repo + - Green test based on example committed to the system + + Background: + Given we are testing the TSA Policy Api +# And I upload the policy to repository + + Scenario: TSA - Evaluate policy synchronously - Positive + Given I upload a policy {test1} to repository + And set the policy to productive + And the policy successfully uploaded to the system + Then I load the REST request {Policy.json} with profile {successful_evaluate} + 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 delete policy {test1} from repository + + Scenario: TSA - Evaluate policy synchronously - Negative + Given I upload a policy {test6} to repository + And set the policy to productive + And the policy successfully uploaded to the system + Then I load the REST request {Policy.json} with profile {unsuccessful_evaluate} + 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 delete policy {test6} from repository \ No newline at end of file diff --git a/src/test/resources/features/tsa/policy/DELETE.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature similarity index 100% rename from src/test/resources/features/tsa/policy/DELETE.feature rename to src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature diff --git a/src/test/resources/features/tsa/policy/POST.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature similarity index 77% rename from src/test/resources/features/tsa/policy/POST.feature rename to src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature index de8d42ca3098a1582f1bfc9c59a47d5fca2c3ae9..d266862d524610c8f6903d23dda5423a9b59a4cb 100644 --- a/src/test/resources/features/tsa/policy/POST.feature +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature @@ -16,7 +16,7 @@ #http://localhost:8081/policy #Author: Georgi Michev georgi.michev@vereign.com -@rest @all @tsa @policy +@rest @all @tsa @policy @lock Feature: As user I want to evaluate the policy So I am able to execute it in the future @@ -28,20 +28,7 @@ Feature: As user Background: Given we are testing the TSA Policy Api -# And I upload the policy to repository - Scenario: TSA - Evaluate policy synchronously - Positive - Given I upload a policy {test1} to repository - And set the policy to productive - And the policy successfully uploaded to the system - Then I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/testable/test1/2.0/evaluation} - Then the status code should be {200} - And the field {allow} has the value {true} - And the field {taskID} is present and not empty - And delete policy {test1} from repository - - @lock Scenario: TSA - Lock policy - Positive Given I upload a policy {test2} to repository When I lock the policy {/testable/test2/2.0/lock} @@ -55,7 +42,6 @@ Feature: As user And I unlock the policy {/testable/test2/2.0/lock} And delete policy {test2} from repository - @lock 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}