diff --git a/src/test/java/api/test/core/GeneralStepDefinitions.java b/src/test/java/api/test/core/GeneralStepDefinitions.java index da7fb70f5db1605b38dc2cebf0530f4a34f9307a..95917e0fc3ff2e3303cce3127a749976ecae3d9c 100644 --- a/src/test/java/api/test/core/GeneralStepDefinitions.java +++ b/src/test/java/api/test/core/GeneralStepDefinitions.java @@ -720,7 +720,7 @@ public class GeneralStepDefinitions extends BaseStepDefinitions { * @see <a href="https://github.com/jayway/JsonPath">https://github.com/jayway/JsonPath</a> */ @And("^the field \\{(.*?)\\} has the value \\{(.*?)\\}$") - public void the_field_has_the_value_(String jsonPath, String expectedResultAsString) throws Throwable { + public static void the_field_has_the_value_(String jsonPath, String expectedResultAsString) 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 8846036e8fb2384135f1a4f7a90e9fb5a9f1a33a..c2ab4532826d4b96d6886c92c5e3ea23386e4b31 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -29,12 +29,17 @@ import core.Request; import core.Response; import core.RestClient; import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; import cucumber.api.java.en.When; +import cucumber.api.java8.Th; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bson.Document; import org.bson.types.ObjectId; +import static api.test.core.GeneralStepDefinitions.the_field_has_the_value_; + public class PolicyStepDefinitions extends BaseStepDefinitions { private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); @@ -49,27 +54,25 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { @When("I upload the policy to repository") public void iUploadThePolicyToRepository() throws Throwable { - MongoClient client = MongoClients.create("mongodb://root:root@localhost:27017"); - MongoDatabase database = client.getDatabase("policy"); - MongoCollection<Document> policies = database.getCollection("policies"); - Document test = new Document("_id", new ObjectId()) - .append("filename", "example_3.0.rego") - .append("name", "test") - .append("group", "testable") - .append("version", "1.0") - .append("locked", false) - .append("rego", "package test.testable allow {1 == 1} taskID := \"0001234567abcdef\""); - policies.insertOne(test); +// MongoClient client = MongoClients.create("mongodb://root:root@localhost:27017"); +// MongoDatabase database = client.getDatabase("policy"); +// MongoCollection<Document> policies = database.getCollection("policies"); +// Document test = new Document("_id", new ObjectId()) +// .append("filename", "example_4.0.rego") +// .append("name", "test") +// .append("group", "testable") +// .append("version", "4.0") +// .append("locked", false) +// .append("rego", "package testable.test\n\t\t\n allow {\n 1 == 1\n }\n\n taskID := \"0123456789abcdef\"\n "); +// policies.insertOne(test); } @And("set the policy to productive") public void setThePolicyToProductive() throws Throwable { - } @And("the policy successfully uploaded to the system") public void thePolicySuccessfullyUploadedToTheSystem() throws Throwable { - } @And("^I execute the policy \\{(.*)\\}$") @@ -79,4 +82,24 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { addRequest(currentRequest); addResponse(response); } + + @Given("the policy exist") + public void thePolicyExist() throws Throwable{ + } + + @When("^I lock the policy \\{(.*)\\}$") + public void iLockThePolicy(String path) throws Throwable { + currentRequest.setPath(path); + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + } + + @When("^I unlock the policy \\{(.*)\\}$") + public void iUnlockThePolicy(String path) throws Throwable { + currentRequest.setPath(path); + Response response = RestClient.delete(currentRequest); + addRequest(currentRequest); + addResponse(response); + } } \ No newline at end of file diff --git a/src/test/resources/features/tsa/policy/api/POST.feature b/src/test/resources/features/tsa/policy/DELETE.feature similarity index 52% rename from src/test/resources/features/tsa/policy/api/POST.feature rename to src/test/resources/features/tsa/policy/DELETE.feature index 98e2886bf309ffe589738165d03d484d7262c9e7..255cd41d4eae870af39250d4a95902e2ad3399eb 100644 --- a/src/test/resources/features/tsa/policy/api/POST.feature +++ b/src/test/resources/features/tsa/policy/DELETE.feature @@ -13,17 +13,25 @@ #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/policy -#Author: Rosen Georgiev rosen.georgiev@vereign.com +#http://localhost:8081/policy +#Author: Georgi Michev georgi.michev@vereign.com -@rest @all -Feature: API - TSA - policy POST - Add a new policy +@rest @all @tsa @policy @lock +Feature: As user + I want to unlock a policy + So I can evaluate it Background: Given we are testing the TSA Policy Api + And I upload the policy to repository - @policy - Scenario: TSA - Adding a new Policy - Positive -#Send Batch - And I clear the request body \ No newline at end of file + Scenario: TSA - Unlock policy - Positive + When I lock the policy {/testable/test/3.0/lock} + And I unlock the policy {/testable/test/3.0/lock} + And the status code should be {200} + + Scenario: TSA - Unlock already unlocked policy - Negative + When I unlock the policy {/testable/test/4.0/lock} + And I unlock the policy {/testable/test/4.0/lock} + And the status code should be {403} + And the field {message} has the value {policy is unlocked} diff --git a/src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature b/src/test/resources/features/tsa/policy/POST.feature similarity index 54% rename from src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature rename to src/test/resources/features/tsa/policy/POST.feature index d10f9737cac98ac79b6f8e3447ef8af42a3f5ed0..0809c6c2b54652a949b54d0340854cde0948d61b 100644 --- a/src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature +++ b/src/test/resources/features/tsa/policy/POST.feature @@ -16,30 +16,48 @@ #http://localhost:8081/policy #Author: Georgi Michev georgi.michev@vereign.com -@rest @all @tsa @sync +@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 - @policy Scenario: TSA - Evaluate policy synchronously - Positive - When I upload the policy to repository And set the policy to productive And the policy successfully uploaded to the system - # When I execute the policy - When I load the REST request {Policy.json} with profile {successful_evaluate} + Then I load the REST request {Policy.json} with profile {successful_evaluate} And I execute the policy {/example/example/1.0/evaluation} - # Then I get successful response Then the status code should be {200} - # And response contains the result of execution of the policy And the field {allow} has the value {true} And the field {taskID} is present and not empty And I clear the request body -#Acceptance criteria: -#- HTTP endpoint to evaluate the policy -#- example policy created and commited to Git repo -#- Green test based on example commited to the system \ No newline at end of file + @lock + Scenario: TSA - Lock policy - Positive + When I lock the policy {/testable/test/1.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/test/1.0/evaluation} + Then the status code should be {403} + And I lock the policy {/testable/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 {/testable/test/1.0/lock} + And I clear the request body + + @lock + Scenario: TSA - Lock already locked policy - Negative + When I lock the policy {/testable/test/2.0/lock} + And I lock the policy {/testable/test/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/test/2.0/lock} + And I clear the request body