Skip to content
Snippets Groups Projects
Unverified Commit e0bc0960 authored by Georgi Michev's avatar Georgi Michev
Browse files

remove mongo interactions


Signed-off-by: default avatargeorgi.michev <georgi.michev@vereign.com>
parent 5d294fca
No related branches found
No related tags found
1 merge request!21remove mongo interactions
......@@ -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
......@@ -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
......@@ -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);
}
}
}
......@@ -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
......@@ -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}
......@@ -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}
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment