mirror of
https://github.com/cve-search/PyVulnerabilityLookup.git
synced 2024-11-25 16:27:23 +00:00
chg: Improve testing for comments and bundles
This commit is contained in:
parent
74c0f6dc22
commit
6e504075a1
1 changed files with 101 additions and 17 deletions
|
@ -111,15 +111,56 @@ class TestPublic(unittest.TestCase):
|
||||||
return None
|
return None
|
||||||
# Makes sure the userkey is set to the right one
|
# Makes sure the userkey is set to the right one
|
||||||
self.client.set_apikey(self.admin_token)
|
self.client.set_apikey(self.admin_token)
|
||||||
comment = {'title': 'test', 'description': 'test',
|
comments = self.client.get_comments()
|
||||||
'vulnerability': 'CVE-2024-20401',
|
self.assertTrue("metadata" in comments)
|
||||||
'related_vulnerabilities': ['CVE-2024-20402']}
|
self.assertTrue("data" in comments)
|
||||||
created_comment = self.client.create_comment(comment)
|
self.assertTrue(len(comments['data']) == 0)
|
||||||
new_comment_uuid = created_comment['data'][0]['uuid']
|
self.assertEqual(comments['metadata']['count'], 0)
|
||||||
comments = self.client.get_comments(uuid=new_comment_uuid)
|
|
||||||
self.assertTrue(len(comments['data']) == 1)
|
comment = {
|
||||||
deleted_comment = self.client.delete_comment(new_comment_uuid)
|
"uuid": "a309d024-2714-4a81-a425-60f83f6d5740",
|
||||||
self.assertTrue(deleted_comment < 300)
|
"title": "Comment",
|
||||||
|
"description": "Comment",
|
||||||
|
"description_format": "markdown",
|
||||||
|
"vulnerability": "CVE-2024-20401",
|
||||||
|
"related_vulnerabilities": ["ghsa-4rcj-fmjg-q9fv"],
|
||||||
|
}
|
||||||
|
comments = self.client.create_comment(comment)
|
||||||
|
self.assertTrue(len(comments["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
comments["data"][0]["uuid"], "a309d024-2714-4a81-a425-60f83f6d5740"
|
||||||
|
)
|
||||||
|
|
||||||
|
comments = self.client.get_comments(uuid="a309d024-2714-4a81-a425-60f83f6d5740")
|
||||||
|
self.assertTrue(len(comments["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
comments["data"][0]["uuid"], "a309d024-2714-4a81-a425-60f83f6d5740"
|
||||||
|
)
|
||||||
|
|
||||||
|
comments = self.client.get_comments(vuln_id="CVE-2024-20401")
|
||||||
|
self.assertTrue(len(comments["data"]) >= 1)
|
||||||
|
for comment in comments["data"]:
|
||||||
|
self.assertEqual(comment["vulnerability"], "CVE-2024-20401")
|
||||||
|
|
||||||
|
# comments = self.client.get_comments(author='admin')
|
||||||
|
# self.assertTrue(len(comments['data']) >= 1)
|
||||||
|
# for comment in comments['data']:
|
||||||
|
# self.assertEqual(comment['author']['login'], 'admin') # type: ignore[call-overload]
|
||||||
|
|
||||||
|
comments = self.client.get_comments(
|
||||||
|
uuid="a309d024-2714-4a81-a425-60f83f6d5740", vuln_id="CVE-2024-20401"
|
||||||
|
)
|
||||||
|
self.assertTrue(len(comments["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
comments["data"][0]["uuid"], "a309d024-2714-4a81-a425-60f83f6d5740"
|
||||||
|
)
|
||||||
|
self.assertEqual(comments["data"][0]["vulnerability"], "CVE-2024-20401")
|
||||||
|
# self.assertEqual(comments['data'][0]['author']['login'], 'admin')
|
||||||
|
|
||||||
|
status_code = self.client.delete_comment("a309d024-2714-4a81-a425-60f83f6d5740")
|
||||||
|
self.assertTrue(status_code == 204)
|
||||||
|
comments = self.client.get_comments(uuid="a309d024-2714-4a81-a425-60f83f6d5740")
|
||||||
|
self.assertTrue(len(comments["data"]) == 0)
|
||||||
|
|
||||||
# Test bundles
|
# Test bundles
|
||||||
|
|
||||||
|
@ -159,14 +200,57 @@ class TestPublic(unittest.TestCase):
|
||||||
return None
|
return None
|
||||||
# Makes sure the userkey is set to the right one
|
# Makes sure the userkey is set to the right one
|
||||||
self.client.set_apikey(self.admin_token)
|
self.client.set_apikey(self.admin_token)
|
||||||
bundle = {'name': 'test', 'description': 'test',
|
bundles = self.client.get_bundles()
|
||||||
'related_vulnerabilities': ['CVE-2024-20402', 'CVE-2024-20403']}
|
self.assertTrue("metadata" in bundles)
|
||||||
created_bundle = self.client.create_bundle(bundle)
|
self.assertTrue("data" in bundles)
|
||||||
new_bundle_uuid = created_bundle['data'][0]['uuid']
|
self.assertTrue(len(bundles['data']) == 0)
|
||||||
bundles = self.client.get_bundles(uuid=new_bundle_uuid)
|
self.assertEqual(bundles['metadata']['count'], 0)
|
||||||
self.assertTrue(len(bundles['data']) == 1)
|
|
||||||
deleted_bundle = self.client.delete_bundle(new_bundle_uuid)
|
bundle = {
|
||||||
self.assertTrue(deleted_bundle < 300)
|
"uuid": "a23cbcad-e890-4df8-8736-9332ed4c3d47",
|
||||||
|
"name": "Bundle",
|
||||||
|
"description": "Bundle",
|
||||||
|
"description_format": "markdown",
|
||||||
|
"related_vulnerabilities": ["ghsa-4rcj-fmjg-q9fv", "CVE-2024-39573"],
|
||||||
|
}
|
||||||
|
bundles = self.client.create_bundle(bundle)
|
||||||
|
self.assertTrue(len(bundles["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
bundles["data"][0]["uuid"], "a23cbcad-e890-4df8-8736-9332ed4c3d47"
|
||||||
|
)
|
||||||
|
|
||||||
|
bundles = self.client.get_bundles(uuid="a23cbcad-e890-4df8-8736-9332ed4c3d47")
|
||||||
|
self.assertTrue(len(bundles["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
bundles["data"][0]["uuid"], "a23cbcad-e890-4df8-8736-9332ed4c3d47"
|
||||||
|
)
|
||||||
|
|
||||||
|
bundles = self.client.get_bundles(vuln_id="CVE-2024-39573")
|
||||||
|
self.assertTrue(len(bundles["data"]) >= 1)
|
||||||
|
for bundle in bundles["data"]:
|
||||||
|
self.assertTrue("CVE-2024-39573" in bundle["related_vulnerabilities"])
|
||||||
|
|
||||||
|
# bundles = self.client.get_bundles(author='admin')
|
||||||
|
# self.assertTrue(len(bundles['data']) >= 1)
|
||||||
|
# for bundle in bundles['data']:
|
||||||
|
# self.assertEqual(bundle['author']['login'], 'admin') # type: ignore[call-overload]
|
||||||
|
|
||||||
|
bundles = self.client.get_bundles(
|
||||||
|
uuid="a23cbcad-e890-4df8-8736-9332ed4c3d47", vuln_id="CVE-2024-39573"
|
||||||
|
)
|
||||||
|
self.assertTrue(len(bundles["data"]) == 1)
|
||||||
|
self.assertEqual(
|
||||||
|
bundles["data"][0]["uuid"], "a23cbcad-e890-4df8-8736-9332ed4c3d47"
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
"CVE-2024-39573" in bundles["data"][0]["related_vulnerabilities"]
|
||||||
|
)
|
||||||
|
# self.assertEqual(bundles['data'][0]['author']['login'], 'admin')
|
||||||
|
|
||||||
|
status_code = self.client.delete_bundle("a23cbcad-e890-4df8-8736-9332ed4c3d47")
|
||||||
|
self.assertTrue(status_code == 204)
|
||||||
|
comments = self.client.get_comments(uuid="a23cbcad-e890-4df8-8736-9332ed4c3d47")
|
||||||
|
self.assertTrue(len(comments["data"]) == 0)
|
||||||
|
|
||||||
# Test User
|
# Test User
|
||||||
def test_list_users(self) -> None:
|
def test_list_users(self) -> None:
|
||||||
|
|
Loading…
Reference in a new issue