From 6ebdd55319afaa76c066d4633c3263da888aba8e Mon Sep 17 00:00:00 2001
From: "georgi.michev" <georgi.michev@vereign.com>
Date: Sun, 3 Jul 2022 21:25:13 +0300
Subject: [PATCH] apply signer test

Signed-off-by: georgi.michev <georgi.michev@vereign.com>
---
 src/main/java/core/JsonUtils.java             |  8 +++
 .../schemas/Signer_GetAllKeys_schema.json     | 53 ++++++++++++++++++
 .../Signer_GetKey_negative_schema.json        | 16 ++++++
 .../REST/schemas/Signer_GetKey_schema.json    | 48 ++++++++++++++++
 .../tsa/signer/SignerStepDefinitions.java     | 56 +++++++++++++++++++
 .../tsa/signer/v1/issuerDID/GET.feature       | 31 ++++++++++
 .../features/tsa/signer/v1/keys/GET.feature   | 47 ++++++++++++++++
 7 files changed, 259 insertions(+)
 create mode 100644 src/main/resources/REST/schemas/Signer_GetAllKeys_schema.json
 create mode 100644 src/main/resources/REST/schemas/Signer_GetKey_negative_schema.json
 create mode 100644 src/main/resources/REST/schemas/Signer_GetKey_schema.json
 create mode 100644 src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java
 create mode 100644 src/test/resources/features/tsa/signer/v1/issuerDID/GET.feature

diff --git a/src/main/java/core/JsonUtils.java b/src/main/java/core/JsonUtils.java
index 2c6828a9..3a5809bf 100644
--- a/src/main/java/core/JsonUtils.java
+++ b/src/main/java/core/JsonUtils.java
@@ -244,6 +244,14 @@ public class JsonUtils {
         return System.getProperty("baseUrl") + "/cache";
     }
 
