| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2016.04.16 |
| 5 |
# |
| 6 |
# Author: Giovanni Cannata |
| 7 |
# |
| 8 |
# Copyright 2016 - 2020 Giovanni Cannata |
| 9 |
# |
| 10 |
# This file is part of ldap3. |
| 11 |
# |
| 12 |
# ldap3 is free software: you can redistribute it and/or modify |
| 13 |
# it under the terms of the GNU Lesser General Public License as published |
| 14 |
# by the Free Software Foundation, either version 3 of the License, or |
| 15 |
# (at your option) any later version. |
| 16 |
# |
| 17 |
# ldap3 is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
# GNU Lesser General Public License for more details. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU Lesser General Public License |
| 23 |
# along with ldap3 in the COPYING and COPYING.LESSER files. |
| 24 |
# If not, see <http://www.gnu.org/licenses/>. |
| 25 |
|
| 26 |
|
| 27 |
import unittest |
| 28 |
|
| 29 |
from test.config import add_user, add_group, get_connection, drop_connection, random_id, test_server_type, get_response_values |
| 30 |
|
| 31 |
testcase_id = '' |
| 32 |
|
| 33 |
|
| 34 |
class Test(unittest.TestCase): |
| 35 |
def setUp(self): |
| 36 |
global testcase_id |
| 37 |
testcase_id = random_id() |
| 38 |
self.connection = get_connection() |
| 39 |
self.delete_at_teardown = [] |
| 40 |
|
| 41 |
def tearDown(self): |
| 42 |
drop_connection(self.connection, self.delete_at_teardown) |
| 43 |
self.assertFalse(self.connection.bound) |
| 44 |
|
| 45 |
def test_add_member_to_group(self): |
| 46 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 47 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-1')) |
| 48 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-1')) |
| 49 |
self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0], |
| 50 |
self.delete_at_teardown[1][0], |
| 51 |
fix=False, |
| 52 |
transaction=False) |
| 53 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 54 |
|
| 55 |
if response: |
| 56 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 57 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 58 |
else: |
| 59 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 60 |
|
| 61 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 62 |
|
| 63 |
if response: |
| 64 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 65 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 66 |
else: |
| 67 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 68 |
|
| 69 |
def test_add_members_to_groups(self): |
| 70 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 71 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-2')) |
| 72 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-3')) |
| 73 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-4')) |
| 74 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-2', self.delete_at_teardown)) |
| 75 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-3')) |
| 76 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-4')) |
| 77 |
self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0], |
| 78 |
self.delete_at_teardown[1][0], |
| 79 |
self.delete_at_teardown[2][0]], |
| 80 |
[self.delete_at_teardown[3][0], |
| 81 |
self.delete_at_teardown[4][0], |
| 82 |
self.delete_at_teardown[5][0]], |
| 83 |
fix=True, |
| 84 |
transaction=False |
| 85 |
) |
| 86 |
for i in range(0, 2): |
| 87 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 88 |
|
| 89 |
if response: |
| 90 |
for j in range(3, 5): |
| 91 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 92 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 93 |
else: |
| 94 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 95 |
|
| 96 |
for j in range(3, 5): |
| 97 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 98 |
|
| 99 |
if response: |
| 100 |
for i in range(0, 2): |
| 101 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 102 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 103 |
else: |
| 104 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |
| 105 |
|
| 106 |
def test_add_member_to_group_transactional(self): |
| 107 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 108 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-5')) |
| 109 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-5', self.delete_at_teardown)) |
| 110 |
self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0], |
| 111 |
self.delete_at_teardown[1][0], |
| 112 |
fix=True, |
| 113 |
transaction=True) |
| 114 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 115 |
|
| 116 |
if response: |
| 117 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 118 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 119 |
else: |
| 120 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 121 |
|
| 122 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 123 |
|
| 124 |
if response: |
| 125 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 126 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 127 |
else: |
| 128 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 129 |
|
| 130 |
def test_add_members_to_groups_transactional(self): |
| 131 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 132 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-6')) |
| 133 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-7')) |
| 134 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-8')) |
| 135 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-6', self.delete_at_teardown)) # this group has members but other attributes are not set |
| 136 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-7')) |
| 137 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-8')) |
| 138 |
self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0], |
| 139 |
self.delete_at_teardown[1][0], |
| 140 |
self.delete_at_teardown[2][0]], |
| 141 |
[self.delete_at_teardown[3][0], |
| 142 |
self.delete_at_teardown[4][0], |
| 143 |
self.delete_at_teardown[5][0]], |
| 144 |
fix=True, |
| 145 |
transaction=True |
| 146 |
) |
| 147 |
for i in range(0, 2): |
| 148 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 149 |
|
| 150 |
if response: |
| 151 |
for j in range(3, 5): |
| 152 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 153 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 154 |
else: |
| 155 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 156 |
|
| 157 |
for j in range(3, 5): |
| 158 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 159 |
|
| 160 |
if response: |
| 161 |
for i in range(0, 2): |
| 162 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 163 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 164 |
else: |
| 165 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |