From a89c82140e5310521b3364c7f8cd607526a3b1cb Mon Sep 17 00:00:00 2001
From: michev <georgi.michev@vereign.com>
Date: Tue, 25 Oct 2022 10:31:21 +0300
Subject: [PATCH] Add tests for evaluating policies and setting cache using
 header.

Testing the following features:
https://gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/-/issues/8
https://gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/-/issues/6

Signed-off-by: michev <georgi.michev@vereign.com>
---
 src/main/resources/REST/json/Policy.json         |  3 ++-
 .../features/tsa/cache/v1/cache/GET.feature      | 14 ++++++++++++++
 .../{name}/{version}/evaluation/POST.feature     | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/main/resources/REST/json/Policy.json b/src/main/resources/REST/json/Policy.json
index e1f37e85..f91bc352 100644
--- a/src/main/resources/REST/json/Policy.json
+++ b/src/main/resources/REST/json/Policy.json
@@ -13,5 +13,6 @@
   },
   "did_missing_method": {
     "did":"did:idunion:BDrEcHc8Tb4Lb2VyQZWEDE"
-  }
+  },
+  "empty": {}
 }
\ No newline at end of file
diff --git a/src/test/resources/features/tsa/cache/v1/cache/GET.feature b/src/test/resources/features/tsa/cache/v1/cache/GET.feature
index 5ddbbc60..21433fd9 100644
--- a/src/test/resources/features/tsa/cache/v1/cache/GET.feature
+++ b/src/test/resources/features/tsa/cache/v1/cache/GET.feature
@@ -40,6 +40,20 @@ Feature: API -TSA - Cache - v1/cache GET
     Then the status code should be {200}
     And the field {msg} has the value {successful setting the cache}
 
+    @test
+  Scenario: TSA - using header values for setting TTL on cache - Positive
+    When I load the REST request {Cache.json} with profile {successful_set}
+    And I load value {test} into current request HEADER {x-cache-key}
+    And I load value {10} into current request HEADER {x-cache-ttl}
+    And I send the Cache POST request via TSA Cache API
+    And the status code should be {201}
+    Then I clear the request body
+    And I send the Cache GET request via TSA Cache API
+    Then the status code should be {200}
+    When I wait for {10000} mseconds
+    And I send the Cache GET request via TSA Cache API
+    Then the status code should be {404}
+
   @negative
   Scenario: TSA - Access non existing Cache - Negative
     Given I load value {NEGATIVE} into current request HEADER {x-cache-key}
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 ae395f1a..cdf1f3f8 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
@@ -44,6 +44,22 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST
     And the response is valid according to the {Policy_EvaluateDID_schema.json} REST schema
     And the field {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6}
 
+  Scenario: TSA - using header values for policy execution - Positive
+    When I load the REST request {Policy.json} with profile {empty}
+    And I load value {someValue} into current request HEADER {X-Cache-Key}
+    And I execute the Policy group {example} name {getHeader} version {1.0} via TSA Policy API
+    Then the status code should be {200}
+    And the field {key} has the value {someValue}
+
+  Scenario: TSA - using multiple header values for policy execution - Positive
+    When I load the REST request {Policy.json} with profile {empty}
+    And I load value {someValue} into current request HEADER {X-Cache-Key}
+    And I load value {another-value} into current request HEADER {X-Another-Header}
+    And I execute the Policy group {example} name {getMultiHeaders} version {1.0} via TSA Policy API
+    Then the status code should be {200}
+    And the field {key} has the value {someValue}
+    And the field {another} has the value {another-value}
+
   @negative
   Scenario: TSA - Evaluate policy with incorrect value - Negative
     When I load the REST request {Policy.json} with profile {incorrect_message}
-- 
GitLab