chg: Improve testing for comments and bundles

This commit is contained in:
Raphaël Vinot 2024-07-31 16:13:53 +02:00
parent 74c0f6dc22
commit 6e504075a1

View file

@ -111,15 +111,56 @@ class TestPublic(unittest.TestCase):
return None
# Makes sure the userkey is set to the right one
self.client.set_apikey(self.admin_token)
comment = {'title': 'test', 'description': 'test',
'vulnerability': 'CVE-2024-20401',
'related_vulnerabilities': ['CVE-2024-20402']}
created_comment = self.client.create_comment(comment)
new_comment_uuid = created_comment['data'][0]['uuid']
comments = self.client.get_comments(uuid=new_comment_uuid)
self.assertTrue(len(comments['data']) == 1)
deleted_comment = self.client.delete_comment(new_comment_uuid)
self.assertTrue(deleted_comment < 300)
comments = self.client.get_comments()
self.assertTrue("metadata" in comments)
self.assertTrue("data" in comments)
self.assertTrue(len(comments['data']) == 0)
self.assertEqual(comments['metadata']['count'], 0)
comment = {
"uuid": "a309d024-2714-4a81-a425-60f83f6d5740",
"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
@ -159,14 +200,57 @@ class TestPublic(unittest.TestCase):
return None
# Makes sure the userkey is set to the right one
self.client.set_apikey(self.admin_token)
bundle = {'name': 'test', 'description': 'test',
'related_vulnerabilities': ['CVE-2024-20402', 'CVE-2024-20403']}
created_bundle = self.client.create_bundle(bundle)
new_bundle_uuid = created_bundle['data'][0]['uuid']
bundles = self.client.get_bundles(uuid=new_bundle_uuid)
self.assertTrue(len(bundles['data']) == 1)
deleted_bundle = self.client.delete_bundle(new_bundle_uuid)
self.assertTrue(deleted_bundle < 300)
bundles = self.client.get_bundles()
self.assertTrue("metadata" in bundles)
self.assertTrue("data" in bundles)
self.assertTrue(len(bundles['data']) == 0)
self.assertEqual(bundles['metadata']['count'], 0)
bundle = {
"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
def test_list_users(self) -> None: