diff --git a/build.gradle b/build.gradle index 3c95fb520bc5fe75df2868fb130ea4aaf0541d4e..64944b04b97227671eda82ca64cf7ba5cbc02abb 100644 --- a/build.gradle +++ b/build.gradle @@ -85,4 +85,5 @@ dependencies { implementation group: 'net.sourceforge.tess4j', name: 'tess4j', version: '4.4.1' implementation 'io.github.prashant-ramcharan:courgette-jvm:3.+' + implementation 'org.mongodb:mongodb-driver-sync:4.0.5' } \ No newline at end of file diff --git a/devRun.sh b/devRun.sh index 20d7bdca08b81efaf1ee5c7fe9e77c2306a563ed..9050730745e0d7cca5106aa30a60d0ed46941414 100755 --- a/devRun.sh +++ b/devRun.sh @@ -1,21 +1,10 @@ #!/bin/bash # This is the run command -# ./gradlew regressionSuite \ - # -PbaseUrl=https://batch-service.rse-test.k8s.vereign.com \ - # -PoutlookManifest=https://azure-dev.vrgnservices.com/outlookaddin/manifest.xml \ - # -PprojectLocation=/home/michev/IdeaProjects/ \ - # -Dcourgette.threads=10 \ - # -Dcourgette.runLevel=Scenario \ - # -Dcourgette.rerunFailedScenarios=false \ - # -Dcourgette.rerunAttempts=1 \ - # -Dcucumber.tags="@batch, not @wip" \ - # -PdeviceType='PC' - ./gradlew regressionSuite \ - -PbaseUrl=https://TestEnv \ + -PbaseUrl="http://localhost:8081" \ -Dcucumber.tags="@rest, ~@wip" \ -Dcourgette.threads=10 \ -Dcourgette.runLevel=Scenario \ -Dcourgette.rerunFailedScenarios=false \ - -Dcourgette.rerunAttempts=1 + -Dcourgette.rerunAttempts=1 \ No newline at end of file diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json new file mode 100644 index 0000000000000000000000000000000000000000..676f909001d0dc929621263e98943ed3698710ed --- /dev/null +++ b/src/main/resources/REST/json/Policy.json @@ -0,0 +1,5 @@ +{ + "successful_evaluate": { + "message": "hello world" + } +} \ No newline at end of file diff --git a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java index a5bc5068aa9f03609c5aa33c6eb017b882eda67d..8db36496ba01f20ada4758d24c302dcc9c8510a2 100644 --- a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java +++ b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java @@ -28,25 +28,28 @@ import core.*; 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 exceptions.RAFException; import org.apache.commons.lang3.RandomStringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + +import java.net.UnknownHostException; import java.security.KeyPair; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; + +import static org.junit.Assert.*; import static utils.RsaGenerator.encrypt; import static utils.RsaGenerator.generateKeyPair; + public class RestGeneralStepDefinitions extends BaseStepDefinitions { private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); RestSessionContainer restSessionContainer; Request currentRequest; - public RestGeneralStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { + public RestGeneralStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) throws UnknownHostException { super(dataContainer); this.restSessionContainer = restSessionContainer; this.currentRequest = currentRequest; @@ -187,33 +190,4 @@ public class RestGeneralStepDefinitions extends BaseStepDefinitions { String cipherText = encrypt(message, pair.getPublic()); currentRequest.getHeaders().put("publicKey", cipherText); } - - @When("I upload the policy to repository") - public void iUploadThePolicyToRepository() { - - } - - @And("set the policy to productive") - public void setThePolicyToProductive() { - - } - - @And("the policy successfully uploaded to the system") - public void thePolicySuccessfullyUploadedToTheSystem() { - - } - - @When("I execute the policy") - public void iExecuteThePolicy() { - - } - - @Then("I get successful response") - public void iGetSuccessfulResponse() { - - } - - @And("response contains the result of execution of the policy") - public void responseContainsTheResultOfExecutionOfThePolicy() { - } -} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..8846036e8fb2384135f1a4f7a90e9fb5a9f1a33a --- /dev/null +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -0,0 +1,82 @@ +/* +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/>. +*/ + +package api.test.rest.tsa.policy; + +import api.test.core.BaseStepDefinitions; +import api.test.rest.RestGeneralStepDefinitions; +import api.test.rest.RestSessionContainer; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import core.DataContainer; +import core.Request; +import core.Response; +import core.RestClient; +import cucumber.api.java.en.And; +import cucumber.api.java.en.When; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bson.Document; +import org.bson.types.ObjectId; + +public class PolicyStepDefinitions extends BaseStepDefinitions { + + private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); + RestSessionContainer restSessionContainer; + Request currentRequest; + + public PolicyStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { + super(dataContainer); + this.restSessionContainer = restSessionContainer; + this.currentRequest = currentRequest; + } + + @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); + } + + @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 \\{(.*)\\}$") + public void iExecuteThePolicy(String path) throws Throwable { + currentRequest.setPath(path); + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + } +} \ No newline at end of file diff --git a/src/test/resources/features/policy/api/POST.feature b/src/test/resources/features/tsa/policy/api/POST.feature similarity index 100% rename from src/test/resources/features/policy/api/POST.feature rename to src/test/resources/features/tsa/policy/api/POST.feature diff --git a/src/test/resources/features/policy/api/evaluatePolicySync.feature b/src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature similarity index 67% rename from src/test/resources/features/policy/api/evaluatePolicySync.feature rename to src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature index b617de4cfdd77967048833b7142bfba1c07373a7..d10f9737cac98ac79b6f8e3447ef8af42a3f5ed0 100644 --- a/src/test/resources/features/policy/api/evaluatePolicySync.feature +++ b/src/test/resources/features/tsa/policy/api/evaluatePolicySync.feature @@ -13,10 +13,10 @@ #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 +#http://localhost:8081/policy #Author: Georgi Michev georgi.michev@vereign.com -@rest @all +@rest @all @tsa @sync Feature: As user I want to evaluate the policy So I am able to execute it in the future @@ -24,13 +24,20 @@ Feature: As user Background: Given we are testing the TSA Policy Api - Scenario: Execute the policy + @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 - Then I get successful response - And response contains the result of execution of the policy + # When I execute the policy + When 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