-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Test Case for SBOM feature (#20797)
Signed-off-by: Shengwen Yu <[email protected]>
- Loading branch information
Shengwen YU
authored
Aug 1, 2024
1 parent
e0b94aa
commit 295e075
Showing
12 changed files
with
359 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/apitests/python/test_sbom_generation_of_image_artifact.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import absolute_import | ||
import unittest | ||
import sys | ||
|
||
from testutils import harbor_server, suppress_urllib3_warning | ||
from testutils import TEARDOWN | ||
from testutils import ADMIN_CLIENT, BASE_IMAGE, BASE_IMAGE_ABS_PATH_NAME | ||
from library.project import Project | ||
from library.user import User | ||
from library.repository import Repository | ||
from library.repository import push_self_build_image_to_project | ||
from library.artifact import Artifact | ||
from library.scan import Scan | ||
|
||
class TestSBOMGeneration(unittest.TestCase): | ||
@suppress_urllib3_warning | ||
def setUp(self): | ||
self.project= Project() | ||
self.user= User() | ||
self.artifact = Artifact() | ||
self.repo = Repository() | ||
self.scan = Scan() | ||
|
||
self.url = ADMIN_CLIENT["endpoint"] | ||
self.user_password = "Aa123456" | ||
self.project_id, self.project_name, self.user_id, self.user_name, self.repo_name1 = [None] * 5 | ||
self.user_id, self.user_name = self.user.create_user(user_password = self.user_password, **ADMIN_CLIENT) | ||
self.USER_CLIENT = dict(with_signature = True, with_immutable_status = True, endpoint = self.url, username = self.user_name, password = self.user_password, with_sbom_overview = True) | ||
|
||
|
||
#2. Create a new private project(PA) by user(UA); | ||
self.project_id, self.project_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT) | ||
|
||
#3. Add user(UA) as a member of project(PA) with project-admin role; | ||
self.project.add_project_members(self.project_id, user_id = self.user_id, **ADMIN_CLIENT) | ||
|
||
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") | ||
def do_tearDown(self): | ||
#1. Delete repository(RA) by user(UA); | ||
self.repo.delete_repository(self.project_name, self.repo_name1.split('/')[1], **self.USER_CLIENT) | ||
|
||
#2. Delete project(PA); | ||
self.project.delete_project(self.project_id, **self.USER_CLIENT) | ||
|
||
#3. Delete user(UA); | ||
self.user.delete_user(self.user_id, **ADMIN_CLIENT) | ||
|
||
def testGenerateSBOMOfImageArtifact(self): | ||
""" | ||
Test case: | ||
Generate an SBOM of An Image Artifact | ||
Test step and expected result: | ||
1. Create a new user(UA); | ||
2. Create a new private project(PA) by user(UA); | ||
3. Add user(UA) as a member of project(PA) with project-admin role; | ||
4. Get private project of user(UA), user(UA) can see only one private project which is project(PA); | ||
5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); | ||
6. Send sbom generation of an image command and get tag(TA) information to check sbom generation result, it should be finished; | ||
Tear down: | ||
1. Delete repository(RA) by user(UA); | ||
2. Delete project(PA); | ||
3. Delete user(UA); | ||
""" | ||
|
||
#4. Get private project of user(UA), user(UA) can see only one private project which is project(PA); | ||
self.project.projects_should_exist(dict(public=False), expected_count = 1, | ||
expected_project_id = self.project_id, **self.USER_CLIENT) | ||
|
||
#Note: Please make sure that this Image has never been pulled before by any other cases, | ||
# so it is a not-scanned image right after repository creation. | ||
image = "docker" | ||
src_tag = "1.13" | ||
#5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); | ||
self.repo_name1, tag = push_self_build_image_to_project(self.project_name, harbor_server, self.user_name, self.user_password, image, src_tag) | ||
|
||
#6. Send sbom generation of an image command and get tag(TA) information to check sbom generation result, it should be finished; | ||
self.scan.sbom_generation_of_artifact(self.project_name, self.repo_name1.split('/')[1], tag, **self.USER_CLIENT) | ||
self.artifact.check_image_sbom_generation_result(self.project_name, image, tag, **self.USER_CLIENT) | ||
|
||
self.do_tearDown() | ||
|
||
|
||
if __name__ == '__main__': | ||
suite = unittest.TestSuite(unittest.makeSuite(TestSBOMGeneration)) | ||
result = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=True).run(suite) | ||
if not result.wasSuccessful(): | ||
raise Exception(r"SBOM generation test failed: {}".format(result)) |
91 changes: 91 additions & 0 deletions
91
tests/apitests/python/test_stop_sbom_generation_of_image_artifact.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from __future__ import absolute_import | ||
import unittest | ||
import sys | ||
|
||
from testutils import harbor_server, suppress_urllib3_warning | ||
from testutils import TEARDOWN | ||
from testutils import ADMIN_CLIENT, BASE_IMAGE, BASE_IMAGE_ABS_PATH_NAME | ||
from library.project import Project | ||
from library.user import User | ||
from library.repository import Repository | ||
from library.repository import push_self_build_image_to_project | ||
from library.artifact import Artifact | ||
from library.scan import Scan | ||
from library.scan_stop import StopScan | ||
|
||
class TestStopSBOMGeneration(unittest.TestCase): | ||
@suppress_urllib3_warning | ||
def setUp(self): | ||
self.project= Project() | ||
self.user= User() | ||
self.artifact = Artifact() | ||
self.repo = Repository() | ||
self.scan = Scan() | ||
self.stop_scan = StopScan() | ||
|
||
self.url = ADMIN_CLIENT["endpoint"] | ||
self.user_password = "Aa123456" | ||
self.project_id, self.project_name, self.user_id, self.user_name, self.repo_name1 = [None] * 5 | ||
self.user_id, self.user_name = self.user.create_user(user_password = self.user_password, **ADMIN_CLIENT) | ||
self.USER_CLIENT = dict(with_signature = True, with_immutable_status = True, endpoint = self.url, username = self.user_name, password = self.user_password, with_sbom_overview = True) | ||
|
||
|
||
#2. Create a new private project(PA) by user(UA); | ||
self.project_id, self.project_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT) | ||
|
||
#3. Add user(UA) as a member of project(PA) with project-admin role; | ||
self.project.add_project_members(self.project_id, user_id = self.user_id, **ADMIN_CLIENT) | ||
|
||
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") | ||
def do_tearDown(self): | ||
#1. Delete repository(RA) by user(UA); | ||
self.repo.delete_repository(self.project_name, self.repo_name1.split('/')[1], **self.USER_CLIENT) | ||
|
||
#2. Delete project(PA); | ||
self.project.delete_project(self.project_id, **self.USER_CLIENT) | ||
|
||
#3. Delete user(UA); | ||
self.user.delete_user(self.user_id, **ADMIN_CLIENT) | ||
|
||
def testStopSBOMGenerationOfImageArtifact(self): | ||
""" | ||
Test case: | ||
Stop SBOM Generation Of An Image Artifact | ||
Test step and expected result: | ||
1. Create a new user(UA); | ||
2. Create a new private project(PA) by user(UA); | ||
3. Add user(UA) as a member of project(PA) with project-admin role; | ||
4. Get private project of user(UA), user(UA) can see only one private project which is project(PA); | ||
5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); | ||
6. Send SBOM generation of an image command; | ||
7. Send stop SBOM generation of an image command. | ||
Tear down: | ||
1. Delete repository(RA) by user(UA); | ||
2. Delete project(PA); | ||
3. Delete user(UA); | ||
""" | ||
|
||
#4. Get private project of user(UA), user(UA) can see only one private project which is project(PA); | ||
self.project.projects_should_exist(dict(public=False), expected_count = 1, | ||
expected_project_id = self.project_id, **self.USER_CLIENT) | ||
|
||
#Note: Please make sure that this Image has never been pulled before by any other cases, | ||
# so it is a not-scanned image right after repository creation. | ||
image = "docker" | ||
src_tag = "1.13" | ||
#5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); | ||
self.repo_name1, tag = push_self_build_image_to_project(self.project_name, harbor_server, self.user_name, self.user_password, image, src_tag) | ||
|
||
#6. Send SBOM generation of an image command; | ||
self.scan.sbom_generation_of_artifact(self.project_name, self.repo_name1.split('/')[1], tag, **self.USER_CLIENT) | ||
|
||
#7. Send stop SBOM generation of an image command. | ||
self.stop_scan.stop_sbom_generation_of_artifact(self.project_name, self.repo_name1.split('/')[1], tag, **self.USER_CLIENT) | ||
|
||
self.do_tearDown() | ||
|
||
if __name__ == '__main__': | ||
suite = unittest.TestSuite(unittest.makeSuite(TestStopSBOMGeneration)) | ||
result = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=True).run(suite) | ||
if not result.wasSuccessful(): | ||
raise Exception(r"Stop SBOM generation test failed: {}".format(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.