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

policy add negative test

parent 70b5b75a
No related branches found
No related tags found
1 merge request!15remove test results, initiate evaluate policy sync
{
"successful_evaluate": {
"message": "hello world"
},
"unsuccessful_evaluate": {
"message": "wrong value!"
}
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"allow": {
"type": "boolean"
},
"taskID": {
"type": "string"
}
},
"required": [
"allow",
"taskID"
]
}
\ No newline at end of file
......@@ -27,6 +27,7 @@ import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.*;
import exceptions.RAFException;
import org.apache.commons.collections.FactoryUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
......@@ -741,7 +742,6 @@ public class GeneralStepDefinitions extends BaseStepDefinitions {
*/
@And("^the field \\{(.*?)\\} is present and not empty$")
public void the_field_is_present_and_not_empty(String jsonPath) throws Throwable {
Configuration conf = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
ReadContext responseContext = JsonPath.using(conf).parse(getLastResponse().getBody());
......
......@@ -67,7 +67,11 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
.append("group", "testable")
.append("version", "2.0")
.append("locked", false)
.append("rego", "package testable."+ policy +"\n\t\t\n allow {\n 1 == 1\n }\n\n taskID := \"0123456789abcdef\"\n ");
.append("rego", "package testable."+ policy +"\n" +
"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);
}
......@@ -114,7 +118,7 @@ public class PolicyStepDefinitions extends BaseStepDefinitions {
MongoCollection<Document> policies = database.getCollection("policies");
Bson query = eq("name", policy);
try {
DeleteResult result = policies.deleteMany(query);
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);
......
#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/>.
#http://localhost:8081/policy
#Author: Georgi Michev georgi.michev@vereign.com
@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
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}
And the response is valid according to the {Policy_Evaluate_schema.json} REST schema
And the field {allow} has the value {true}
And the field {taskID} has the value {0123456}
And delete policy {test1} from repository
Scenario: TSA - Evaluate policy synchronously - 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
......@@ -16,7 +16,7 @@
#http://localhost:8081/policy
#Author: Georgi Michev georgi.michev@vereign.com
@rest @all @tsa @policy
@rest @all @tsa @policy @lock
Feature: As user
I want to evaluate the policy
So I am able to execute it in the future
......@@ -28,20 +28,7 @@ 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}
And the field {allow} has the value {true}
And the field {taskID} is present and not empty
And delete policy {test1} from repository
@lock
Scenario: TSA - Lock policy - Positive
Given I upload a policy {test2} to repository
When I lock the policy {/testable/test2/2.0/lock}
......@@ -55,7 +42,6 @@ Feature: As user
And I unlock the policy {/testable/test2/2.0/lock}
And delete policy {test2} from repository
@lock
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