This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
96 lines (83 loc) · 3.93 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
An unofficial, RESTful API for NIST's NVD.
Copyright (C) 2022 [email protected]
"""
import unittest
from api.app import app
class ApiTests(unittest.TestCase):
"""Test endpoints and search functions."""
def setUp(self) -> None:
app.config["DEBUG"] = False
self.app = app.test_client()
self.assertEqual(app.debug, False)
def tearDown(self) -> None:
pass
def test_schema(self) -> None:
"""Test schema endpoint."""
response = self.app.get("/nvd-api/v1/schema", follow_redirects=True)
self.assertEqual(response.status_code, 200)
def test_year(self) -> None:
"""Test year endpoint."""
response = self.app.get("/nvd-api/v1/year/2020?keyword=",
follow_redirects=True)
response2 = self.app.get("/nvd-api/v1/year/bullshit",
follow_redirects=True)
response3 = self.app.get("/nvd-api/v1/year/2000",
follow_redirects=True)
response4 = self.app.get("/nvd-api/v1/year/2020?keyword=the",
follow_redirects=True)
response5 = self.app.get("/nvd-api/v1/year/2002?keyword=the",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 404)
self.assertEqual(response3.status_code, 200)
self.assertEqual(response4.status_code, 200)
self.assertEqual(response5.status_code, 200)
def test_recent(self) -> None:
"""Test recent endpoint."""
response = self.app.get("/nvd-api/v1/recent", follow_redirects=True)
response2 = self.app.get("/nvd-api/v1/recent?keyword=the",
follow_redirects=True)
response3 = self.app.get("/nvd-api/v1/recent?bullshit=",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 200)
self.assertEqual(response3.status_code, 200)
def test_modified(self) -> None:
"""Test modified endpoint."""
response = self.app.get("/nvd-api/v1/modified", follow_redirects=True)
response2 = self.app.get("/nvd-api/v1/modified?keyword=the",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 200)
def test_all(self) -> None:
"""Test all endpoint."""
response = self.app.get("/nvd-api/v1/all", follow_redirects=True)
response2 = self.app.get("/nvd-api/v1/all?keyword=sudo",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 200)
def test_cve(self) -> None:
"""Test cve endpoint."""
response = self.app.get("/nvd-api/v1/CVE-2020-8087",
follow_redirects=True)
response2 = self.app.get("/nvd-api/v1/CVE-2000-1246",
follow_redirects=True)
response3 = self.app.get("/nvd-api/v1/bullshit", follow_redirects=True)
response4 = self.app.get("/nvd-api/v1/CVE-2021-9999",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 200)
self.assertEqual(response3.status_code, 404)
self.assertEqual(response4.status_code, 404)
def test_cpe(self) -> None:
"""Test cpe endpoint."""
response = self.app.get("/nvd-api/v1/cpe/23/arris",
follow_redirects=True)
response2 = self.app.get(
"/nvd-api/v1/cpe/23/arris?keyword=buffer overflow",
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response2.status_code, 200)
if __name__ == "__main__":
unittest.main()