From 77e9fc38c73008a4f032e2b8615c601f6a0f8d57 Mon Sep 17 00:00:00 2001 From: danfengliu Date: Mon, 16 Mar 2020 10:13:28 +0800 Subject: [PATCH] Modify api test for test step of add addition Signed-off-by: danfengliu --- api/v2.0/swagger.yaml | 8 ++- tests/apitests/python/library/artifact.py | 29 ++++++++++- tests/apitests/python/library/base.py | 1 + tests/apitests/python/library/cnab.py | 2 +- tests/apitests/python/library/docker_api.py | 6 +-- tests/apitests/python/library/repository.py | 4 +- tests/apitests/python/library/scan.py | 5 +- tests/apitests/python/library/scanner.py | 26 ++++++++++ .../python/test_add_sys_label_to_tag.py | 4 +- .../test_copy_artifact_outside_project.py | 4 +- .../apitests/python/test_create_delete_tag.py | 4 +- tests/apitests/python/test_del_repo.py | 2 +- .../python/test_edit_project_creation.py | 11 ++--- .../python/test_garbage_collection.py | 2 +- .../python/test_manage_project_member.py | 2 +- ...test_project_level_policy_content_trust.py | 4 +- tests/apitests/python/test_project_quota.py | 2 +- .../test_push_chart_by_helm3_chart_cli.py | 31 +++++++++--- .../apitests/python/test_push_cnab_bundle.py | 4 +- .../test_push_index_by_docker_manifest.py | 49 ++++++++++++++++--- tests/apitests/python/test_retention.py | 2 +- tests/apitests/python/test_robot_account.py | 2 +- .../python/test_scan_image_artifact.py | 26 +++++++--- tests/apitests/python/test_sign_image.py | 4 +- .../python/test_system_level_scan_all.py | 20 ++++++-- tests/robot-cases/Group0-BAT/API_DB.robot | 10 ++-- 26 files changed, 197 insertions(+), 67 deletions(-) create mode 100644 tests/apitests/python/library/scanner.py diff --git a/api/v2.0/swagger.yaml b/api/v2.0/swagger.yaml index 08fd57d0a..654830273 100644 --- a/api/v2.0/swagger.yaml +++ b/api/v2.0/swagger.yaml @@ -461,7 +461,13 @@ paths: required: true responses: '200': - $ref: '#/responses/200' + description: Success + headers: + Content-Type: + description: The content type of the addition + type: string + schema: + type: string '400': $ref: '#/responses/400' '401': diff --git a/tests/apitests/python/library/artifact.py b/tests/apitests/python/library/artifact.py index 8a6ed1a68..ff40895a6 100644 --- a/tests/apitests/python/library/artifact.py +++ b/tests/apitests/python/library/artifact.py @@ -5,7 +5,14 @@ import base import v2_swagger_client from v2_swagger_client.rest import ApiException -class Artifact(base.Base): +class Artifact(base.Base, object): + def __init__(self): + super(Artifact,self).__init__(api_type = "artifact") + + def list_artifacts(self, project_name, repo_name, **kwargs): + client = self._get_client(**kwargs) + return client.list_artifacts(project_name, repo_name) + def get_reference_info(self, project_name, repo_name, reference, **kwargs): client = self._get_client(**kwargs) params = {} @@ -15,7 +22,25 @@ class Artifact(base.Base): params["with_tag"] = kwargs["with_tag"] if "with_scan_overview" in kwargs: params["with_scan_overview"] = kwargs["with_scan_overview"] - return client.get_artifact_with_http_info(project_name, repo_name, reference, **params ) + return client.get_artifact_with_http_info(project_name, repo_name, reference, **params) + + def delete_artifact(self, project_name, repo_name, reference, expect_status_code = 200, expect_response_body = None, **kwargs): + client = self._get_client(**kwargs) + + try: + _, status_code, _ = client.delete_artifact_with_http_info(project_name, repo_name, reference) + except ApiException as e: + base._assert_status_code(expect_status_code, e.status) + if expect_response_body is not None: + base._assert_status_body(expect_response_body, e.body) + return + + base._assert_status_code(expect_status_code, status_code) + base._assert_status_code(200, status_code) + + def get_addition(self, project_name, repo_name, reference, addition, **kwargs): + client = self._get_client(**kwargs) + return client.get_addition_with_http_info(project_name, repo_name, reference, addition) def add_label_to_reference(self, project_name, repo_name, reference, label_id, **kwargs): client = self._get_client(**kwargs) diff --git a/tests/apitests/python/library/base.py b/tests/apitests/python/library/base.py index 561e842df..f51b357b7 100644 --- a/tests/apitests/python/library/base.py +++ b/tests/apitests/python/library/base.py @@ -39,6 +39,7 @@ def _create_client(server, credential, debug, api_type="products"): "artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)), "repository": v2_swagger_client.RepositoryApi(v2_swagger_client.ApiClient(cfg)), "scan": v2_swagger_client.ScanApi(v2_swagger_client.ApiClient(cfg)), + "scanner": swagger_client.ScannersApi(swagger_client.ApiClient(cfg)), }.get(api_type,'Error: Wrong API type') def _assert_status_code(expect_code, return_code): diff --git a/tests/apitests/python/library/cnab.py b/tests/apitests/python/library/cnab.py index 85f60f62c..d93f516b0 100644 --- a/tests/apitests/python/library/cnab.py +++ b/tests/apitests/python/library/cnab.py @@ -43,7 +43,7 @@ def cnab_push_bundle(bundle_file, target): raise Exception(r"Fail to get sha256 in returned data: {}".format(ret)) def push_cnab_bundle(harbor_server, user, password, service_image, invocation_image, target, auto_update_bundle = True): - docker_api.docker_login(harbor_server, user, password, enable_manifest = False) + docker_api.docker_login_cmd(harbor_server, user, password, enable_manifest = False) bundle_file = load_bundle(service_image, invocation_image) fixed_bundle_file = cnab_fixup_bundle(bundle_file, target, auto_update_bundle = auto_update_bundle) sha256 = cnab_push_bundle(fixed_bundle_file, target) diff --git a/tests/apitests/python/library/docker_api.py b/tests/apitests/python/library/docker_api.py index 7ebf5265f..d426e5742 100644 --- a/tests/apitests/python/library/docker_api.py +++ b/tests/apitests/python/library/docker_api.py @@ -10,13 +10,13 @@ except ImportError: pip.main(['install', 'docker']) import docker -def docker_login(harbor_host, user, password, enable_manifest = True): +def docker_login_cmd(harbor_host, user, password, enable_manifest = True): command = ["sudo", "docker", "login", harbor_host, "-u", user, "-p", password] print "Docker Login Command: ", command base.run_command(command) if enable_manifest == True: try: - subprocess.check_output(["./tests/apitests/python/update_docker_cfg.sh"], shell=False) + ret = subprocess.check_output(["./tests/apitests/python/update_docker_cfg.sh"], shell=False) except subprocess.CalledProcessError, exc: raise Exception("Failed to update docker config, error is {} {}.".format(exc.returncode, exc.output)) @@ -40,7 +40,7 @@ def docker_manifest_push(index): return index_sha256, manifest_list def docker_manifest_push_to_harbor(index, manifests, harbor_server, user, password): - docker_login(harbor_server, user, password) + docker_login_cmd(harbor_server, user, password) docker_manifest_create(index, manifests) return docker_manifest_push(index) diff --git a/tests/apitests/python/library/repository.py b/tests/apitests/python/library/repository.py index 9f4925736..2ab8ae9e9 100644 --- a/tests/apitests/python/library/repository.py +++ b/tests/apitests/python/library/repository.py @@ -46,7 +46,9 @@ def is_repo_exist_in_project(repositories, repo_name): return True return result -class Repository(base.Base): +class Repository(base.Base, object): + def __init__(self): + super(Repository,self).__init__(api_type = "repository") def list_tags(self, repository, **kwargs): client = self._get_client(**kwargs) diff --git a/tests/apitests/python/library/scan.py b/tests/apitests/python/library/scan.py index 4a65f8735..6273a503d 100644 --- a/tests/apitests/python/library/scan.py +++ b/tests/apitests/python/library/scan.py @@ -5,7 +5,10 @@ import base import v2_swagger_client from v2_swagger_client.rest import ApiException -class Scan(base.Base): +class Scan(base.Base, object): + def __init__(self): + super(Scan,self).__init__(api_type = "scan") + def scan_artifact(self, project_name, repo_name, reference, expect_status_code = 202, **kwargs): client = self._get_client(**kwargs) data, status_code, _ = client.scan_artifact_with_http_info(project_name, repo_name, reference) diff --git a/tests/apitests/python/library/scanner.py b/tests/apitests/python/library/scanner.py new file mode 100644 index 000000000..97a19ae49 --- /dev/null +++ b/tests/apitests/python/library/scanner.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +import time +import base +import swagger_client +from swagger_client.rest import ApiException + +class Scanner(base.Base, object): + def __init__(self): + super(Scanner,self).__init__(api_type = "scanner") + + def scanners_get(self, **kwargs): + client = self._get_client(**kwargs) + return client.scanners_get() + + def scanners_get_uuid(self, is_default = False, **kwargs): + scanners = self.scanners_get(**kwargs) + for scanner in scanners: + if scanner.is_default == is_default: + return scanner.uuid + + def scanners_registration_id_patch(self, registration_id, is_default = True, **kwargs): + client = self._get_client(**kwargs) + isdefault = swagger_client.IsDefault(is_default) + client.scanners_registration_id_patch(registration_id, isdefault) + diff --git a/tests/apitests/python/test_add_sys_label_to_tag.py b/tests/apitests/python/test_add_sys_label_to_tag.py index 9b092799a..f54a5804c 100644 --- a/tests/apitests/python/test_add_sys_label_to_tag.py +++ b/tests/apitests/python/test_add_sys_label_to_tag.py @@ -17,8 +17,8 @@ class TestProjects(unittest.TestCase): def setUp(self): self.project = Project() self.user = User() - self.artifact = Artifact(api_type='artifact') - self.repo = Repository(api_type='repository') + self.artifact = Artifact() + self.repo = Repository() self.label = Label() @classmethod diff --git a/tests/apitests/python/test_copy_artifact_outside_project.py b/tests/apitests/python/test_copy_artifact_outside_project.py index 5229f0382..7b481527a 100644 --- a/tests/apitests/python/test_copy_artifact_outside_project.py +++ b/tests/apitests/python/test_copy_artifact_outside_project.py @@ -20,8 +20,8 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project = Project() self.user = User() - self.artifact = Artifact(api_type='artifact') - self.repo = Repository(api_type='repository') + self.artifact = Artifact() + self.repo = Repository() @classmethod def tearDownClass(self): diff --git a/tests/apitests/python/test_create_delete_tag.py b/tests/apitests/python/test_create_delete_tag.py index 2e828941c..89efca078 100644 --- a/tests/apitests/python/test_create_delete_tag.py +++ b/tests/apitests/python/test_create_delete_tag.py @@ -22,8 +22,8 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo= Repository(api_type='repository') + self.artifact = Artifact() + self.repo= Repository() self.url = ADMIN_CLIENT["endpoint"] self.user_password = "Aa123456" self.repo_name = "hello-world" diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py index 221ed080e..6eed0af1a 100644 --- a/tests/apitests/python/test_del_repo.py +++ b/tests/apitests/python/test_del_repo.py @@ -18,7 +18,7 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project= Project() self.user= User() - self.repo= Repository(api_type='repository') + self.repo= Repository() @classmethod def tearDownClass(self): diff --git a/tests/apitests/python/test_edit_project_creation.py b/tests/apitests/python/test_edit_project_creation.py index c815f8a1a..d15cda6eb 100644 --- a/tests/apitests/python/test_edit_project_creation.py +++ b/tests/apitests/python/test_edit_project_creation.py @@ -10,14 +10,9 @@ from library.configurations import Configurations class TestProjects(unittest.TestCase): @classmethod def setUp(self): - conf = Configurations() - self.conf= conf - - project = Project() - self.project= project - - user = User() - self.user= user + self.conf= Configurations() + self.project= Project() + self.user= User() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_garbage_collection.py b/tests/apitests/python/test_garbage_collection.py index 3ef3fd649..fd943b275 100644 --- a/tests/apitests/python/test_garbage_collection.py +++ b/tests/apitests/python/test_garbage_collection.py @@ -18,7 +18,7 @@ class TestProjects(unittest.TestCase): self.system = System() self.project = Project() self.user = User() - self.repo = Repository(api_type='repository') + self.repo = Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_manage_project_member.py b/tests/apitests/python/test_manage_project_member.py index 42af14d9a..27bd25f01 100644 --- a/tests/apitests/python/test_manage_project_member.py +++ b/tests/apitests/python/test_manage_project_member.py @@ -15,7 +15,7 @@ class TestProjects(unittest.TestCase): def setUp(self): self.project = Project() self.user = User() - self.repo = Repository(api_type='repository') + self.repo = Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_project_level_policy_content_trust.py b/tests/apitests/python/test_project_level_policy_content_trust.py index 68251cd96..d54574a1e 100644 --- a/tests/apitests/python/test_project_level_policy_content_trust.py +++ b/tests/apitests/python/test_project_level_policy_content_trust.py @@ -18,8 +18,8 @@ class TestProjects(unittest.TestCase): def setUp(self): self.project= Project() self.user= User() - self.artifact= Artifact(api_type='artifact') - self.repo= Repository(api_type='repository') + self.artifact= Artifact() + self.repo= Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_project_quota.py b/tests/apitests/python/test_project_quota.py index 92629ec59..a6896ec04 100644 --- a/tests/apitests/python/test_project_quota.py +++ b/tests/apitests/python/test_project_quota.py @@ -10,7 +10,7 @@ from library.system import System class TestProjects(unittest.TestCase): @classmethod def setUp(cls): - cls.repo = Repository(api_type='repository') + cls.repo = Repository() cls.system = System() @classmethod diff --git a/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py b/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py index 97e4c813b..2ba5a6ed9 100644 --- a/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py +++ b/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py @@ -19,8 +19,8 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo= Repository(api_type='repository') + self.artifact = Artifact() + self.repo= Repository() self.url = ADMIN_CLIENT["endpoint"] self.user_push_chart_password = "Aa123456" self.chart_file = "https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz" @@ -51,8 +51,10 @@ class TestProjects(unittest.TestCase): 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Push an chart(CA) to Harbor by helm3 registry/chart CLI successfully; - 4. Get chart(CA) from Harbor successfully; - 5. TO_DO: Verify this chart artifact information, like digest. + 4. List artifacts successfully; + 5. Get chart(CA) by reference successfully; + 6. Get addtion successfully; + 7. Delete chart by reference successfully. Tear down: 1. Delete repository chart(CA) by user(UA); 2. Delete project(PA); @@ -69,14 +71,27 @@ class TestProjects(unittest.TestCase): chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_push_chart_name, self.repo_name, self.verion, user_name, self.user_push_chart_password) print "chart_cli_ret:", chart_cli_ret - #4. Get chart(CA) from Harbor successfully; - artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT) - print "artifact:", artifact + #4. List artifacts successfully; + artifacts = self.artifact.list_artifacts(TestProjects.project_push_chart_name, self.repo_name, **TestProjects.USER_CLIENT) + self.assertEqual(artifacts[0].type, 'CHART') + self.assertEqual(artifacts[0].tags[0].name, self.verion) - #5. TO_DO: Verify this chart artifact information, like digest; + #5. Get chart(CA) by reference successfully; + artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT) self.assertEqual(artifact[0].type, 'CHART') self.assertEqual(artifact[0].tags[0].name, self.verion) + #6. Get addtion successfully; + addition_r = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "readme.md", **TestProjects.USER_CLIENT) + self.assertIn("Helm Chart for Harbor", addition_r[0]) + addition_d = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "dependencies", **TestProjects.USER_CLIENT) + self.assertIn("https://kubernetes-charts.storage.googleapis.com", addition_d[0]) + addition_v = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "values.yaml", **TestProjects.USER_CLIENT) + self.assertIn("adminserver", addition_v[0]) + + #7. Delete chart by reference successfully. + self.artifact.delete_artifact(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT) + if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/test_push_cnab_bundle.py b/tests/apitests/python/test_push_cnab_bundle.py index ba442efdf..3f815779d 100644 --- a/tests/apitests/python/test_push_cnab_bundle.py +++ b/tests/apitests/python/test_push_cnab_bundle.py @@ -20,8 +20,8 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo= Repository(api_type='repository') + self.artifact = Artifact() + self.repo= Repository() self.url = ADMIN_CLIENT["endpoint"] self.user_push_chart_password = "Aa123456" self.cnab_repo_name = "test_cnab" diff --git a/tests/apitests/python/test_push_index_by_docker_manifest.py b/tests/apitests/python/test_push_index_by_docker_manifest.py index aff1fabca..5c4f353bf 100644 --- a/tests/apitests/python/test_push_index_by_docker_manifest.py +++ b/tests/apitests/python/test_push_index_by_docker_manifest.py @@ -22,8 +22,8 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo= Repository(api_type='repository') + self.artifact = Artifact() + self.repo= Repository() self.url = ADMIN_CLIENT["endpoint"] self.user_push_index_password = "Aa123456" self.index_name = "ci_test_index" @@ -57,9 +57,13 @@ class TestProjects(unittest.TestCase): 2. Create a new project(PA) by user(UA); 3. Create 2 new repositorys(RA,RB) in project(PA) by user(UA); 4. Push an index(IA) to Harbor by docker manifest CLI successfully; - 5. Get index(IA) from Harbor successfully; - 6. Verify harbor index is index(IA) pushed by docker manifest CLI; - 7. Verify harbor index(IA) can be pulled by docker CLI successfully. + 5. Get Artifacts successfully; + 6. Get index(IA) by reference successfully; + 7. Verify harbor index is index(IA) pushed by docker manifest CLI; + 8. Verify harbor index(IA) can be pulled by docker CLI successfully; + 9. Get addition successfully; + 10. Unable to Delete artifact in manifest list; + 11. Delete index successfully. Tear down: 1. Delete repository(RA,RB,IA) by user(UA); 2. Delete project(PA); @@ -82,18 +86,47 @@ class TestProjects(unittest.TestCase): index = harbor_server+"/"+TestProjects.project_push_index_name+"/"+self.index_name+":"+self.index_tag index_sha256_cli_ret, manifests_sha256_cli_ret = library.docker_api.docker_manifest_push_to_harbor(index, manifests, harbor_server, user_name, self.user_push_index_password) - #5. Get index(IA) from Harbor successfully; + #5. Get Artifacts successfully; + artifacts = self.artifact.list_artifacts(TestProjects.project_push_index_name, self.index_name, **TestProjects.USER_CLIENT) + artifacts_ref_child_list = [artifacts[0].references[1].child_digest, artifacts[0].references[0].child_digest] + self.assertEqual(artifacts_ref_child_list.count(manifests_sha256_cli_ret[0]), 1) + self.assertEqual(artifacts_ref_child_list.count(manifests_sha256_cli_ret[1]), 1) + + #6. Get index(IA) by reference successfully; index_data = self.artifact.get_reference_info(TestProjects.project_push_index_name, self.index_name, self.index_tag, **TestProjects.USER_CLIENT) manifests_sha256_harbor_ret = [index_data[0].references[1].child_digest, index_data[0].references[0].child_digest] - #6. Verify harbor index is index(IA) pushed by docker manifest CLI; + #7. Verify harbor index is index(IA) pushed by docker manifest CLI; self.assertEqual(index_data[0].digest, index_sha256_cli_ret) self.assertEqual(manifests_sha256_harbor_ret.count(manifests_sha256_cli_ret[0]), 1) self.assertEqual(manifests_sha256_harbor_ret.count(manifests_sha256_cli_ret[1]), 1) - #7. Verify harbor index(IA) can be pulled by docker CLI successfully; + #8. Verify harbor index(IA) can be pulled by docker CLI successfully; pull_harbor_image(harbor_server, user_name, self.user_push_index_password, TestProjects.project_push_index_name+"/"+self.index_name, self.index_tag) + #9. Get addition successfully; + addition_v = self.artifact.get_addition(TestProjects.project_push_index_name, self.index_name, self.index_tag, "vulnerabilities", **TestProjects.USER_CLIENT) + self.assertEqual(addition_v[0], '{}') + #This artifact has no build history + + addition_v = self.artifact.get_addition(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[0], "vulnerabilities", **TestProjects.USER_CLIENT) + self.assertEqual(addition_v[0], '{}') + addition_b = self.artifact.get_addition(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[0], "build_history", **TestProjects.USER_CLIENT) + self.assertIn("ADD file:e69d441d729412d24675dcd33e04580885df99981cec43de8c9b24015313ff8e", addition_b[0]) + image_data = self.artifact.get_reference_info(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[0], **TestProjects.USER_CLIENT) + + addition_v = self.artifact.get_addition(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[1], "vulnerabilities", **TestProjects.USER_CLIENT) + self.assertEqual(addition_v[0], '{}') + addition_b = self.artifact.get_addition(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[1], "build_history", **TestProjects.USER_CLIENT) + self.assertIn("ADD file:450bea8cddb743ed282cb1ade3d1614033172b93ef531c69a4e49fda3016cef0", addition_b[0]) + image_data = self.artifact.get_reference_info(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[0], **TestProjects.USER_CLIENT) + + #10. Unable to Delete artifact in manifest list; + self.artifact.delete_artifact(TestProjects.project_push_index_name, self.index_name, manifests_sha256_cli_ret[0], expect_status_code = 412, **TestProjects.USER_CLIENT) + + #11. Delete index successfully. + self.artifact.delete_artifact(TestProjects.project_push_index_name, self.index_name, self.index_tag, **TestProjects.USER_CLIENT) + if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/test_retention.py b/tests/apitests/python/test_retention.py index e639cb630..b8b502ffd 100644 --- a/tests/apitests/python/test_retention.py +++ b/tests/apitests/python/test_retention.py @@ -35,7 +35,7 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.user = User() self.system = System() - self.repo = Repository(api_type='repository') + self.repo = Repository() self.project = Project() self.retention = Retention() diff --git a/tests/apitests/python/test_robot_account.py b/tests/apitests/python/test_robot_account.py index aca81d93c..83040d4d9 100644 --- a/tests/apitests/python/test_robot_account.py +++ b/tests/apitests/python/test_robot_account.py @@ -17,7 +17,7 @@ class TestProjects(unittest.TestCase): def setUp(self): self.project = Project() self.user = User() - self.repo = Repository(api_type='repository') + self.repo = Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_scan_image_artifact.py b/tests/apitests/python/test_scan_image_artifact.py index d7afe4c35..93e04c76d 100644 --- a/tests/apitests/python/test_scan_image_artifact.py +++ b/tests/apitests/python/test_scan_image_artifact.py @@ -10,20 +10,22 @@ from library.repository import Repository from library.repository import push_image_to_project from library.artifact import Artifact from library.scan import Scan +from library.scanner import Scanner class TestProjects(unittest.TestCase): @classmethod def setUp(self): self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo = Repository(api_type='repository') - self.scan = Scan(api_type='scan') + self.artifact = Artifact() + self.repo = Repository() + self.scan = Scan() + self.scanner = Scanner() @classmethod def tearDown(self): print "Case completed" - @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") + @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); self.repo.delete_repoitory(TestProjects.project_scan_image_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_SCAN_IMAGE_CLIENT) @@ -45,6 +47,8 @@ class TestProjects(unittest.TestCase): 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 scan image command and get tag(TA) information to check scan result, it should be finished; + 7. Swith Scanner; + 8. Send scan another image command and get tag(TA) information to check scan result, it should be finished. Tear down: 1. Delete repository(RA) by user(UA); 2. Delete project(PA); @@ -69,8 +73,7 @@ class TestProjects(unittest.TestCase): expected_project_id = TestProjects.project_scan_image_id, **TestProjects.USER_SCAN_IMAGE_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 = "tomcat" + # 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); @@ -78,8 +81,17 @@ class TestProjects(unittest.TestCase): #6. Send scan image command and get tag(TA) information to check scan result, it should be finished; self.scan.scan_artifact(TestProjects.project_scan_image_name, TestProjects.repo_name.split('/')[1], tag, **TestProjects.USER_SCAN_IMAGE_CLIENT) + self.artifact.check_image_scan_result(TestProjects.project_scan_image_name, image, tag, **TestProjects.USER_SCAN_IMAGE_CLIENT) - #6. Send scan image command and get tag(TA) information to check scan result, it should be finished; + #7. Swith Scanner; + uuid = self.scanner.scanners_get_uuid(**ADMIN_CLIENT) + self.scanner.scanners_registration_id_patch(uuid, **ADMIN_CLIENT) + + image = "tomcat" + src_tag = "latest" + TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_scan_image_name, harbor_server, user_scan_image_name, user_001_password, image, src_tag) + #8. Send scan another image command and get tag(TA) information to check scan result, it should be finished. + self.scan.scan_artifact(TestProjects.project_scan_image_name, TestProjects.repo_name.split('/')[1], tag, **TestProjects.USER_SCAN_IMAGE_CLIENT) self.artifact.check_image_scan_result(TestProjects.project_scan_image_name, image, tag, **TestProjects.USER_SCAN_IMAGE_CLIENT) if __name__ == '__main__': diff --git a/tests/apitests/python/test_sign_image.py b/tests/apitests/python/test_sign_image.py index 2186c7235..3a02e51b9 100644 --- a/tests/apitests/python/test_sign_image.py +++ b/tests/apitests/python/test_sign_image.py @@ -16,8 +16,8 @@ class TestProjects(unittest.TestCase): def setUp(self): self.project = Project() self.user = User() - self.artifact = Artifact(api_type='artifact') - self.repo = Repository(api_type='repository') + self.artifact = Artifact() + self.repo = Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_system_level_scan_all.py b/tests/apitests/python/test_system_level_scan_all.py index f897e31fc..20c15782b 100644 --- a/tests/apitests/python/test_system_level_scan_all.py +++ b/tests/apitests/python/test_system_level_scan_all.py @@ -10,6 +10,7 @@ from library.user import User from library.repository import Repository from library.repository import push_image_to_project from library.artifact import Artifact +from library.scanner import Scanner class TestProjects(unittest.TestCase): @classmethod @@ -17,8 +18,9 @@ class TestProjects(unittest.TestCase): self.system = System() self.project= Project() self.user= User() - self.artifact = Artifact(api_type='artifact') - self.repo = Repository(api_type='repository') + self.artifact = Artifact() + self.repo = Repository() + self.scanner = Scanner() @classmethod def tearDown(self): @@ -88,10 +90,20 @@ class TestProjects(unittest.TestCase): self.system.scan_now(**ADMIN_CLIENT) #5. Check if image in project_Alice and another image in project_Luca were both scanned. - #self.repo.check_image_scan_result(TestProjects.repo_Alice_name, tag_Alice, **USER_ALICE_CLIENT) - #self.repo.check_image_scan_result(TestProjects.repo_Luca_name, tag_Luca, **USER_LUCA_CLIENT) self.artifact.check_image_scan_result(TestProjects.project_Alice_name, image_a, tag_Alice, **USER_ALICE_CLIENT) self.artifact.check_image_scan_result(TestProjects.project_Luca_name, image_b, tag_Luca, **USER_LUCA_CLIENT) + #6. Swith Scanner; + uuid = self.scanner.scanners_get_uuid(**ADMIN_CLIENT) + self.scanner.scanners_registration_id_patch(uuid, **ADMIN_CLIENT) + + #7. Trigger scan all event; + self.system.scan_now(**ADMIN_CLIENT) + + #8. Check if image in project_Alice and another image in project_Luca were both scanned. + self.artifact.check_image_scan_result(TestProjects.project_Alice_name, image_a, tag_Alice, **USER_ALICE_CLIENT) + self.artifact.check_image_scan_result(TestProjects.project_Luca_name, image_b, tag_Luca, **USER_LUCA_CLIENT) + + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/tests/robot-cases/Group0-BAT/API_DB.robot b/tests/robot-cases/Group0-BAT/API_DB.robot index 8fbe670e4..a9c7d1f18 100644 --- a/tests/robot-cases/Group0-BAT/API_DB.robot +++ b/tests/robot-cases/Group0-BAT/API_DB.robot @@ -17,6 +17,10 @@ ${SERVER_API_ENDPOINT} ${SERVER_URL}/api &{SERVER_CONFIG} endpoint=${SERVER_API_ENDPOINT} verify_ssl=False *** Test Cases *** +Test Case - Scan Image + Harbor API Test ./tests/apitests/python/test_scan_image_artifact.py +Test Case - Scan All Images + Harbor API Test ./tests/apitests/python/test_system_level_scan_all.py Test Case - Garbage Collection Harbor API Test ./tests/apitests/python/test_garbage_collection.py Test Case - Add Private Project Member and Check User Can See It @@ -29,10 +33,6 @@ Test Case - Add Replication Rule Harbor API Test ./tests/apitests/python/test_add_replication_rule.py Test Case - Edit Project Creation Harbor API Test ./tests/apitests/python/test_edit_project_creation.py -Test Case - Scan Image - Harbor API Test ./tests/apitests/python/test_scan_image_artifact.py -Test Case - Scan All Images - Harbor API Test ./tests/apitests/python/test_system_level_scan_all.py Test Case - Manage Project Member Harbor API Test ./tests/apitests/python/test_manage_project_member.py Test Case - Project Level Policy Content Trust @@ -64,7 +64,7 @@ Test Case - Health Check Harbor API Test ./tests/apitests/python/test_health_check.py Test Case - Push Index By Docker Manifest Harbor API Test ./tests/apitests/python/test_push_index_by_docker_manifest.py -Test Case - Push Index By Docker Manifest +Test Case - Push Chart By Helm3 Chart CLI Harbor API Test ./tests/apitests/python/test_push_chart_by_helm3_chart_cli.py Test Case - Push Cnab Bundle Harbor API Test ./tests/apitests/python/test_push_cnab_bundle.py