diff --git a/.gitignore b/.gitignore index 13cb8527de5be59f11ce387f7a885623b82ed6cd..cf8e193b86d560afadbb4f86fc753430ecda6d74 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ build/reports/ build/test-results/ build/tmp/ reports/ + +devRun.sh diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json index c364041a99798a495bc7bcd64fd3ad01a9250e1c..9ecb0593386ec8ed0a00c21274a2182f5d2314f3 100644 --- a/src/main/resources/REST/json/Policy.json +++ b/src/main/resources/REST/json/Policy.json @@ -7,5 +7,8 @@ }, "didResolve_evaluate": { "did":"did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE" + }, + "didResolve_missing_method": { + "did":"did:idunion:BDrEcHc8Tb4Lb2VyQZWEDE" } } \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json b/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..f8694063f96579419c3537036404d7c1f2c375f3 --- /dev/null +++ b/src/main/resources/REST/schemas/Policy_EvaluateDID_negative_schema.json @@ -0,0 +1,48 @@ +{ + "$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 diff --git a/src/main/resources/REST/schemas/Policy_Evaluate_negative_schema.json b/src/main/resources/REST/schemas/Policy_Evaluate_negative_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..2bb8c406d714067ca7ceb26e548c69aa0b82fc79 --- /dev/null +++ b/src/main/resources/REST/schemas/Policy_Evaluate_negative_schema.json @@ -0,0 +1,20 @@ +{ + "$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 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 9af270fb21a9c4fd63acfc630c04bd1b96d14b15..866469f94077a5b56647587468fc3f0a577382d5 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -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); diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature index 7d045850ff8146a24cee0898ad7e35f41805503e..c88320c1589a7316e5ca534f27bc8417ccf14e47 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -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 diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature index 53af9ca35b034f5909c718db58d56849046ab600..f9edd19a7adf1130419e7bf03f6ce88f2c661e4e 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/DELETE.feature @@ -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} diff --git a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature index d266862d524610c8f6903d23dda5423a9b59a4cb..153569a8098a26788fe9f630367af21b5bc57f96 100644 --- a/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature +++ b/src/test/resources/features/tsa/policy/{group}/{name}/{version}/lock/POST.feature @@ -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}