diff --git a/tests/apitests/python/library/configurations.py b/tests/apitests/python/library/configurations.py index 664658943..44c321d80 100644 --- a/tests/apitests/python/library/configurations.py +++ b/tests/apitests/python/library/configurations.py @@ -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) diff --git a/tests/apitests/python/test_add_replication_rule.py b/tests/apitests/python/test_add_replication_rule.py index 3b321224a..86035ee81 100644 --- a/tests/apitests/python/test_add_replication_rule.py +++ b/tests/apitests/python/test_add_replication_rule.py @@ -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; 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 860396727..79fb87c4e 100644 --- a/tests/apitests/python/test_add_sys_label_to_tag.py +++ b/tests/apitests/python/test_add_sys_label_to_tag.py @@ -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; diff --git a/tests/apitests/python/test_assign_sys_admin.py b/tests/apitests/python/test_assign_sys_admin.py new file mode 100644 index 000000000..d098d1495 --- /dev/null +++ b/tests/apitests/python/test_assign_sys_admin.py @@ -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() + diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py index e9215547e..ac4a6b552 100644 --- a/tests/apitests/python/test_del_repo.py +++ b/tests/apitests/python/test_del_repo.py @@ -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); diff --git a/tests/apitests/python/test_edit_project_creation.py b/tests/apitests/python/test_edit_project_creation.py index 09c3ba22b..53b4056e0 100644 --- a/tests/apitests/python/test_edit_project_creation.py +++ b/tests/apitests/python/test_edit_project_creation.py @@ -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; diff --git a/tests/apitests/python/test_manage_project_member.py b/tests/apitests/python/test_manage_project_member.py index 2d6adf918..901523e62 100644 --- a/tests/apitests/python/test_manage_project_member.py +++ b/tests/apitests/python/test_manage_project_member.py @@ -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" 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 7326478d6..4e38c1c29 100644 --- a/tests/apitests/python/test_project_level_policy_content_trust.py +++ b/tests/apitests/python/test_project_level_policy_content_trust.py @@ -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; diff --git a/tests/apitests/python/test_scan_all_images.py b/tests/apitests/python/test_scan_all_images.py index 29bac292f..d23b964c5 100644 --- a/tests/apitests/python/test_scan_all_images.py +++ b/tests/apitests/python/test_scan_all_images.py @@ -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; diff --git a/tests/apitests/python/test_scan_image.py b/tests/apitests/python/test_scan_image.py index d2f2c975b..764d5fb08 100644 --- a/tests/apitests/python/test_scan_image.py +++ b/tests/apitests/python/test_scan_image.py @@ -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; diff --git a/tests/robot-cases/Group0-BAT/API_DB.robot b/tests/robot-cases/Group0-BAT/API_DB.robot index 2614b39fc..a92d86a55 100644 --- a/tests/robot-cases/Group0-BAT/API_DB.robot +++ b/tests/robot-cases/Group0-BAT/API_DB.robot @@ -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 \ No newline at end of file + 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 \ No newline at end of file