Upgrade repository API tests to V2.0

Enable _xsrf in cookies in swagger.yaml, so that scripts don't have to handle it.

Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
danfengliu 2020-02-21 17:08:27 +08:00
parent c2a77c2825
commit 4933bb634f
14 changed files with 106 additions and 81 deletions

View File

@ -498,6 +498,7 @@ swagger_client:
rm -rf harborclient rm -rf harborclient
mkdir -p harborclient/harbor_swagger_client mkdir -p harborclient/harbor_swagger_client
mkdir -p harborclient/harbor_v2_swagger_client mkdir -p harborclient/harbor_v2_swagger_client
sed -i "/type: basic/ a\\security:\n - basicAuth: []" api/v2.0/swagger.yaml
java -jar swagger-codegen-cli.jar generate -i api/v2.0/legacy_swagger.yaml -l python -o harborclient/harbor_swagger_client -DpackageName=swagger_client java -jar swagger-codegen-cli.jar generate -i api/v2.0/legacy_swagger.yaml -l python -o harborclient/harbor_swagger_client -DpackageName=swagger_client
java -jar swagger-codegen-cli.jar generate -i api/v2.0/swagger.yaml -l python -o harborclient/harbor_v2_swagger_client -DpackageName=v2_swagger_client java -jar swagger-codegen-cli.jar generate -i api/v2.0/swagger.yaml -l python -o harborclient/harbor_v2_swagger_client -DpackageName=v2_swagger_client
cd harborclient/harbor_swagger_client; python ./setup.py install cd harborclient/harbor_swagger_client; python ./setup.py install

View File

@ -5,5 +5,21 @@ import v2_swagger_client
from v2_swagger_client.rest import ApiException from v2_swagger_client.rest import ApiException
class Artifact(base.Base): class Artifact(base.Base):
def create_artifact(self, expect_status_code = 201, expect_response_body = None, **kwargs): def get_reference_info(self, project_name, repo_name, reference, **kwargs):
return None client = self._get_client(**kwargs)
return client.get_artifact_with_http_info(project_name, repo_name, reference)
def copy_artifact(self, project_name, repo_name, _from, expect_status_code = 201, expect_response_body = None, **kwargs):
client = self._get_client(**kwargs)
try:
data, status_code, _ = client.copy_artifact_with_http_info(project_name, repo_name, _from)
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(201, status_code)
return data

View File

@ -34,8 +34,9 @@ def _create_client(server, credential, debug, api_type="products"):
if proxy: if proxy:
cfg.proxy = proxy cfg.proxy = proxy
return { return {
"products": swagger_client.ProductsApi(swagger_client.ApiClient(cfg)), "products": swagger_client.ProductsApi(swagger_client.ApiClient(cfg)),
"artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)), "artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)),
"repository": v2_swagger_client.RepositoryApi(v2_swagger_client.ApiClient(cfg)),
}.get(api_type,'Error: Wrong API type') }.get(api_type,'Error: Wrong API type')
def _assert_status_code(expect_code, return_code): def _assert_status_code(expect_code, return_code):
@ -96,4 +97,4 @@ class Base:
credential.username = kwargs.get("username") credential.username = kwargs.get("username")
if "password" in kwargs: if "password" in kwargs:
credential.password = kwargs.get("password") credential.password = kwargs.get("password")
return _create_client(server, credential, self.debug) return _create_client(server, credential, self.debug, self.api_type)

View File

@ -72,14 +72,14 @@ class Repository(base.Base):
if self.image_exists(repository, tag, **kwargs): if self.image_exists(repository, tag, **kwargs):
raise Exception("image %s:%s exists" % (repository, tag)) raise Exception("image %s:%s exists" % (repository, tag))
def delete_repoitory(self, repo_name, **kwargs): def delete_repoitory(self, project_name, repo_name, **kwargs):
client = self._get_client(**kwargs) client = self._get_client(**kwargs)
_, status_code, _ = client.repositories_repo_name_delete_with_http_info(repo_name) _, status_code, _ = client.delete_repository_with_http_info(project_name, repo_name)
base._assert_status_code(200, status_code) base._assert_status_code(200, status_code)
def get_repository(self, project_id, **kwargs): def get_repository(self, project_name, **kwargs):
client = self._get_client(**kwargs) client = self._get_client(**kwargs)
data, status_code, _ = client.repositories_get_with_http_info(project_id) data, status_code, _ = client.list_repositories_with_http_info(project_name)
base._assert_status_code(200, status_code) base._assert_status_code(200, status_code)
return data return data

View File

@ -22,6 +22,8 @@ class TestProjects(unittest.TestCase):
repo = Repository() repo = Repository()
self.repo= repo self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
label = Label() label = Label()
self.label= label self.label= label
@ -33,7 +35,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_add_g_lbl_CLIENT) self.repo_v2.delete_repoitory(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_add_g_lbl_CLIENT)
#2. Delete project(PA); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT) self.project.delete_project(TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT)
@ -71,7 +73,7 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_add_g_lbl_CLIENT=dict(endpoint = url, username = user_add_g_lbl_name, password = user_001_password) TestProjects.USER_add_g_lbl_CLIENT=dict(endpoint = url, username = user_add_g_lbl_name, password = user_001_password)
#2. Create private project-001 #2. Create private project-001
TestProjects.project_add_g_lbl_id, project_add_g_lbl_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT) TestProjects.project_add_g_lbl_id, TestProjects.project_add_g_lbl_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT)
#3. Add user-001 as a member of project-001 with project-admin role #3. Add user-001 as a member of project-001 with project-admin role
self.project.add_project_members(TestProjects.project_add_g_lbl_id, TestProjects.user_add_g_lbl_id, **ADMIN_CLIENT) self.project.add_project_members(TestProjects.project_add_g_lbl_id, TestProjects.user_add_g_lbl_id, **ADMIN_CLIENT)
@ -81,7 +83,7 @@ class TestProjects(unittest.TestCase):
expected_project_id = TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT) expected_project_id = TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT)
#5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
TestProjects.repo_name, tag = push_image_to_project(project_add_g_lbl_name, harbor_server, user_add_g_lbl_name, user_001_password, "hello-world", "latest") TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_add_g_lbl_name, harbor_server, user_add_g_lbl_name, user_001_password, "hello-world", "latest")
#6. Create a new label(LA) in project(PA) by admin; #6. Create a new label(LA) in project(PA) by admin;
TestProjects.label_id, _ = self.label.create_label(**ADMIN_CLIENT) TestProjects.label_id, _ = self.label.create_label(**ADMIN_CLIENT)

View File

@ -8,6 +8,7 @@ from testutils import ADMIN_CLIENT
from testutils import harbor_server from testutils import harbor_server
from testutils import TEARDOWN from testutils import TEARDOWN
from library.artifact import Artifact
from library.project import Project from library.project import Project
from library.user import User from library.user import User
from library.repository import Repository from library.repository import Repository
@ -23,7 +24,9 @@ class TestProjects(unittest.TestCase):
user = User() user = User()
self.user= user self.user= user
repo = Repository() artifact = Artifact(api_type='artifact')
self.artifact= artifact
repo = Repository(api_type='repository')
self.repo= repo self.repo= repo
@classmethod @classmethod
@ -33,10 +36,10 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA); #1. Delete repository(RA);
self.repo.delete_repoitory(TestProjects.src_repo_name, **TestProjects.USER_RETAG_CLIENT) self.repo.delete_repoitory(TestProjects.project_src_repo_name, (TestProjects.src_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT)
#2. Delete repository by retag; #2. Delete repository by retag;
self.repo.delete_repoitory(TestProjects.dst_repo_name, **TestProjects.USER_RETAG_CLIENT) self.repo.delete_repoitory(TestProjects.project_dst_repo_name, (TestProjects.dst_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT)
#3. Delete project(PA); #3. Delete project(PA);
self.project.delete_project(TestProjects.project_src_repo_id, **TestProjects.USER_RETAG_CLIENT) self.project.delete_project(TestProjects.project_src_repo_id, **TestProjects.USER_RETAG_CLIENT)
@ -73,7 +76,6 @@ class TestProjects(unittest.TestCase):
user_retag_password = "Aa123456" user_retag_password = "Aa123456"
pull_tag_name = "latest" pull_tag_name = "latest"
dst_repo_sub_name = "repo" dst_repo_sub_name = "repo"
dst_tag_name = "test_tag"
#1. Create a new user(UA); #1. Create a new user(UA);
TestProjects.user_retag_id, user_retag_name = self.user.create_user(user_password = user_retag_password, **ADMIN_CLIENT) TestProjects.user_retag_id, user_retag_name = self.user.create_user(user_password = user_retag_password, **ADMIN_CLIENT)
@ -81,10 +83,10 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_RETAG_CLIENT=dict(endpoint = url, username = user_retag_name, password = user_retag_password) TestProjects.USER_RETAG_CLIENT=dict(endpoint = url, username = user_retag_name, password = user_retag_password)
#2. Create a new project(PA) by user(UA); #2. Create a new project(PA) by user(UA);
TestProjects.project_src_repo_id, project_src_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RETAG_CLIENT) TestProjects.project_src_repo_id, TestProjects.project_src_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RETAG_CLIENT)
#3. Create a new project(PB) by user(UA); #3. Create a new project(PB) by user(UA);
TestProjects.project_dst_repo_id, project_dst_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RETAG_CLIENT) TestProjects.project_dst_repo_id, TestProjects.project_dst_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RETAG_CLIENT)
retag_member_id = self.project.get_project_member_id(TestProjects.project_dst_repo_id, user_retag_name, **TestProjects.USER_RETAG_CLIENT) retag_member_id = self.project.get_project_member_id(TestProjects.project_dst_repo_id, user_retag_name, **TestProjects.USER_RETAG_CLIENT)
@ -92,34 +94,32 @@ class TestProjects(unittest.TestCase):
self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 3, **ADMIN_CLIENT) self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 3, **ADMIN_CLIENT)
#5. Create a new repository(RA) in project(PA) by user(UA); #5. Create a new repository(RA) in project(PA) by user(UA);
TestProjects.src_repo_name, tag_name = push_image_to_project(project_src_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", pull_tag_name) TestProjects.src_repo_name, tag_name = push_image_to_project(TestProjects.project_src_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", pull_tag_name)
#6. Get repository in project(PA), there should be one repository which was created by user(UA); #6. Get repository in project(PA), there should be one repository which was created by user(UA);
src_repo_data = self.repo.get_repository(TestProjects.project_src_repo_id, **TestProjects.USER_RETAG_CLIENT) src_repo_data = self.repo.get_repository(TestProjects.project_src_repo_name, **TestProjects.USER_RETAG_CLIENT)
_assert_status_code(TestProjects.src_repo_name, src_repo_data[0].name) _assert_status_code(TestProjects.src_repo_name, src_repo_data[0].name)
#7. Get repository(RA)'s image tag detail information; #7. Get repository(RA)'s image tag detail information;
src_tag_data = self.repo.get_tag(TestProjects.src_repo_name, tag_name, **TestProjects.USER_RETAG_CLIENT) src_tag_data = self.artifact.get_reference_info(TestProjects.project_src_repo_name, TestProjects.src_repo_name.split('/')[1], tag_name, **TestProjects.USER_RETAG_CLIENT)
TestProjects.dst_repo_name = TestProjects.project_dst_repo_name+"/"+ dst_repo_sub_name
TestProjects.dst_repo_name = project_dst_repo_name+"/"+ dst_repo_sub_name
#8. Retag image in project(PA) to project(PB), it should be forbidden; #8. Retag image in project(PA) to project(PB), it should be forbidden;
self.repo.retag_image(TestProjects.dst_repo_name, dst_tag_name, TestProjects.src_repo_name+":"+src_tag_data.digest, expect_status_code=403, **TestProjects.USER_RETAG_CLIENT) self.artifact.copy_artifact(TestProjects.project_dst_repo_name, dst_repo_sub_name, TestProjects.src_repo_name+"@"+src_tag_data[0].digest, expect_status_code=403, **TestProjects.USER_RETAG_CLIENT)
#9. Update role of user-retag as admin member of project(PB); #9. Update role of user-retag as admin member of project(PB);
self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 1, **ADMIN_CLIENT) self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 1, **ADMIN_CLIENT)
#10. Retag image in project(PA) to project(PB), it should be successful; #10. Retag image in project(PA) to project(PB), it should be successful;
self.repo.retag_image(TestProjects.dst_repo_name, dst_tag_name, TestProjects.src_repo_name+":"+src_tag_data.digest, **TestProjects.USER_RETAG_CLIENT) self.artifact.copy_artifact(TestProjects.project_dst_repo_name, dst_repo_sub_name, TestProjects.src_repo_name+"@"+src_tag_data[0].digest, **TestProjects.USER_RETAG_CLIENT)
#11. Get repository(RB)'s image tag detail information; #11. Get repository(RB)'s image tag detail information;
dst_tag_data = self.repo.get_tag(TestProjects.dst_repo_name, dst_tag_name, **TestProjects.USER_RETAG_CLIENT) dst_tag_data = self.artifact.get_reference_info(TestProjects.project_dst_repo_name, dst_repo_sub_name, tag_name, **TestProjects.USER_RETAG_CLIENT)
#12. Read digest of retaged image, it must be the same with the image in repository(RA); #12. Read digest of retaged image, it must be the same with the image in repository(RA);
self.assertEqual(src_tag_data.digest, dst_tag_data.digest) self.assertEqual(src_tag_data[0].digest, dst_tag_data[0].digest)
#13. Pull image from project(PB) by user_retag, it must be successful;" #13. Pull image from project(PB) by user_retag, it must be successful;"
pull_harbor_image(harbor_server, user_retag_name, user_retag_password, TestProjects.dst_repo_name, dst_tag_name) pull_harbor_image(harbor_server, user_retag_name, user_retag_password, TestProjects.dst_repo_name, tag_name)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -22,10 +22,9 @@ class TestProjects(unittest.TestCase):
user = User() user = User()
self.user= user self.user= user
repo = Repository() repo = Repository(api_type='repository')
self.repo= repo self.repo= repo
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
print "Case completed" print "Case completed"
@ -62,20 +61,20 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_del_repo_CLIENT=dict(endpoint = url, username = user_del_repo_name, password = user_del_repo_password) TestProjects.USER_del_repo_CLIENT=dict(endpoint = url, username = user_del_repo_name, password = user_del_repo_password)
#2. Create a new project(PA) by user(UA); #2. Create a new project(PA) by user(UA);
TestProjects.project_del_repo_id, project_del_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_del_repo_CLIENT) TestProjects.project_del_repo_id, TestProjects.project_del_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_del_repo_CLIENT)
#3. Create a new repository(RA) in project(PA) by user(UA); #3. Create a new repository(RA) in project(PA) by user(UA);
repo_name, _ = push_image_to_project(project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", "latest") repo_name, _ = push_image_to_project(TestProjects.project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", "latest")
#4. Get repository in project(PA), there should be one repository which was created by user(UA); #4. Get repository in project(PA), there should be one repository which was created by user(UA);
repo_data = self.repo.get_repository(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT) repo_data = self.repo.get_repository(TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT)
_assert_status_code(repo_name, repo_data[0].name) _assert_status_code(repo_name, repo_data[0].name)
#5. Delete repository(RA) by user(UA); #5. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(repo_name, **TestProjects.USER_del_repo_CLIENT) self.repo.delete_repoitory(TestProjects.project_del_repo_name, repo_name.split('/')[1], **TestProjects.USER_del_repo_CLIENT)
#6. Get repository by user(UA), it should get nothing; #6. Get repository by user(UA), it should get nothing;
repo_data = self.repo.get_repository(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT) repo_data = self.repo.get_repository(TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT)
_assert_status_code(len(repo_data), 0) _assert_status_code(len(repo_data), 0)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -24,7 +24,7 @@ class TestProjects(unittest.TestCase):
user = User() user = User()
self.user= user self.user= user
repo = Repository() repo = Repository(api_type='repository')
self.repo= repo self.repo= repo
@classmethod @classmethod
@ -67,16 +67,16 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_GC_CLIENT=dict(endpoint = url, username = user_gc_name, password = user_gc_password) TestProjects.USER_GC_CLIENT=dict(endpoint = url, username = user_gc_name, password = user_gc_password)
#2. Create a new project(PA) by user(UA); #2. Create a new project(PA) by user(UA);
TestProjects.project_gc_id, project_gc_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_GC_CLIENT) TestProjects.project_gc_id, TestProjects.project_gc_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_GC_CLIENT)
#3. Push a new image(IA) in project(PA) by admin; #3. Push a new image(IA) in project(PA) by admin;
repo_name, _ = push_image_to_project(project_gc_name, harbor_server, admin_name, admin_password, "tomcat", "latest") repo_name, _ = push_image_to_project(TestProjects.project_gc_name, harbor_server, admin_name, admin_password, "tomcat", "latest")
#4. Delete repository(RA) by user(UA); #4. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(repo_name, **TestProjects.USER_GC_CLIENT) self.repo.delete_repoitory(TestProjects.project_gc_name, repo_name.split('/')[1], **TestProjects.USER_GC_CLIENT)
#5. Get repository by user(UA), it should get nothing; #5. Get repository by user(UA), it should get nothing;
repo_data = self.repo.get_repository(TestProjects.project_gc_id, **TestProjects.USER_GC_CLIENT) repo_data = self.repo.get_repository(TestProjects.project_gc_name, **TestProjects.USER_GC_CLIENT)
_assert_status_code(len(repo_data), 0) _assert_status_code(len(repo_data), 0)
#6. Tigger garbage collection operation; #6. Tigger garbage collection operation;

View File

@ -19,7 +19,7 @@ class TestProjects(unittest.TestCase):
user = User() user = User()
self.user= user self.user= user
repo = Repository() repo = Repository(api_type='repository')
self.repo= repo self.repo= repo
@classmethod @classmethod
@ -29,7 +29,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by admin; #1. Delete repository(RA) by admin;
self.repo.delete_repoitory(TestProjects.repo_name, **ADMIN_CLIENT) self.repo.delete_repoitory(TestProjects.project_alice_name, TestProjects.repo_name.split('/')[1], **ADMIN_CLIENT)
#2. Delete project(Alice); #2. Delete project(Alice);
self.project.delete_project(TestProjects.project_alice_id, **ADMIN_CLIENT) self.project.delete_project(TestProjects.project_alice_id, **ADMIN_CLIENT)
@ -57,7 +57,7 @@ class TestProjects(unittest.TestCase):
Tear down: Tear down:
1. Delete repository(RA) by admin; 1. Delete repository(RA) by admin;
2. Delete project(Alice); 2. Delete project(Alice);
3. Delete user Alice, Bob and Carol. 3. Delete user Alice, Bob and Carol.
""" """
url = ADMIN_CLIENT["endpoint"] url = ADMIN_CLIENT["endpoint"]
user_alice_password = "Aa123456" user_alice_password = "Aa123456"
@ -76,10 +76,10 @@ class TestProjects(unittest.TestCase):
TestProjects.user_carol_id, user_carol_name = self.user.create_user(user_password = user_carol_password, **ADMIN_CLIENT) TestProjects.user_carol_id, user_carol_name = self.user.create_user(user_password = user_carol_password, **ADMIN_CLIENT)
#2.1 Create private project(PA) by Alice #2.1 Create private project(PA) by Alice
TestProjects.project_alice_id, project_alice_name = self.project.create_project(metadata = {"public": "false"}, **USER_ALICE_CLIENT) TestProjects.project_alice_id, TestProjects.project_alice_name = self.project.create_project(metadata = {"public": "false"}, **USER_ALICE_CLIENT)
#2.2 Add a repository to project(PA) by Alice #2.2 Add a repository to project(PA) by Alice
TestProjects.repo_name, _ = push_image_to_project(project_alice_name, harbor_server, user_alice_name, user_alice_password, "hello-world", "latest") TestProjects.repo_name, _ = push_image_to_project(TestProjects.project_alice_name, harbor_server, user_alice_name, user_alice_password, "hello-world", "latest")
#3. Bob is not a member of project(PA); #3. Bob is not a member of project(PA);
self.project.check_project_member_not_exist(TestProjects.project_alice_id, user_bob_name, **USER_ALICE_CLIENT) self.project.check_project_member_not_exist(TestProjects.project_alice_id, user_bob_name, **USER_ALICE_CLIENT)

View File

@ -23,6 +23,8 @@ class TestProjects(unittest.TestCase):
repo = Repository() repo = Repository()
self.repo= repo self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
@classmethod @classmethod
def tearDown(self): def tearDown(self):
@ -31,7 +33,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_CONTENT_TRUST_CLIENT) self.repo_v2.delete_repoitory(TestProjects.project_content_trust_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_CONTENT_TRUST_CLIENT)
#2. Delete project(PA); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT) self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT)
@ -67,10 +69,10 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_CONTENT_TRUST_CLIENT=dict(endpoint = url, username = user_content_trust_name, password = user_content_trust_password) TestProjects.USER_CONTENT_TRUST_CLIENT=dict(endpoint = url, username = user_content_trust_name, password = user_content_trust_password)
#2. Create a new project(PA) by user(UA); #2. Create a new project(PA) by user(UA);
TestProjects.project_content_trust_id, project_content_trust_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CONTENT_TRUST_CLIENT) TestProjects.project_content_trust_id, TestProjects.project_content_trust_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CONTENT_TRUST_CLIENT)
#3. Push a new image(IA) in project(PA) by admin; #3. Push a new image(IA) in project(PA) by admin;
TestProjects.repo_name, tag = push_image_to_project(project_content_trust_name, harbor_server, admin_name, admin_password, "hello-world", "latest") TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_content_trust_name, harbor_server, admin_name, admin_password, "hello-world", "latest")
#4. Image(IA) should exist; #4. Image(IA) should exist;
self.repo.image_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_CONTENT_TRUST_CLIENT) self.repo.image_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_CONTENT_TRUST_CLIENT)

View File

@ -35,7 +35,7 @@ class TestProjects(unittest.TestCase):
def setUpClass(self): def setUpClass(self):
self.user = User() self.user = User()
self.system = System() self.system = System()
self.repo= Repository() self.repo= Repository(api_type='repository')
self.project = Project() self.project = Project()
self.retention=Retention() self.retention=Retention()
@ -48,18 +48,18 @@ class TestProjects(unittest.TestCase):
password=user_ra_password) password=user_ra_password)
TestProjects.user_ra_id = int(user_ra_id) TestProjects.user_ra_id = int(user_ra_id)
TestProjects.project_src_repo_id, project_src_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_src_repo_id, TestProjects.project_src_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT)
# Push image test1:1.0, test1:2.0, test1:3.0,latest, test2:1.0, test2:latest, test3:1.0 # Push image test1:1.0, test1:2.0, test1:3.0,latest, test2:1.0, test2:latest, test3:1.0
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['1.0']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['1.0'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['2.0']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['2.0'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['3.0','latest']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['3.0','latest'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['1.0']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['1.0'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['latest']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['latest'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test3", ['1.0']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test3", ['1.0'])
push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test4", ['1.0']) push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test4", ['1.0'])
resp=self.repo.get_repository(TestProjects.project_src_repo_id, **TestProjects.USER_RA_CLIENT) resp=self.repo.get_repository(TestProjects.project_src_repo_name, **TestProjects.USER_RA_CLIENT)
self.assertEqual(len(resp), 4) self.assertEqual(len(resp), 4)
# Create Retention Policy # Create Retention Policy

View File

@ -21,7 +21,7 @@ class TestProjects(unittest.TestCase):
user = User() user = User()
self.user= user self.user= user
repo = Repository() repo = Repository(api_type='repository')
self.repo= repo self.repo= repo
@classmethod @classmethod
@ -31,10 +31,10 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name_in_project_a, **TestProjects.USER_RA_CLIENT) self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_in_project_a.split('/')[1], **TestProjects.USER_RA_CLIENT)
self.repo.delete_repoitory(TestProjects.repo_name_in_project_b, **TestProjects.USER_RA_CLIENT) self.repo.delete_repoitory(TestProjects.project_ra_name_b, TestProjects.repo_name_in_project_b.split('/')[1], **TestProjects.USER_RA_CLIENT)
self.repo.delete_repoitory(TestProjects.repo_name_in_project_c, **TestProjects.USER_RA_CLIENT) self.repo.delete_repoitory(TestProjects.project_ra_name_c, TestProjects.repo_name_in_project_c.split('/')[1], **TestProjects.USER_RA_CLIENT)
self.repo.delete_repoitory(TestProjects.repo_name_pa, **TestProjects.USER_RA_CLIENT) self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_pa.split('/')[1], **TestProjects.USER_RA_CLIENT)
#2. Delete project(PA); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_ra_id_a, **TestProjects.USER_RA_CLIENT) self.project.delete_project(TestProjects.project_ra_id_a, **TestProjects.USER_RA_CLIENT)
@ -84,17 +84,17 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_RA_CLIENT=dict(endpoint = url, username = user_ra_name, password = user_ra_password) TestProjects.USER_RA_CLIENT=dict(endpoint = url, username = user_ra_name, password = user_ra_password)
print "#2. Create private project(PA), private project(PB) and public project(PC) by user(UA);" print "#2. Create private project(PA), private project(PB) and public project(PC) by user(UA);"
TestProjects.project_ra_id_a, project_ra_name_a = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_ra_id_a, TestProjects.project_ra_name_a = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT)
TestProjects.project_ra_id_b, project_ra_name_b = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_ra_id_b, TestProjects.project_ra_name_b = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT)
TestProjects.project_ra_id_c, project_ra_name_c = self.project.create_project(metadata = {"public": "true"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_ra_id_c, TestProjects.project_ra_name_c = self.project.create_project(metadata = {"public": "true"}, **TestProjects.USER_RA_CLIENT)
print "#3. Push image(ImagePA) to project(PA), image(ImagePB) to project(PB) and image(ImagePC) to project(PC) by user(UA);" print "#3. Push image(ImagePA) to project(PA), image(ImagePB) to project(PB) and image(ImagePC) to project(PC) by user(UA);"
TestProjects.repo_name_in_project_a, tag_a = push_image_to_project(project_ra_name_a, harbor_server, user_ra_name, user_ra_password, image_project_a, tag) TestProjects.repo_name_in_project_a, tag_a = push_image_to_project(TestProjects.project_ra_name_a, harbor_server, user_ra_name, user_ra_password, image_project_a, tag)
TestProjects.repo_name_in_project_b, tag_b = push_image_to_project(project_ra_name_b, harbor_server, user_ra_name, user_ra_password, image_project_b, tag) TestProjects.repo_name_in_project_b, tag_b = push_image_to_project(TestProjects.project_ra_name_b, harbor_server, user_ra_name, user_ra_password, image_project_b, tag)
TestProjects.repo_name_in_project_c, tag_c = push_image_to_project(project_ra_name_c, harbor_server, user_ra_name, user_ra_password, image_project_c, tag) TestProjects.repo_name_in_project_c, tag_c = push_image_to_project(TestProjects.project_ra_name_c, harbor_server, user_ra_name, user_ra_password, image_project_c, tag)
print "#4. Create a new robot account(RA) with pull and push privilige in project(PA) by user(UA);" print "#4. Create a new robot account(RA) with pull and push privilige in project(PA) by user(UA);"
robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_ra_id_a, project_ra_name_a, robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_ra_id_a, TestProjects.project_ra_name_a,
2441000531 ,**TestProjects.USER_RA_CLIENT) 2441000531 ,**TestProjects.USER_RA_CLIENT)
print robot_account.name print robot_account.name
print robot_account.token print robot_account.token
@ -107,10 +107,10 @@ class TestProjects(unittest.TestCase):
pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a) pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a)
print "#7. Push image(ImageRA) to project(PA) by robot account(RA), it must be successful;" print "#7. Push image(ImageRA) to project(PA) by robot account(RA), it must be successful;"
TestProjects.repo_name_pa, _ = push_image_to_project(project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag) TestProjects.repo_name_pa, _ = push_image_to_project(TestProjects.project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag)
print "#8. Push image(ImageRA) to project(PB) by robot account(RA), it must be not successful;" print "#8. Push image(ImageRA) to project(PB) by robot account(RA), it must be not successful;"
push_image_to_project(project_ra_name_b, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository") push_image_to_project(TestProjects.project_ra_name_b, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository")
print "#9. Pull image(ImagePB) from project(PB) by robot account(RA), it must be not successful;" print "#9. Pull image(ImagePB) from project(PB) by robot account(RA), it must be not successful;"
pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_b, tag_b, expected_error_message = "unauthorized to access repository") pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_b, tag_b, expected_error_message = "unauthorized to access repository")
@ -119,7 +119,7 @@ class TestProjects(unittest.TestCase):
pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_c, tag_c) pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_c, tag_c)
print "#11. Push image(ImageRA) to project(PC) by robot account(RA), it must be not successful;" print "#11. Push image(ImageRA) to project(PC) by robot account(RA), it must be not successful;"
push_image_to_project(project_ra_name_c, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository") push_image_to_project(TestProjects.project_ra_name_c, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository")
print "#12. Update action property of robot account(RA);" print "#12. Update action property of robot account(RA);"
self.project.disable_project_robot_account(TestProjects.project_ra_id_a, robot_id, True, **TestProjects.USER_RA_CLIENT) self.project.disable_project_robot_account(TestProjects.project_ra_id_a, robot_id, True, **TestProjects.USER_RA_CLIENT)
@ -128,7 +128,7 @@ class TestProjects(unittest.TestCase):
pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a, expected_login_error_message = "401 Unauthorized") pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a, expected_login_error_message = "401 Unauthorized")
print "#14. Push image(ImageRA) to project(PA) by robot account(RA), it must be not successful;" print "#14. Push image(ImageRA) to project(PA) by robot account(RA), it must be not successful;"
push_image_to_project(project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_login_error_message = "401 Unauthorized") push_image_to_project(TestProjects.project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_login_error_message = "401 Unauthorized")
print "#15. Delete robot account(RA), it must be not successful." print "#15. Delete robot account(RA), it must be not successful."
self.project.delete_project_robot_account(TestProjects.project_ra_id_a, robot_id, **TestProjects.USER_RA_CLIENT) self.project.delete_project_robot_account(TestProjects.project_ra_id_a, robot_id, **TestProjects.USER_RA_CLIENT)

View File

@ -21,6 +21,8 @@ class TestProjects(unittest.TestCase):
repo = Repository() repo = Repository()
self.repo= repo self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
@classmethod @classmethod
def tearDown(self): def tearDown(self):
@ -29,7 +31,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == True, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_sign_image_CLIENT) self.repo_v2.delete_repoitory(TestProjects.project_sign_image_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_sign_image_CLIENT)
#2. Delete project(PA); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT) self.project.delete_project(TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT)
@ -61,7 +63,7 @@ class TestProjects(unittest.TestCase):
TestProjects.USER_sign_image_CLIENT=dict(endpoint = url, username = user_sign_image_name, password = user_001_password) TestProjects.USER_sign_image_CLIENT=dict(endpoint = url, username = user_sign_image_name, password = user_001_password)
#2. Create a new private project(PA) by user(UA); #2. Create a new private project(PA) by user(UA);
TestProjects.project_sign_image_id, project_sign_image_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT) TestProjects.project_sign_image_id, TestProjects.project_sign_image_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT)
#3. Add user(UA) as a member of project(PA) with project-admin role; #3. Add user(UA) as a member of project(PA) with project-admin role;
self.project.add_project_members(TestProjects.project_sign_image_id, TestProjects.user_sign_image_id, **ADMIN_CLIENT) self.project.add_project_members(TestProjects.project_sign_image_id, TestProjects.user_sign_image_id, **ADMIN_CLIENT)
@ -73,10 +75,10 @@ class TestProjects(unittest.TestCase):
image = "hello-world" image = "hello-world"
src_tag = "latest" src_tag = "latest"
#5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA); #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
TestProjects.repo_name, tag = push_image_to_project(project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, image, src_tag) TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, image, src_tag)
#6. Sign image with tag(TA) which was tagged by step #5; #6. Sign image with tag(TA) which was tagged by step #5;
sign_image(harbor_server, project_sign_image_name, image, tag) sign_image(harbor_server, TestProjects.project_sign_image_name, image, tag)
#7. Get signature of image with tag(TA), it should be exist. #7. Get signature of image with tag(TA), it should be exist.
self.repo.signature_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_sign_image_CLIENT) self.repo.signature_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_sign_image_CLIENT)

View File

@ -24,8 +24,8 @@ ${SERVER_API_ENDPOINT} ${SERVER_URL}/api
# Harbor API Test ./tests/apitests/python/test_garbage_collection.py # Harbor API Test ./tests/apitests/python/test_garbage_collection.py
Test Case - Add Private Project Member and Check User Can See It Test Case - Add Private Project Member and Check User Can See It
Harbor API Test ./tests/apitests/python/test_add_member_to_private_project.py Harbor API Test ./tests/apitests/python/test_add_member_to_private_project.py
# Test Case - Delete a Repository of a Certain Project Created by Normal User Test Case - Delete a Repository of a Certain Project Created by Normal User
# Harbor API Test ./tests/apitests/python/test_del_repo.py Harbor API Test ./tests/apitests/python/test_del_repo.py
#Test Case - Add a System Global Label to a Certain Tag #Test Case - Add a System Global Label to a Certain Tag
# Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py # Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py
Test Case - Add Replication Rule Test Case - Add Replication Rule
@ -51,6 +51,8 @@ Test Case - Edit Project Creation
# Harbor API Test ./tests/apitests/python/test_list_helm_charts.py # Harbor API Test ./tests/apitests/python/test_list_helm_charts.py
### Test Case - Assign Sys Admin ### Test Case - Assign Sys Admin
### Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py ### Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py
Test Case - Copy Artifact Outside Project
Harbor API Test ./tests/apitests/python/test_copy_artifact_outside_project.py
### Test Case - Robot Account ### Test Case - Robot Account
### Harbor API Test ./tests/apitests/python/test_robot_account.py ### Harbor API Test ./tests/apitests/python/test_robot_account.py
### Test Case - Sign A Image ### Test Case - Sign A Image