+    /**
+     * Get the url for "TSA Signer"
+     * @return the uri
+     */
+    public static String getTSASigner() {
+        return System.getProperty("baseUrl") + "/signer";
+    }
+
     /**
      * Get the url for "TSA Task"
      * @return the uri
diff --git a/src/main/resources/REST/schemas/Signer_GetAllKeys_schema.json b/src/main/resources/REST/schemas/Signer_GetAllKeys_schema.json
new file mode 100644
index 00000000..3461756d
--- /dev/null
+++ b/src/main/resources/REST/schemas/Signer_GetAllKeys_schema.json
@@ -0,0 +1,53 @@
+{
+  "$schema": "http://json-schema.org/draft-04/schema#",
+  "type": "array",
+  "items": [
+    {
+      "type": "object",
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "type": {
+          "type": "string"
+        },
+        "controller": {
+          "type": "string"
+        },
+        "publicKeyJwk": {
+          "type": "object",
+          "properties": {
+            "kty": {
+              "type": "string"
+            },
+            "kid": {
+              "type": "string"
+            },
+            "crv": {
+              "type": "string"
+            },
+            "x": {
+              "type": "string"
+            },
+            "y": {
+              "type": "string"
+            }
+          },
+          "required": [
+            "kty",
+            "kid",
+            "crv",
+            "x",
+            "y"
+          ]
+        }
+      },
+      "required": [
+        "id",
+        "type",
+        "controller",
+        "publicKeyJwk"
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/src/main/resources/REST/schemas/Signer_GetKey_negative_schema.json b/src/main/resources/REST/schemas/Signer_GetKey_negative_schema.json
new file mode 100644
index 00000000..93ff0d60
--- /dev/null
+++ b/src/main/resources/REST/schemas/Signer_GetKey_negative_schema.json
@@ -0,0 +1,16 @@
+{
+  "$schema": "http://json-schema.org/draft-04/schema#",
+  "type": "object",
+  "properties": {
+    "id": {
+      "type": "string"
+    },
+    "kind": {
+      "type": "integer"
+    }
+  },
+  "required": [
+    "id",
+    "kind"
+  ]
+}
\ No newline at end of file
diff --git a/src/main/resources/REST/schemas/Signer_GetKey_schema.json b/src/main/resources/REST/schemas/Signer_GetKey_schema.json
new file mode 100644
index 00000000..214a754b
--- /dev/null
+++ b/src/main/resources/REST/schemas/Signer_GetKey_schema.json
@@ -0,0 +1,48 @@
+{
+  "$schema": "http://json-schema.org/draft-04/schema#",
+  "type": "object",
+  "properties": {
+    "id": {
+      "type": "string"
+    },
+    "type": {
+      "type": "string"
+    },
+    "controller": {
+      "type": "string"
+    },
+    "publicKeyJwk": {
+      "type": "object",
+      "properties": {
+        "kty": {
+          "type": "string"
+        },
+        "kid": {
+          "type": "string"
+        },
+        "crv": {
+          "type": "string"
+        },
+        "x": {
+          "type": "string"
+        },
+        "y": {
+          "type": "string"
+        }
+      },
+      "required": [
+        "kty",
+        "kid",
+        "crv",
+        "x",
+        "y"
+      ]
+    }
+  },
+  "required": [
+    "id",
+    "type",
+    "controller",
+    "publicKeyJwk"
+  ]
+}
\ No newline at end of file
diff --git a/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java
new file mode 100644
index 00000000..da72e92f
--- /dev/null
+++ b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java
@@ -0,0 +1,56 @@
+package api.test.rest.tsa.signer;
+
+import api.test.core.BaseStepDefinitions;
+import api.test.rest.RestGeneralStepDefinitions;
+import api.test.rest.RestSessionContainer;
+import core.*;
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.When;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class SignerStepDefinitions  extends BaseStepDefinitions {
+    private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName());
+    RestSessionContainer restSessionContainer;
+    Request currentRequest;
+
+    public SignerStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) {
+        super(dataContainer);
+        this.restSessionContainer = restSessionContainer;
+        this.currentRequest = currentRequest;
+    }
+
+    @Given("we are testing the TSA Signer Api")
+    public void weAreTestingTheTSASignerApi() {
+        RestClient.setDefaultEncoding("UTF8");
+        RestClient.setBaseURI(JsonUtils.getTSASigner());
+        RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false);
+        currentRequest.clear();
+        currentRequest.getHeaders().put("X-Client-UserAgent", "test framework");
+        currentRequest.setContentType("application/json");
+    }
+
+    @When("I get all keys via TSA Signer API")
+    public void iGetAllKeysViaTSASignerAPI() {
+        currentRequest.setPath("/v1/keys");
+        Response response = RestClient.get(currentRequest);
+        addRequest(currentRequest);
+        addResponse(response);
+    }
+
+    @When("^I get key \\{(.*)\\} via TSA Signer API$")
+    public void iGetKeyViaTSASignerAPI(String key) {
+        currentRequest.setPath("/v1/keys/" + key);
+        Response response = RestClient.get(currentRequest);
+        addRequest(currentRequest);
+        addResponse(response);
+    }
+
+    @When("I get issuer DID via TSA Signer API")
+    public void iGetSignerDIDViaTSASignerAPI() {
+        currentRequest.setPath("/v1/issuerDID");
+        Response response = RestClient.get(currentRequest);
+        addRequest(currentRequest);
+        addResponse(response);
+    }
+}
diff --git a/src/test/resources/features/tsa/signer/v1/issuerDID/GET.feature b/src/test/resources/features/tsa/signer/v1/issuerDID/GET.feature
new file mode 100644
index 00000000..831a682b
--- /dev/null
+++ b/src/test/resources/features/tsa/signer/v1/issuerDID/GET.feature
@@ -0,0 +1,31 @@
+#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/>.
+
+#https://gaiax.vereign.com/tsa/signer/v1/issuerDID
+#Author: Georgi Michev georgi.michev@vereign.com
+
+@rest @all @tsa @signer
+Feature: API -TSA - Signer Issuer DID - v1/keys POST
+  As user
+  I want to see what keys are available
+  So I am able to use them the future
+
+  Background:
+    Given we are testing the TSA Signer Api
+
+  Scenario: TSA - Getting Issuer DID - Positive
+    When I get issuer DID via TSA Signer API
+    And the status code should be {200}
+    And the field {did} has the value {did:web:gaiax.vereign.com:tsa:policy:policy:example:returnDID:1.0:evaluation}
\ No newline at end of file
diff --git a/src/test/resources/features/tsa/signer/v1/keys/GET.feature b/src/test/resources/features/tsa/signer/v1/keys/GET.feature
index e69de29b..58d5a1a1 100644
--- a/src/test/resources/features/tsa/signer/v1/keys/GET.feature
+++ b/src/test/resources/features/tsa/signer/v1/keys/GET.feature
@@ -0,0 +1,47 @@
+#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/>.
+
+#https://gaiax.vereign.com/tsa/signer/v1/keys
+#Author: Georgi Michev georgi.michev@vereign.com
+
+@rest @all @tsa @signer
+Feature: API -TSA - Signer keys - v1/keys POST
+  As user
+  I want to see what keys are available
+  So I am able to use them the future
+
+  Background:
+    Given we are testing the TSA Signer Api
+
+  Scenario: TSA - Getting all keys from Singer - Positive
+    When I get all keys via TSA Signer API
+    And the status code should be {200}
+    And the response is valid according to the {Signer_GetAllKeys_schema.json} REST schema
+    And the field {$..type} has the value {["JsonWebKey2020","JsonWebKey2020"]}
+    And the field {$..publicKeyJwk.kid} has the value {["key1","key2"]}
+    And the field {$..publicKeyJwk.crv} has the value {["P-256","Ed25519"]}
+
+  Scenario: TSA - Getting key1 from Singer - Positive
+    When I get key {key1} via TSA Signer API
+    And the status code should be {200}
+    And the response is valid according to the {Signer_GetKey_schema.json} REST schema
+    And the field {type} has the value {JsonWebKey2020}
+    And the field {publicKeyJwk.kid} has the value {key1}
+    And the field {publicKeyJwk.crv} has the value {P-256}
+
+  Scenario: TSA - Getting non existing key - Negative
+    When I get key {non_existing} via TSA Signer API
+    And the response is valid according to the {Signer_GetKey_negative_schema.json} REST schema
+    And the status code should be {404}
-- 
GitLab