test_ldap_admin_role.py 2.01 KB
Newer Older
1 2 3 4 5
# coding: utf-8

"""
    Harbor API

6
    These APIs provide services for manipulating Harbor project.
7 8

    OpenAPI spec version: 1.4.0
9

10 11 12 13 14 15 16 17 18 19 20 21 22
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import os
import sys
sys.path.append(os.environ["SWAGGER_CLIENT_PATH"])

import unittest
import testutils
import swagger_client
23
from testutils import TEARDOWN
24
from library.base import _random_name
25
from library.project import Project
26
from swagger_client.models.configurations import Configurations
27 28 29 30 31 32 33 34 35
from pprint import pprint


#Testcase
# Define a LDAP group with harbor admin
class TestLdapAdminRole(unittest.TestCase):
    """AccessLog unit test stubs"""
    product_api = testutils.GetProductApi("admin", "Harbor12345")
    project_id = 0
36

37
    def setUp(self):
38 39
        self.project= Project()
        self.mike_product_api = Project("mike", "zhu88jie")
40 41

    def tearDown(self):
42 43 44 45
        print("Case completed")

    @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
    def test_ClearData(self):
46
        if self.project_id > 0 :
47
            self.mike_product_api.delete_project(self.project_id)
48 49 50

    def testLdapAdminRole(self):
        """Test LdapAdminRole"""
51
        _project_name = _random_name("test-ldap-admin-role")
52 53 54
        result = self.product_api.configurations_put(configurations=Configurations(ldap_group_admin_dn="cn=harbor_users,ou=groups,dc=example,dc=com"))

        # Create a private project
55
        result = self.project.create_project(_project_name)
56 57

        # query project with ldap user mike
58
        projects = self.mike_product_api.get_projects(dict(name=_project_name))
59 60 61

        print("=================", projects)
        self.assertTrue(len(projects) == 1)
62
        self.project_id = projects[0].project_id
63 64 65 66 67 68

        # check the mike is not admin in Database
        user_list = self.product_api.users_get(username="mike")
        pprint(user_list[0])
        self.assertFalse(user_list[0].sysadmin_flag)

69 70 71 72 73
        pass


if __name__ == '__main__':
    unittest.main()