test_ldap_admin_role.py 1.61 KB
Newer Older
1 2
from __future__ import absolute_import
import unittest
danfengliu's avatar
danfengliu committed
3 4

from testutils import harbor_server
5
from testutils import TEARDOWN
danfengliu's avatar
danfengliu committed
6 7
from testutils import ADMIN_CLIENT
from library.user import User
8
from library.project import Project
danfengliu's avatar
danfengliu committed
9
from library.configurations import Configurations
10 11 12


class TestLdapAdminRole(unittest.TestCase):
danfengliu's avatar
danfengliu committed
13
    @classmethod
14
    def setUp(self):
danfengliu's avatar
danfengliu committed
15 16
        url = ADMIN_CLIENT["endpoint"]
        self.conf= Configurations()
17
        self.user = User()
danfengliu's avatar
danfengliu committed
18 19
        self.project = Project()
        self.USER_MIKE=dict(endpoint = url, username = "mike", password = "zhu88jie")
20

danfengliu's avatar
danfengliu committed
21
    @classmethod
22
    def tearDown(self):
danfengliu's avatar
danfengliu committed
23
        self.project.delete_project(TestLdapAdminRole.project_id, **self.USER_MIKE)
24 25
        print("Case completed")

26
    def testLdapAdminRole(self):
danfengliu's avatar
danfengliu committed
27 28 29 30 31 32 33 34 35 36
        """
        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;
            4. Check mike is not admin;
            5. Delete project(PA);
        """
37

38

danfengliu's avatar
danfengliu committed
39
        self.conf.set_configurations_of_ldap(ldap_group_admin_dn="cn=harbor_users,ou=groups,dc=example,dc=com", **ADMIN_CLIENT)
40

danfengliu's avatar
danfengliu committed
41 42
        TestLdapAdminRole.project_id, project_name = self.project.create_project(metadata = {"public": "false"}, **self.USER_MIKE)
        self.project.check_project_name_exist(name=project_name, **self.USER_MIKE)
43

44
        _user = self.user.get_user_by_name(self.USER_MIKE["username"], **ADMIN_CLIENT)
danfengliu's avatar
danfengliu committed
45
        self.assertFalse(_user.sysadmin_flag)
46 47 48


if __name__ == '__main__':
danfengliu's avatar
danfengliu committed
49
    unittest.main()