commit da8c37535046cd1ce4086c37d4af1704e8bd6111
Author: Captain_Trojan <sejakm@students.zcu.cz>
Date:   Sun May 2 16:11:53 2021 +0200

    Re #8702 - Added filtering/pagination tests.

diff --git a/tests/integration_tests/rest_api/certificates_test.py b/tests/integration_tests/rest_api/certificates_test.py
index 4f31502..9b0c36d 100644
--- a/tests/integration_tests/rest_api/certificates_test.py
+++ b/tests/integration_tests/rest_api/certificates_test.py
@@ -342,8 +342,8 @@ def test_sign_by_non_ca(server):
     assert d["success"]
 
 
-def test_filtering(server):
-    ret = server.get("/api/certificates?filtering=%7B%22CA%22:true%7D")
+def test_filtering_url(server):
+    ret = server.get("/api/certificates?filtering=%7B%22type%22%3A%20%5B%22root%22%2C%20%22inter%22%5D%7D")
 
     assert ret.status_code == 200
 
@@ -355,7 +355,9 @@ def test_filtering(server):
 
     assert all(c["usage"]["CA"] for c in d)
 
-    ret = server.get("/api/certificates", json={"filtering": {"CA": True}})
+
+def test_filtering_multi(server):
+    ret = server.get("/api/certificates", json={"filtering": {"type": ["root", "inter"]}})
 
     assert ret.status_code == 200
 
@@ -368,8 +370,7 @@ def test_filtering(server):
     assert all(c["usage"]["CA"] for c in d)
 
     all_certs_expected = list(d)
-
-    ret = server.get("/api/certificates", json={"filtering": {"CA": False}})
+    ret = server.get("/api/certificates", json={"filtering": {"type": ["end"]}})
 
     assert ret.status_code == 200
 
@@ -395,8 +396,8 @@ def test_filtering(server):
     all_certs_actual = ret.json["data"]
 
     assert len(all_certs_actual) == len(all_certs_expected)
-    # TODO assert set(all_certs_expected) == set(all_certs_actual) or something like that instead
 
+def test_filtering_issuer(server):
     ret = server.get("/api/certificates", json={"filtering": {"issuedby": 2}})
     assert ret.status_code == 200
     assert "data" in ret.json
@@ -406,7 +407,9 @@ def test_filtering(server):
     assert len(issued_by_2) == 2
     assert set(issued_by_2[i]["id"] for i in range(2)) == {3, 8}
 
-    ret = server.get("/api/certificates", json={"filtering": {"issuedby": 2, "CA": True}})
+
+def test_filtering_issuer_type(server):
+    ret = server.get("/api/certificates", json={"filtering": {"issuedby": 2, "type": ["root", "inter"]}})
     assert ret.status_code == 200
     assert "data" in ret.json
     assert "success" in ret.json
@@ -416,6 +419,84 @@ def test_filtering(server):
     assert issued_by_2[0]["id"] == 3
 
 
+def test_filtering_pagination(server):
+    certs = []
+    for i in range(3):
+        ret = server.get("/api/certificates", json={"page": i, "per_page": 2})
+        assert ret.status_code == 200
+        assert "data" in ret.json
+        assert "success" in ret.json
+        assert ret.json["success"]
+        certs += ret.json["data"]
+
+    ret = server.get("/api/certificates", json={"page": 0, "per_page": 6})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+    assert certs == ret.json["data"]
+
+
+def test_filtering_usage_1(server):
+    ret = server.get("/api/certificates", json={"filtering": {"usage": ["CA", "digitalSignature"]}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all(c["usage"]["CA"] or c["usage"]["digitalSignature"] for c in ret.json["data"])
+
+
+def test_filtering_usage_2(server):
+    ret = server.get("/api/certificates", json={"filtering": {"usage": ["CA", "SSL"]}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all(c["usage"]["CA"] or c["usage"]["SSL"] for c in ret.json["data"])
+
+
+def test_filtering_usage_3(server):
+    ret = server.get("/api/certificates", json={"filtering": {"usage": ["SSL"]}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all(c["usage"]["SSL"] for c in ret.json["data"])
+
+
+def test_filtering_cn_1(server):
+    ret = server.get("/api/certificates", json={"filtering": {"CN": "Root"}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all("Root" in c["CN"] for c in ret.json["data"])
+
+
+def test_filtering_cn_2(server):
+    ret = server.get("/api/certificates", json={"filtering": {"CN": "s.r.o"}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all("s.r.o" in c["CN"] for c in ret.json["data"])
+
+
+def test_filtering_cn_3(server):
+    ret = server.get("/api/certificates", json={"filtering": {"CN": "awoehawegpiuh"}})
+    assert ret.status_code == 200
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    assert all("awoehawegpiuh" in c["CN"] for c in ret.json["data"])
+
+
 def test_get_one(server):
     ret = server.get("/api/certificates/1")
 
