2018-08-01 00:38:23 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
2020-08-17 08:51:18 +02:00
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
from testutils import harbor_server, suppress_urllib3_warning
|
2020-08-15 18:09:06 +02:00
|
|
|
from testutils import TEARDOWN
|
2020-08-17 08:51:18 +02:00
|
|
|
from testutils import ADMIN_CLIENT
|
|
|
|
from library.user import User
|
2020-08-15 18:09:06 +02:00
|
|
|
from library.project import Project
|
2020-08-17 08:51:18 +02:00
|
|
|
from library.configurations import Configurations
|
2018-08-01 00:38:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestLdapAdminRole(unittest.TestCase):
|
2020-11-04 03:13:12 +01:00
|
|
|
@suppress_urllib3_warning
|
2018-08-01 00:38:23 +02:00
|
|
|
def setUp(self):
|
2020-08-17 08:51:18 +02:00
|
|
|
url = ADMIN_CLIENT["endpoint"]
|
|
|
|
self.conf= Configurations()
|
2020-09-07 05:33:27 +02:00
|
|
|
self.user = User()
|
2020-08-17 08:51:18 +02:00
|
|
|
self.project = Project()
|
|
|
|
self.USER_MIKE=dict(endpoint = url, username = "mike", password = "zhu88jie")
|
2020-11-04 03:13:12 +01:00
|
|
|
self.project_id = None
|
2018-08-01 00:38:23 +02:00
|
|
|
|
2020-08-15 18:09:06 +02:00
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
def testLdapAdminRole(self):
|
2020-08-17 08:51:18 +02:00
|
|
|
"""
|
|
|
|
Test case:
|
|
|
|
LDAP Admin Role
|
|
|
|
Test step and expected result:
|
|
|
|
1. Set LDAP Auth configurations;
|
|
|
|
2. Create a new public project(PA) by LDAP user mike;
|
|
|
|
3. Check project is created successfully;
|
2020-09-29 11:52:39 +02:00
|
|
|
4. Check mike's SysAdminFlag is false, but AdminRoleInAuth should be true
|
2020-08-17 08:51:18 +02:00
|
|
|
5. Delete project(PA);
|
|
|
|
"""
|
2018-08-01 00:38:23 +02:00
|
|
|
|
2020-08-07 08:56:18 +02:00
|
|
|
|
2020-08-17 08:51:18 +02:00
|
|
|
self.conf.set_configurations_of_ldap(ldap_group_admin_dn="cn=harbor_users,ou=groups,dc=example,dc=com", **ADMIN_CLIENT)
|
2019-12-11 10:17:18 +01:00
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
self.project_id, project_name = self.project.create_project(metadata = {"public": "false"}, **self.USER_MIKE)
|
|
|
|
print("self.project_id:", self.project_id)
|
2020-08-17 08:51:18 +02:00
|
|
|
self.project.check_project_name_exist(name=project_name, **self.USER_MIKE)
|
2019-12-11 10:17:18 +01:00
|
|
|
|
2020-09-29 11:52:39 +02:00
|
|
|
_user = self.user.get_user_current(**self.USER_MIKE)
|
|
|
|
print( _user)
|
2020-08-17 08:51:18 +02:00
|
|
|
self.assertFalse(_user.sysadmin_flag)
|
2020-09-29 11:52:39 +02:00
|
|
|
self.assertTrue(_user.admin_role_in_auth)
|
2018-08-01 00:38:23 +02:00
|
|
|
|
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
|
|
|
def tearDown(self):
|
|
|
|
print("self.project_id:", self.project_id)
|
|
|
|
self.project.delete_project(self.project_id, **self.USER_MIKE)
|
|
|
|
print("Case completed")
|
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
if __name__ == '__main__':
|
2020-08-17 08:51:18 +02:00
|
|
|
unittest.main()
|