commit fb98740300f28a0a29fd36e5f9ba133bdae98ede
Author: Captain_Trojan <sejakm@students.zcu.cz>
Date:   Wed Apr 7 00:50:29 2021 +0200

    Re #8476 - Added and tested `get_certificate(id)`.

diff --git a/app.py b/app.py
index 92b1c07..d48e539 100644
--- a/app.py
+++ b/app.py
@@ -20,6 +20,11 @@ def get_cert_list():
     return CertController.get_certificate_list()
 
 
+@app.route('/api/certificates/<id>', methods=["GET"])
+def get_cert(id):
+    return CertController.get_certificate_by_id(id)
+
+
 if __name__ == '__main__':
     host = "0.0.0.0"
     port = 5000
diff --git a/src/controllers/certificates_controller.py b/src/controllers/certificates_controller.py
index c06abb1..59d76a5 100644
--- a/src/controllers/certificates_controller.py
+++ b/src/controllers/certificates_controller.py
@@ -156,9 +156,17 @@ class CertController:
         """
         CertController.setup()  # TODO remove after issue fixed
 
-        if connexion.request.is_json:
-            id = IdParameter.from_dict(connexion.request.get_json())  # noqa: E501
-        return 'do some magic!'
+        try:
+            v = int(id)
+        except ValueError:
+            return E_WRONG_PARAMETERS, 400
+
+        cert = CERTIFICATE_SERVICE.get_certificate(v)
+
+        if cert is None:
+            return E_NO_CERTIFICATES_FOUND, 205                 # TODO related to 204 issue
+        else:
+            return {"success": True, "data": cert.pem_data}
 
     @staticmethod
     def get_certificate_details_by_id(id):  # noqa: E501
@@ -217,7 +225,7 @@ class CertController:
         if certs is None:
             return E_GENERAL_ERROR, 500
         elif len(certs) == 0:
-            return E_NO_CERTIFICATES_FOUND, 204
+            return E_NO_CERTIFICATES_FOUND, 205         # TODO related to 204 issue
         else:
             ret = []
             for c in certs:
diff --git a/tests/unit_tests/rest_api/certificates.py b/tests/unit_tests/rest_api/certificates.py
index 170e10a..c5162b2 100644
--- a/tests/unit_tests/rest_api/certificates.py
+++ b/tests/unit_tests/rest_api/certificates.py
@@ -120,6 +120,37 @@ def test_invalid_params_3(server):
     assert not d["success"]
 
 
+def test_invalid_params_4(server):
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "CA": 80081358008135,
+        "subject": {
+            "C": "CZ",
+            "CN": "Root CA s.r.o.",
+            "L": "Pilsen",
+            "O": "Root CA s.r.o.",
+            "OU": "IT department",
+            "ST": "Pilsen",
+            "emailAddress": "root@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    })
+
+    assert ret.status_code == 400
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == "No certificate authority with such unique ID exists."
+    assert "success" in d
+    assert not d["success"]
+
+
 def test_root_inter_ca(server):
     ret = server.post("/api/certificates", content_type="application/json", json={
         "subject": {
@@ -305,4 +336,38 @@ def test_filtering(server):
 
     assert d[0]['issuer']['id'] == 1
     assert d[1]['issuer']['id'] == 2
-    assert d[2]['issuer']['id'] == 2
\ No newline at end of file
+    assert d[2]['issuer']['id'] == 2
+
+
+def test_get_one(server):
+    ret = server.get("/api/certificates/1")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json["data"]
+
+    assert str(d).startswith("-----BEGIN CERTIFICATE-----")
+
+
+def test_get_one_bad_param(server):
+    ret = server.get("/api/certificates/whoopsie")
+
+    assert ret.status_code == 400
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert not ret.json["success"]
+    assert ret.json["data"] == "Invalid request, wrong parameters."
+
+
+def test_get_one_bad_param_2(server):
+    ret = server.get("/api/certificates/805")
+
+    assert ret.status_code == 205
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert not ret.json["success"]
+    assert ret.json["data"] == "No certificates found."
\ No newline at end of file
