mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Modify api test for test step of add addition
Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
parent
b0e87b46e4
commit
77e9fc38c7
@ -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':
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
26
tests/apitests/python/library/scanner.py
Normal file
26
tests/apitests/python/library/scanner.py
Normal file
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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"
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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);
|
||||
@ -70,7 +74,6 @@ class TestProjects(unittest.TestCase):
|
||||
|
||||
#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"
|
||||
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__':
|
||||
|
@ -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):
|
||||
|
@ -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()
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user