| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2016.04.17 |
| 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 test_base, 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_remove_member_from_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.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-1b', [self.delete_at_teardown[0]])) |
| 50 |
self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0], |
| 51 |
[self.delete_at_teardown[1][0], |
| 52 |
self.delete_at_teardown[2][0]], |
| 53 |
fix=True, |
| 54 |
transaction=False) |
| 55 |
# verifies user in group-1 |
| 56 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 57 |
|
| 58 |
if response: |
| 59 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 60 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 61 |
else: |
| 62 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 63 |
|
| 64 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 65 |
|
| 66 |
if response: |
| 67 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 68 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 69 |
else: |
| 70 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 71 |
|
| 72 |
# verifies user in group-1b |
| 73 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 74 |
|
| 75 |
if response: |
| 76 |
self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 77 |
self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 78 |
else: |
| 79 |
self.assertFalse(True, self.delete_at_teardown[2][0] + ' not found') |
| 80 |
|
| 81 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[2][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 82 |
|
| 83 |
if response: |
| 84 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 85 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 86 |
else: |
| 87 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 88 |
|
| 89 |
self.connection.extend.novell.remove_members_from_groups(self.delete_at_teardown[0][0], |
| 90 |
self.delete_at_teardown[1][0], |
| 91 |
fix=False, |
| 92 |
transaction=False) |
| 93 |
|
| 94 |
# verifies users not in group-1 |
| 95 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 96 |
|
| 97 |
if response: |
| 98 |
self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 99 |
self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 100 |
else: |
| 101 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 102 |
|
| 103 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 104 |
|
| 105 |
if response: |
| 106 |
self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 107 |
self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 108 |
else: |
| 109 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 110 |
|
| 111 |
# verifies user still in group-1b |
| 112 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 113 |
|
| 114 |
if response: |
| 115 |
self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 116 |
self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 117 |
else: |
| 118 |
self.assertFalse(True, self.delete_at_teardown[2][0] + ' not found') |
| 119 |
|
| 120 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[2][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 121 |
|
| 122 |
if response: |
| 123 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 124 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 125 |
else: |
| 126 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 127 |
|
| 128 |
def test_remove_members_from_groups(self): |
| 129 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 130 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-2')) |
| 131 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-3')) |
| 132 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-4')) |
| 133 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-2', self.delete_at_teardown)) |
| 134 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-3')) |
| 135 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-4')) |
| 136 |
self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0], |
| 137 |
self.delete_at_teardown[1][0], |
| 138 |
self.delete_at_teardown[2][0]], |
| 139 |
[self.delete_at_teardown[3][0], |
| 140 |
self.delete_at_teardown[4][0], |
| 141 |
self.delete_at_teardown[5][0]], |
| 142 |
fix=True, |
| 143 |
transaction=False |
| 144 |
) |
| 145 |
for i in range(0, 2): |
| 146 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 147 |
|
| 148 |
if response: |
| 149 |
for j in range(3, 5): |
| 150 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 151 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 152 |
else: |
| 153 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 154 |
|
| 155 |
for j in range(3, 5): |
| 156 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 157 |
|
| 158 |
if response: |
| 159 |
for i in range(0, 2): |
| 160 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 161 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 162 |
else: |
| 163 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |
| 164 |
|
| 165 |
self.connection.extend.novell.remove_members_from_groups([self.delete_at_teardown[0][0], |
| 166 |
self.delete_at_teardown[1][0], |
| 167 |
self.delete_at_teardown[2][0]], |
| 168 |
[self.delete_at_teardown[3][0], |
| 169 |
self.delete_at_teardown[4][0], |
| 170 |
self.delete_at_teardown[5][0]], |
| 171 |
fix=True, |
| 172 |
transaction=False |
| 173 |
) |
| 174 |
|
| 175 |
for i in range(0, 2): |
| 176 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 177 |
|
| 178 |
if response: |
| 179 |
for j in range(3, 5): |
| 180 |
self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 181 |
self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 182 |
else: |
| 183 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 184 |
|
| 185 |
for j in range(3, 5): |
| 186 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 187 |
|
| 188 |
if response: |
| 189 |
for i in range(0, 2): |
| 190 |
self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 191 |
self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 192 |
else: |
| 193 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |
| 194 |
|
| 195 |
def test_remove_member_from_group_transactional(self): |
| 196 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 197 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-5')) |
| 198 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-5', self.delete_at_teardown)) |
| 199 |
self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0], |
| 200 |
self.delete_at_teardown[1][0], |
| 201 |
fix=True, |
| 202 |
transaction=True) |
| 203 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 204 |
|
| 205 |
if response: |
| 206 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 207 |
self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 208 |
else: |
| 209 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 210 |
|
| 211 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 212 |
|
| 213 |
if response: |
| 214 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 215 |
self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 216 |
else: |
| 217 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 218 |
|
| 219 |
self.connection.extend.novell.remove_members_from_groups(self.delete_at_teardown[0][0], |
| 220 |
self.delete_at_teardown[1][0], |
| 221 |
fix=False, |
| 222 |
transaction=False) |
| 223 |
|
| 224 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 225 |
|
| 226 |
if response: |
| 227 |
self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 228 |
self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 229 |
else: |
| 230 |
self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found') |
| 231 |
|
| 232 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 233 |
|
| 234 |
if response: |
| 235 |
self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 236 |
self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 237 |
else: |
| 238 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 239 |
|
| 240 |
def test_remove_members_from_groups_transactional(self): |
| 241 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 242 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-6')) |
| 243 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-7')) |
| 244 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-8')) |
| 245 |
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 |
| 246 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-7')) |
| 247 |
self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-8')) |
| 248 |
self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0], |
| 249 |
self.delete_at_teardown[1][0], |
| 250 |
self.delete_at_teardown[2][0]], |
| 251 |
[self.delete_at_teardown[3][0], |
| 252 |
self.delete_at_teardown[4][0], |
| 253 |
self.delete_at_teardown[5][0]], |
| 254 |
fix=True, |
| 255 |
transaction=True |
| 256 |
) |
| 257 |
for i in range(0, 2): |
| 258 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 259 |
|
| 260 |
if response: |
| 261 |
for j in range(3, 5): |
| 262 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 263 |
self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 264 |
else: |
| 265 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 266 |
|
| 267 |
for j in range(3, 5): |
| 268 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 269 |
|
| 270 |
if response: |
| 271 |
for i in range(0, 2): |
| 272 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 273 |
self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 274 |
else: |
| 275 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |
| 276 |
|
| 277 |
self.connection.extend.novell.remove_members_from_groups([self.delete_at_teardown[0][0], |
| 278 |
self.delete_at_teardown[1][0], |
| 279 |
self.delete_at_teardown[2][0]], |
| 280 |
[self.delete_at_teardown[3][0], |
| 281 |
self.delete_at_teardown[4][0], |
| 282 |
self.delete_at_teardown[5][0]], |
| 283 |
fix=True, |
| 284 |
transaction=False |
| 285 |
) |
| 286 |
|
| 287 |
for i in range(0, 2): |
| 288 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection) |
| 289 |
|
| 290 |
if response: |
| 291 |
for j in range(3, 5): |
| 292 |
self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else [])) |
| 293 |
self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else [])) |
| 294 |
else: |
| 295 |
self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found') |
| 296 |
|
| 297 |
for j in range(3, 5): |
| 298 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection) |
| 299 |
|
| 300 |
if response: |
| 301 |
for i in range(0, 2): |
| 302 |
self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else [])) |
| 303 |
self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else [])) |
| 304 |
else: |
| 305 |
self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found') |