diff --git a/build.gradle b/build.gradle index 906dafac18df97e62bb3bfe8afc317589d0cd3ff..4da9e2e6da74ac40886b560052a19599cb1b3432 100644 --- a/build.gradle +++ b/build.gradle @@ -41,12 +41,6 @@ if (project.hasProperty("baseUrl")) { baseUrl = project.property("baseUrl") } -def mongoUrl -if (project.hasProperty("mongoUrl")) { - mongoUrl = project.property("mongoUrl") -} - - tasks.withType(Test) { systemProperties = System.getProperties() @@ -60,7 +54,6 @@ task regressionSuite(type: Test) { } systemProperty "file.encoding", "utf-8" systemProperty "baseUrl", "${baseUrl}" - systemProperty "mongoUrl", "${mongoUrl}" systemProperties System.getProperties() @@ -90,6 +83,4 @@ dependencies { implementation 'org.bouncycastle:bcpkix-jdk15on:1.51' 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/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java index 77b1a6c08e047239d86d16c6baa6ffaf899ddc8b..13aa8332e45093c2ce49cda6738433fa6deb4762 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -20,35 +20,18 @@ package api.test.rest.tsa.policy; import api.test.core.BaseStepDefinitions; import api.test.rest.RestGeneralStepDefinitions; import api.test.rest.RestSessionContainer; -import com.mongodb.MongoException; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.result.DeleteResult; import core.DataContainer; 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.conversions.Bson; -import org.bson.types.ObjectId; - -import static com.mongodb.client.model.Filters.eq; public class PolicyStepDefinitions extends BaseStepDefinitions { private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); - - // MONGO_PATH environment variable should be set to point to the MonoDB instance - public static final String mongoConnection = System.getProperty("mongoUrl"); RestSessionContainer restSessionContainer; Request currentRequest; @@ -58,39 +41,6 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { this.currentRequest = currentRequest; } - @When("^I upload a policy \\{(.*)\\} to repository$") - public void iUploadThePolicyToRepository(String policy) throws Throwable { - MongoClient client = MongoClients.create(mongoConnection); - MongoDatabase database = client.getDatabase("policy"); - MongoCollection<Document> policies = database.getCollection("policies"); - Document test = new Document("_id", new ObjectId()) - .append("filename", "example_2.0.rego") - .append("name", policy) - .append("group", "testable") - .append("version", "2.0") - .append("locked", false) - .append("rego", "package testable."+ policy +"\n" + - "default allow = false\n" + - "allow {input.message == \"hello world\"}"); - policies.insertOne(test); - } - - @Given("I upload a DID resolver policy to repository") - public void iUploadADIDResolverPolicyDidResolverToRepository() { - MongoClient client = MongoClients.create(mongoConnection); - MongoDatabase database = client.getDatabase("policy"); - MongoCollection<Document> policies = database.getCollection("policies"); - Document test = new Document("_id", new ObjectId()) - .append("filename", "resolve_1.0.rego") - .append("name", "resolve") - .append("group", "example") - .append("version", "1.0") - .append("locked", false) - .append("rego", "package example.resolve\n" + - "data = did.resolve(input.did)"); - policies.insertOne(test); - } - @And("^I execute the policy \\{(.*)\\}$") public void iExecuteThePolicy(String path) throws Throwable { currentRequest.setPath(path); @@ -114,18 +64,4 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { addRequest(currentRequest); addResponse(response); } - - @And("^delete policy \\{(.*)\\} from repository$") - public void deletePolicyTestFromRepository(String policy) { - MongoClient client = MongoClients.create(mongoConnection); - MongoDatabase database = client.getDatabase("policy"); - MongoCollection<Document> policies = database.getCollection("policies"); - Bson query = eq("name", policy); - try { - 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); - } - } } \ No newline at end of file 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 cd0362daa4230e6f2e2acd66c2b03631f19b2629..9cf0d8f4064220b9c8692e37f7fc7f25b2797d89 100644 --- a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java @@ -3,23 +3,11 @@ package api.test.rest.tsa.task; import api.test.core.BaseStepDefinitions; import api.test.rest.RestGeneralStepDefinitions; import api.test.rest.RestSessionContainer; -import com.mongodb.MongoException; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.result.DeleteResult; import core.*; import cucumber.api.java.en.And; import cucumber.api.java.en.Given; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.bson.Document; -import org.bson.conversions.Bson; -import org.bson.types.ObjectId; - -import static api.test.rest.tsa.policy.PolicyStepDefinitions.mongoConnection; -import static com.mongodb.client.model.Filters.eq; public class TaskStepDefinitions extends BaseStepDefinitions{ private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); @@ -42,17 +30,6 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ currentRequest.setContentType("application/json"); } - @Given("^I upload a task template \\{(.*?)\\} to repository$") - public void iUploadATaskTemplateToRepository(String task) { - MongoClient client = MongoClients.create(mongoConnection); - MongoDatabase database = client.getDatabase("task"); - MongoCollection<Document> policies = database.getCollection("taskTemplates"); - Document test = new Document("_id", new ObjectId()) - .append("name", task) - .append("requestPolicy", "example/resolve/1.0"); - policies.insertOne(test); - } - @And("^I send the current request to endpoint \\{(.*?)\\} with container value\\{(.*?)\\}$") public void I_send_the_current_request_to_endpoint_with_container_value(String endpoint, String suffix) throws Throwable { currentRequest.setPath(endpoint +"/"+ getDataContainer().getObject(suffix)); @@ -61,18 +38,4 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ addRequest(currentRequest); addResponse(response); } - - @And("^delete task \\{(.*)\\} from repository$") - public void deletePolicyTestFromRepository(String task) { - MongoClient client = MongoClients.create(mongoConnection); - MongoDatabase database = client.getDatabase("task"); - MongoCollection<Document> policies = database.getCollection("taskTemplates"); - Bson query = eq("name", task); - try { - 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/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature index 080bb9e791181a04edd71127c70cec8157687806..6facb008ce5682e24f4eba45f15a650c68d6f9c3 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,42 +31,34 @@ 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 upload a policy {test1} to repository - Then I load the REST request {Policy.json} with profile {successful_evaluate} - And I execute the policy {/policy/testable/test1/2.0/evaluation} + Given I load the REST request {Policy.json} with profile {successful_evaluate} + And I execute the policy {/policy/example/test/1.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 {result.allow} has the value {true} - And delete policy {test1} from repository @bug @issue-35 Scenario: TSA - DID resolution - Positive - Given I upload a DID resolver policy to repository - Then I load the REST request {Policy.json} with profile {didResolve_evaluate} + Given I load the REST request {Policy.json} with profile {didResolve_evaluate} And I execute the policy {/policy/example/resolve/1.0/evaluation} Then the status code should be {200} And the response is valid according to the {Policy_EvaluateDID_schema.json} REST schema And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} - And delete policy {resolve} from repository @negative Scenario: TSA - Evaluate policy with incorrect value - Negative - Given I upload a policy {test6} to repository - Then I load the REST request {Policy.json} with profile {unsuccessful_evaluate} - And I execute the policy {/policy/testable/test6/2.0/evaluation} + Given I load the REST request {Policy.json} with profile {unsuccessful_evaluate} + And I execute the policy {/policy/example/test/1.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 {result.allow} has the value {false} - And delete policy {test6} from repository @negative Scenario: TSA - Evaluate policy with missing body- Negative - Given I upload a policy {test7} to repository - And I execute the policy {/policy/testable/test7/2.0/evaluation} + Given I execute the policy {/policy/example/test/1.0/evaluation} Then the status code should be {400} And the response is valid according to the {Policy_Evaluate_negative_schema.json} REST schema And the field {message} has the value {missing required payload} - And delete policy {test7} from repository @negative Scenario: TSA - Evaluate missing policy - Negative @@ -78,10 +70,8 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative @bug @issue-35 Scenario: TSA - DID resolution with incorrect did - Negative - Given I upload a DID resolver policy to repository Then I load the REST request {Policy.json} with profile {didResolve_missing_method} And I execute the policy {/policy/example/resolve/1.0/evaluation} 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 {result.data.didResolutionMetadata.error} has the value {notFound} - And delete policy {resolve} from repository 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 7de3e01dd6b94174a6d1f78f6a149d2426090424..98592b36e4e7529297646de59512ac6ed8515d5b 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,14 +26,12 @@ Feature: API - TSA - Policy - :group/:name/:version/lock DELETE Given we are testing the TSA Policy Api Scenario: TSA - Unlock policy - Positive - Given I upload a policy {test4} to repository - When I lock the policy {/policy/testable/test4/2.0/lock} - And I unlock the policy {/policy/testable/test4/2.0/lock} + When I lock the policy {/policy/example/test/1.0/lock} + And I unlock the policy {/policy/example/test/1.0/lock} And the status code should be {200} - And delete policy {test4} from repository @negative Scenario: TSA - Unlock none existing policy - Negative - When I unlock the policy {/policy/testable/test8/2.0/lock} + When I unlock the policy {/policy/example/non_existing/1.0/lock} 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 6496e9b6a2eabfdb638465ac2967a5d2b8a00457..5aea20e16541f864122a3c069937c15306c0bbf7 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,24 +31,20 @@ Feature: API - TSA -Policy - :group/:name/:version/lock POST Given we are testing the TSA Policy Api Scenario: TSA - Lock policy - Positive - Given I upload a policy {test2} to repository - When I lock the policy {/policy/testable/test2/2.0/lock} + When I lock the policy {/policy/example/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 {/policy/testable/test2/2.0/evaluation} + And I execute the policy {/policy/example/test/1.0/evaluation} Then the status code should be {403} - And I lock the policy {/policy/testable/test2/2.0/lock} + 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/testable/test2/2.0/lock} - And delete policy {test2} from repository + And I unlock the policy {/policy/example/test/1.0/lock} @negative Scenario: TSA - Lock already locked policy - Negative - Given I upload a policy {test3} to repository - When I lock the policy {/policy/testable/test3/2.0/lock} - And I lock the policy {/policy/testable/test3/2.0/lock} + When I lock the policy {/policy/example/test/1.0/lock} + 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/testable/test3/2.0/lock} - And delete policy {test3} from repository + And I unlock the policy {/policy/example/test/1.0/lock} 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 0fdc7bb5bf486c2da2f041fa61f36dc9ef9cb043..446f7dcb925295d22d5810b124747b5bec333436 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 @@ -32,9 +32,7 @@ Feature: API -TSA - Task - v1/task GET @bug @issue-35 Scenario: TSA - Executing Task with DID resolver and Evaluate the Cache - Positive - Given I upload a DID resolver policy to repository - And I upload a task template {didResolve} to repository - Then I load the REST request {Policy.json} with profile {didResolve_evaluate} + 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} Then the status code should be {200} And the response is valid according to the {Task_Execute_schema.json} REST schema @@ -51,6 +49,4 @@ Feature: API -TSA - Task - v1/task GET And I send the current request as GET to endpoint {http://localhost:8083/v1/cache} And the status code should be {200} And the response is valid according to the {Task_ExecuteDID_schema.json} REST schema - And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} - Then delete task {didResolve} from repository - And delete policy {resolve} from repository \ No newline at end of file + And the field {result.data.didDocument.id} has the value {did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE} \ No newline at end of file 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 84ecc844d3d82fcd8161a5d43c293c19b4ecb2e7..2d135477d9a5a126845573e0cf2bc1ff952906ee 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 @@ -32,8 +32,6 @@ Feature: API -TSA - Task - v1/task POST @bug @issue-35 Scenario: TSA - Executing Task with DID resolver - Positive - Given I upload a DID resolver policy to repository - And I upload a task template {didResolve} to repository 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} Then the status code should be {200} @@ -48,9 +46,7 @@ Feature: API -TSA - Task - v1/task POST @negative Scenario: TSA - Executing Task with non existing task template - Negative - Given I upload a DID resolver policy to repository 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} 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} - And delete policy {resolve} from repository