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

add more negative tests and refactor

parent a3cace0c
No related branches found
No related tags found
1 merge request!15remove test results, initiate evaluate policy sync
......@@ -72,3 +72,5 @@ build/reports/
build/test-results/
build/tmp/
reports/
devRun.sh
......@@ -7,5 +7,8 @@
},
"didResolve_evaluate": {
"did":"did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE"
},
"didResolve_missing_method": {
"did":"did:idunion:BDrEcHc8Tb4Lb2VyQZWEDE"
}
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"@context": {
"type": "string"
},
"didDocument": {
"type": "null"
},
"didDocumentMetadata": {
"type": "object"
},
"didResolutionMetadata": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"error": {
"type": "string"
},
"errorMessage": {
"type": "string"
}
},
"required": [
"contentType",
"error",
"errorMessage"
]
}
},
"required": [
"@context",
"didDocument",
"didDocumentMetadata",
"didResolutionMetadata"
]
}
},
"required": [
"data"
]
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"kind": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"id",
"kind",
"message"
]
}
\ No newline at end of file
......@@ -47,6 +47,7 @@ import static com.mongodb.client.model.Filters.eq;
public class PolicyStepDefinitions extends BaseStepDefinitions {
private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName());
public static final String mongoConnection = "mongodb://root:root@localhost:27017";
RestSessionContainer restSessionContainer;
Request currentRequest;
......@@ -58,7 +59,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
@When("^I upload a policy \\{(.*)\\} to repository$")
public void iUploadThePolicyToRepository(String policy) throws Throwable {
MongoClient client = MongoClients.create("mongodb://root:root@localhost:27017");
MongoClient client = MongoClients.create(mongoConnection);
MongoDatabase database = client.getDatabase("policy");
MongoCollection<Document> policies = database.getCollection("policies");
Document test = new Document("_id", new ObjectId())
......@@ -71,13 +72,12 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
"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);
}
@Given("I upload a DID resolver policy to repository")
public void iUploadADIDResolverPolicyDidResolverToRepository() {
MongoClient client = MongoClients.create("mongodb://root:root@localhost:27017");
MongoClient client = MongoClients.create(mongoConnection);
MongoDatabase database = client.getDatabase("policy");
MongoCollection<Document> policies = database.getCollection("policies");
Document test = new Document("_id", new ObjectId())
......@@ -92,14 +92,6 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
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);
......@@ -108,10 +100,6 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
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);
......@@ -130,7 +118,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
@And("^delete policy \\{(.*)\\} from repository$")
public void deletePolicyTestFromRepository(String policy) {
MongoClient client = MongoClients.create("mongodb://root:root@localhost:27017");
MongoClient client = MongoClients.create(mongoConnection);
MongoDatabase database = client.getDatabase("policy");
MongoCollection<Document> policies = database.getCollection("policies");
Bson query = eq("name", policy);
......
......@@ -13,11 +13,12 @@
#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
#http://localhost:8081/policy/:group/:name/:version/evaluation
#Author: Georgi Michev georgi.michev@vereign.com
@rest @all @tsa @policy
Feature: As user
Feature: API -TSA - Policy - :group/:name/:version/evaluation POST
As user
I want to evaluate the policy
So I am able to execute it in the future
......@@ -28,12 +29,9 @@ 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}
......@@ -52,14 +50,39 @@ Feature: As user
And the field {taskID} has the value {01234567}
And delete policy {resolve} from repository
Scenario: TSA - Evaluate policy synchronously - Negative
@negative
Scenario: TSA - Evaluate policy with incorrect value - 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
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 {/testable/test7/2.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 @wip
Scenario: TSA - Evaluate missing policy - Negative
Given I execute the policy {/testable/test0/2.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 {policy not found}
@negative
Scenario: TSA - DID resolution - 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 {/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 {data.didResolutionMetadata.error} has the value {notFound}
And delete policy {resolve} from repository
......@@ -13,17 +13,17 @@
#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
#http://localhost:8081/policy/:group/:name/:version/lock
#Author: Georgi Michev georgi.michev@vereign.com
@rest @all @tsa @policy @lock
Feature: As user
Feature: API - TSA - Policy - :group/:name/:version/lock DELETE
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
Scenario: TSA - Unlock policy - Positive
Given I upload a policy {test4} to repository
......@@ -32,10 +32,8 @@ Feature: As user
And the status code should be {200}
And delete policy {test4} from repository
Scenario: TSA - Unlock already unlocked policy - Negative
Given I upload a policy {test5} to repository
When I unlock the policy {/testable/test5/2.0/lock}
And I unlock the policy {/testable/test5/2.0/lock}
And the status code should be {403}
And the field {message} has the value {policy is unlocked}
And delete policy {test5} from repository
@negative
Scenario: TSA - Unlock none existing policy - Negative
When I unlock the policy {/testable/test8/2.0/lock}
And the status code should be {404}
And the field {message} has the value {policy not found}
......@@ -13,11 +13,12 @@
#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
#http://localhost:8081/policy/:group/:name/:version/lock
#Author: Georgi Michev georgi.michev@vereign.com
@rest @all @tsa @policy @lock
Feature: As user
Feature: API - TSA -Policy - :group/:name/:version/lock POST
As user
I want to evaluate the policy
So I am able to execute it in the future
......@@ -42,6 +43,7 @@ Feature: As user
And I unlock the policy {/testable/test2/2.0/lock}
And delete policy {test2} from repository
@negative
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}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment