Add API test case assign system admin role. (#6413)

Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
danfengliu 2018-12-04 12:26:12 +08:00 committed by Yan
parent 7d4de8743b
commit 3356368bff
11 changed files with 100 additions and 33 deletions

View File

@ -45,14 +45,14 @@ class Configurations(base.Base):
return data
def set_configurations_of_project_creation_restriction(self, project_creation_restriction, **kwargs):
def set_configurations_of_project_creation_restriction(self, project_creation_restriction, expect_status_code = 200, **kwargs):
client = self._get_client(**kwargs)
config=dict(project_creation_restriction=project_creation_restriction)
set_configurations(client, **config)
set_configurations(client, expect_status_code = expect_status_code, **config)
def set_configurations_of_token_expiration(self, token_expiration, **kwargs):
def set_configurations_of_token_expiration(self, token_expiration, expect_status_code = 200, **kwargs):
client = self._get_client(**kwargs)
config=dict(token_expiration=token_expiration)
set_configurations(client, **config)
set_configurations(client, expect_status_code = expect_status_code, **config)

View File

@ -28,7 +28,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete rule(RA);
for rule_id in TestProjects.rule_id_list:
@ -47,7 +47,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Add Replication Rule
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Create a new private project(PA) by user(UA);
3. Create a new target(TA)/registry;

View File

@ -30,7 +30,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_add_g_lbl_CLIENT)
@ -48,7 +48,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Add Global Label To Tag
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Create a new private project(PA) by user(UA);
3. Add user(UA) as a member of project(PA) with project-admin role;

View File

@ -0,0 +1,61 @@
from __future__ import absolute_import
import unittest
from testutils import ADMIN_CLIENT
from testutils import TEARDOWN
from library.user import User
from library.configurations import Configurations
class TestProjects(unittest.TestCase):
@classmethod
def setUp(self):
conf = Configurations()
self.conf= conf
user = User()
self.user= user
@classmethod
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete user(UA);
self.user.delete_user(TestProjects.user_assign_sys_admin_id, **ADMIN_CLIENT)
def testAssignSysAdmin(self):
"""
Test case:
Assign Sys Admin
Test step and expected result:
1. Create a new user(UA);
2. Set user(UA) has sysadmin role by admin, check user(UA) can modify system configuration;
3. 3. Set user(UA) has no sysadmin role by admin, check user(UA) can not modify system configuration;
4. Set user(UA) has sysadmin role by admin, check user(UA) can modify system configuration.
Tear down:
1. Delete user(UA).
"""
url = ADMIN_CLIENT["endpoint"]
user_assign_sys_admin_password = "Aa123456"
#1. Create a new user(UA);
TestProjects.user_assign_sys_admin_id, user_assign_sys_admin_name = self.user.create_user(user_password = user_assign_sys_admin_password, **ADMIN_CLIENT)
USER_ASSIGN_SYS_ADMIN_CLIENT=dict(endpoint = url, username = user_assign_sys_admin_name, password = user_assign_sys_admin_password)
#2. Set user(UA) has sysadmin role by admin, check user(UA) can modify system configuration;
self.user.update_uesr_role_as_sysadmin(TestProjects.user_assign_sys_admin_id, True, **ADMIN_CLIENT)
self.conf.set_configurations_of_token_expiration(60, **USER_ASSIGN_SYS_ADMIN_CLIENT)
#3. Set user(UA) has no sysadmin role by admin, check user(UA) can not modify system configuration;
self.user.update_uesr_role_as_sysadmin(TestProjects.user_assign_sys_admin_id, False, **ADMIN_CLIENT)
self.conf.set_configurations_of_token_expiration(70, expect_status_code = 403, **USER_ASSIGN_SYS_ADMIN_CLIENT)
#4. Set user(UA) has sysadmin role by admin, check user(UA) can modify system configuration.
self.user.update_uesr_role_as_sysadmin(TestProjects.user_assign_sys_admin_id, True, **ADMIN_CLIENT)
self.conf.set_configurations_of_token_expiration(80, **USER_ASSIGN_SYS_ADMIN_CLIENT)
if __name__ == '__main__':
unittest.main()

View File

@ -30,7 +30,7 @@ class TestProjects(unittest.TestCase):
def tearDownClass(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete project(PA);
self.project.delete_project(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT)
@ -42,7 +42,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Delete a repository
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Create a new project(PA) by user(UA);
3. Create a new repository(RA) in project(PA) by user(UA);

View File

@ -23,7 +23,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
print "Clear trace"
#1. Delete project(PA);
@ -36,7 +36,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Edit Project Creation
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Set project creation to "admin only";
3. Create a new project(PA) by user(UA), and fail to create a new project;

View File

@ -26,15 +26,15 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete repository(RA) by user(UA);
#1. Delete repository(RA) by admin;
self.repo.delete_repoitory(TestProjects.repo_name, **ADMIN_CLIENT)
#3. Delete project(PA);
#2. Delete project(Alice);
self.project.delete_project(TestProjects.project_alice_id, **ADMIN_CLIENT)
#4. Delete user(UA);
#3. Delete user Alice, Bob and Carol.
self.user.delete_user(TestProjects.user_alice_id, **ADMIN_CLIENT)
self.user.delete_user(TestProjects.user_bob_id, **ADMIN_CLIENT)
self.user.delete_user(TestProjects.user_carol_id, **ADMIN_CLIENT)
@ -43,17 +43,21 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Manage Project members
Test step and Expectation:
Test step and expected result:
1. Create user Alice, Bob, Carol;
2. Create private project(PA) by Alice, Add a repository to project(PA) by Alice;
3. Bob is not a member of project(PA);
4. Alice Add Bob as a guest member of project(PA), Check Bob is a guest member of project(PA);
5. Update role of Bob to developer of project(PA), Check Bob is developer member of project(PA);
6. Update role of Bob to admin member of project(PA), Check Bob is admin member of project(PA);
7. Bob add Carol to project(PA) as a guest member, Carol is a member of project(PA) as a guest;
8. Alice delete Bob from project(PA),
Bob is no longer a member of project(PA) and Bob can see project(PA),
Carol is still a member of project(PA) as a guest.
2. Create private project(Alice) by Alice, Add a repository to project(Alice) by Alice;
3. Bob is not a member of project(Alice);
4. Alice Add Bob as a guest member of project(Alice), Check Bob is a guest member of project(Alice);
5. Update role of Bob to developer of project(Alice), Check Bob is developer member of project(Alice);
6. Update role of Bob to admin member of project(Alice), Check Bob is admin member of project(Alice);
7. Bob add Carol to project(Alice) as a guest member, Carol is a member of project(Alice) as a guest;
8. Alice delete Bob from project(Alice),
Bob is no longer a member of project(Alice) and Bob can see project(Alice),
Carol is still a member of project(Alice) as a guest.
Tear down:
1. Delete repository(RA) by admin;
2. Delete project(Alice);
3. Delete user Alice, Bob and Carol.
"""
url = ADMIN_CLIENT["endpoint"]
user_alice_password = "Aa123456"

View File

@ -29,7 +29,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_CONTENT_TRUST_CLIENT)
@ -44,7 +44,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Project Level Policy Content Trust
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Create a new project(PA) by user(UA);
3. Push a new image(IA) in project(PA) by admin;

View File

@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete Alice's repository and Luca's repository;
self.repo.delete_repoitory(TestProjects.repo_Alice_name, **ADMIN_CLIENT)
@ -43,7 +43,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Scan All Image
Test step & Expectation:
Test step and expected result:
1. Create user Alice and Luca;
2. Create 2 new private projects project_Alice and project_Luca;
3. Push a image to project_Alice and push another image to project_Luca;

View File

@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase):
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == True, "Test data should be remain in the harbor.")
@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.repo_name, **TestProjects.USER_SCAN_IMAGE_CLIENT)
@ -40,7 +40,7 @@ class TestProjects(unittest.TestCase):
"""
Test case:
Scan A Image
Test step & Expectation:
Test step and expected result:
1. Create a new user(UA);
2. Create a new private project(PA) by user(UA);
3. Add user(UA) as a member of project(PA) with project-admin role;

View File

@ -40,4 +40,6 @@ Test Case - User View Logs
Test Case - Scan All Images
Harbor API Test ./tests/apitests/python/test_scan_all_images.py
Test Case - List Helm Charts
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
Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py