| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2016.08.20 |
| 5 |
# |
| 6 |
# Author: Giovanni Cannata |
| 7 |
# |
| 8 |
# Copyright 2015 - 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 |
import unittest |
| 27 |
from time import sleep |
| 28 |
|
| 29 |
from ldap3 import REUSABLE |
| 30 |
from ldap3.core.exceptions import LDAPCursorError, LDAPOperationResult, LDAPConstraintViolationResult, LDAPAttributeOrValueExistsResult |
| 31 |
from ldap3.abstract import STATUS_WRITABLE, STATUS_COMMITTED, STATUS_DELETED, STATUS_INIT, STATUS_MANDATORY_MISSING, STATUS_VIRTUAL, STATUS_PENDING_CHANGES, STATUS_READ, STATUS_READY_FOR_DELETION |
| 32 |
from ldap3.core.results import RESULT_CONSTRAINT_VIOLATION, RESULT_ATTRIBUTE_OR_VALUE_EXISTS |
| 33 |
from test.config import test_base, test_name_attr, random_id, get_connection, add_user, drop_connection, test_server_type, test_int_attr, test_strategy,\ |
| 34 |
test_multivalued_attribute, test_singlevalued_attribute, get_response_values |
| 35 |
|
| 36 |
|
| 37 |
testcase_id = '' |
| 38 |
|
| 39 |
|
| 40 |
class Test(unittest.TestCase): |
| 41 |
def setUp(self): |
| 42 |
global testcase_id |
| 43 |
testcase_id = random_id() |
| 44 |
self.connection = get_connection() |
| 45 |
self.delete_at_teardown = [] |
| 46 |
if test_server_type == 'EDIR': |
| 47 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-1', attributes={test_multivalued_attribute: 'givenname-1', test_int_attr: 0})) |
| 48 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-2', attributes={test_multivalued_attribute: ['givenname-2a', 'givenname-2b', 'givenname-2c'], test_int_attr: 0, test_singlevalued_attribute: 'init'})) |
| 49 |
elif test_server_type == 'AD': |
| 50 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-1', attributes={test_multivalued_attribute: 'givenname-1'})) |
| 51 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-2', attributes={test_multivalued_attribute: ['givenname-2a', 'givenname-2b', 'givenname-2c'], test_singlevalued_attribute: 'init'})) |
| 52 |
else: |
| 53 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-1', attributes={test_multivalued_attribute: 'givenname-1'})) |
| 54 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mod-2', attributes={test_multivalued_attribute: ['givenname-2a', 'givenname-2b', 'givenname-2c'], test_singlevalued_attribute: 'init'})) |
| 55 |
|
| 56 |
def tearDown(self): |
| 57 |
drop_connection(self.connection, self.delete_at_teardown) |
| 58 |
self.assertFalse(self.connection.bound) |
| 59 |
|
| 60 |
def get_entry(self, entry_name): |
| 61 |
status, result, response, request = get_response_values(self.connection.search(search_base=test_base, search_filter='(' + test_name_attr + '=' + testcase_id + entry_name + ')', attributes=[test_name_attr, 'givenName', test_multivalued_attribute, test_singlevalued_attribute]), self.connection) |
| 62 |
entries = self.connection._get_entries(response, request) |
| 63 |
self.assertEqual(result['description'], 'success') |
| 64 |
self.assertEqual(len(entries), 1) |
| 65 |
return entries[0] |
| 66 |
|
| 67 |
def compare_entries(self, entry1, entry2): |
| 68 |
for attr in entry1: |
| 69 |
self.assertFalse(entry1[attr.key] is entry2[attr.key]) |
| 70 |
self.assertEqual(entry1[attr.key], entry2[attr.key]) |
| 71 |
|
| 72 |
for attr in entry2: |
| 73 |
self.assertFalse(entry2[attr.key] is entry1[attr.key]) |
| 74 |
self.assertEqual(entry2[attr.key], entry1[attr.key]) |
| 75 |
|
| 76 |
for attr in entry1._state.attributes.keys(): |
| 77 |
self.assertFalse(entry1._state.attributes[attr] is entry2._state.attributes[attr]) |
| 78 |
self.assertEqual(entry1._state.attributes[attr], entry2._state.attributes[attr]) |
| 79 |
|
| 80 |
for attr in entry2._state.attributes.keys(): |
| 81 |
self.assertFalse(entry2._state.attributes[attr] is entry1._state.attributes[attr]) |
| 82 |
self.assertEqual(entry2._state.attributes[attr], entry1._state.attributes[attr]) |
| 83 |
|
| 84 |
for attr in entry1._state.raw_attributes.keys(): |
| 85 |
self.assertFalse(entry1._state.raw_attributes[attr] is entry2._state.raw_attributes[attr]) |
| 86 |
self.assertEqual(entry1._state.raw_attributes[attr], entry2._state.raw_attributes[attr]) |
| 87 |
|
| 88 |
for attr in entry2._state.raw_attributes.keys(): |
| 89 |
self.assertFalse(entry2._state.raw_attributes[attr] is entry1._state.raw_attributes[attr]) |
| 90 |
self.assertEqual(entry2._state.raw_attributes[attr], entry1._state.raw_attributes[attr]) |
| 91 |
|
| 92 |
self.assertEqual(entry1._state.dn, entry2._state.dn) |
| 93 |
self.assertEqual(entry1._state.response, entry2._state.response) |
| 94 |
self.assertEqual(entry1._state.read_time, entry2._state.read_time) |
| 95 |
|
| 96 |
self.assertFalse(entry1 is entry2) |
| 97 |
self.assertFalse(entry1._state is entry2._state) |
| 98 |
self.assertFalse(entry1._state.attributes is entry2._state.attributes) |
| 99 |
self.assertFalse(entry1._state.raw_attributes is entry2._state.raw_attributes) |
| 100 |
# if entry1._state.response is not None: |
| 101 |
# self.assertFalse(entry1._state.response is entry2._state.response) |
| 102 |
# if entry1._state.read_time is not None: |
| 103 |
# self.assertFalse(entry1._state.read_time is entry2._state.read_time) |
| 104 |
|
| 105 |
def test_search_and_delete_entry(self): |
| 106 |
add_user(self.connection, testcase_id, 'del1', attributes={'givenName': 'givenname-delete'}) |
| 107 |
read_only_entry = self.get_entry('del1') |
| 108 |
self.assertEqual(read_only_entry.entry_status, STATUS_READ) |
| 109 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 110 |
self.assertEqual(writable_entry.entry_status, STATUS_WRITABLE) |
| 111 |
writable_entry.entry_delete() |
| 112 |
self.assertEqual(writable_entry.entry_status, STATUS_READY_FOR_DELETION) |
| 113 |
result = writable_entry.entry_commit_changes() |
| 114 |
self.assertEqual(writable_entry.entry_status, STATUS_DELETED) |
| 115 |
self.assertTrue(result) |
| 116 |
counter = 20 |
| 117 |
while counter > 0: # waits for at maximum 20 times - delete operation can take some time to complete |
| 118 |
status, result, response, request = get_response_values(self.connection.search(search_base=test_base, search_filter='(' + test_name_attr + '=' + testcase_id + 'del1)', attributes=[test_name_attr, 'givenName']), self.connection) |
| 119 |
entries = self.connection._get_entries(response, request) |
| 120 |
if len(entries) == 0: |
| 121 |
break |
| 122 |
sleep(3) |
| 123 |
counter -= 1 |
| 124 |
|
| 125 |
self.assertEqual(result['description'], 'success') |
| 126 |
self.assertEqual(len(entries), 0) |
| 127 |
self.compare_entries(read_only_entry, writable_entry) |
| 128 |
|
| 129 |
def test_search_and_add_value_to_existing_single_value(self): |
| 130 |
read_only_entry = self.get_entry('mod-2') |
| 131 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 132 |
writable_entry[test_singlevalued_attribute].add('single') |
| 133 |
writable_entry.entry_commit_changes() |
| 134 |
cursor = writable_entry.entry_cursor |
| 135 |
if not cursor.failed: |
| 136 |
self.fail('error assigning to existing single value') |
| 137 |
self.assertEqual(len(cursor.errors), 1) |
| 138 |
self.assertTrue(cursor.errors[0].result['result'] in [RESULT_CONSTRAINT_VIOLATION, RESULT_ATTRIBUTE_OR_VALUE_EXISTS]) |
| 139 |
|
| 140 |
def test_search_and_implicit_add_value_to_existing_single_value(self): |
| 141 |
read_only_entry = self.get_entry('mod-2') |
| 142 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 143 |
writable_entry[test_singlevalued_attribute] += 'single' |
| 144 |
writable_entry.entry_commit_changes() |
| 145 |
cursor = writable_entry.entry_cursor |
| 146 |
if not cursor.failed: |
| 147 |
self.fail('error assigning to existing single value') |
| 148 |
self.assertEqual(len(cursor.errors), 1) |
| 149 |
self.assertTrue(cursor.errors[0].result['result'] in [RESULT_CONSTRAINT_VIOLATION, RESULT_ATTRIBUTE_OR_VALUE_EXISTS]) |
| 150 |
|
| 151 |
def test_search_and_add_value_to_existing_single_value_with_exception(self): |
| 152 |
if test_strategy != REUSABLE: # in REUSABLE strategy the connection can't be changed |
| 153 |
old_raise_exception = self.connection.raise_exceptions |
| 154 |
self.connection.raise_exceptions = True |
| 155 |
read_only_entry = self.get_entry('mod-2') |
| 156 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 157 |
writable_entry[test_singlevalued_attribute].add('single') |
| 158 |
try: |
| 159 |
writable_entry.entry_commit_changes() |
| 160 |
except (LDAPConstraintViolationResult, LDAPAttributeOrValueExistsResult): |
| 161 |
return |
| 162 |
finally: |
| 163 |
self.connection.raise_exceptions = old_raise_exception |
| 164 |
self.fail('error assigning to existing single value') |
| 165 |
|
| 166 |
def test_search_and_implicit_add_value_to_existing_single_value_with_exception(self): |
| 167 |
if test_strategy != REUSABLE: # in REUSABLE strategy the connection can't be changed |
| 168 |
old_raise_exception = self.connection.raise_exceptions |
| 169 |
self.connection.raise_exceptions = True |
| 170 |
read_only_entry = self.get_entry('mod-2') |
| 171 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 172 |
writable_entry[test_singlevalued_attribute] += 'single' |
| 173 |
try: |
| 174 |
writable_entry.entry_commit_changes() |
| 175 |
except (LDAPConstraintViolationResult, LDAPAttributeOrValueExistsResult): |
| 176 |
return |
| 177 |
finally: |
| 178 |
self.connection.raise_exceptions = old_raise_exception |
| 179 |
self.fail('error assigning to existing single value') |
| 180 |
|
| 181 |
def test_search_and_add_value_to_non_existing_single_value(self): |
| 182 |
read_only_entry = self.get_entry('mod-1') |
| 183 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 184 |
writable_entry[test_singlevalued_attribute].add('single') |
| 185 |
result = writable_entry.entry_commit_changes() |
| 186 |
self.assertTrue(result) |
| 187 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'single') |
| 188 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 189 |
self.compare_entries(read_only_entry, writable_entry) |
| 190 |
|
| 191 |
def test_search_and_implicit_add_value_to_non_existing_single_value(self): |
| 192 |
read_only_entry = self.get_entry('mod-1') |
| 193 |
writable_entry = read_only_entry.entry_writable('inetorgperson', attributes=[test_singlevalued_attribute]) |
| 194 |
writable_entry[test_singlevalued_attribute] += 'single' |
| 195 |
result = writable_entry.entry_commit_changes() |
| 196 |
self.assertTrue(result) |
| 197 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'single') |
| 198 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 199 |
self.compare_entries(read_only_entry, writable_entry) |
| 200 |
|
| 201 |
def test_search_and_add_value_to_existing_multi_value(self): |
| 202 |
read_only_entry = self.get_entry('mod-1') |
| 203 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 204 |
writable_entry[test_multivalued_attribute].add('added-givenname-1') |
| 205 |
result = writable_entry.entry_commit_changes() |
| 206 |
self.assertTrue(result) |
| 207 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 208 |
self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 209 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 210 |
self.compare_entries(read_only_entry, writable_entry) |
| 211 |
|
| 212 |
def test_search_and_implicit_add_value_to_existing_multi_value(self): |
| 213 |
read_only_entry = self.get_entry('mod-1') |
| 214 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 215 |
writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-1' |
| 216 |
result = writable_entry.entry_commit_changes() |
| 217 |
self.assertTrue(result) |
| 218 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 219 |
self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 220 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 221 |
self.compare_entries(read_only_entry, writable_entry) |
| 222 |
|
| 223 |
def test_search_and_add_values_to_existing_multi_value(self): |
| 224 |
read_only_entry = self.get_entry('mod-1') |
| 225 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 226 |
writable_entry[test_multivalued_attribute].add('added-givenname-1') |
| 227 |
writable_entry[test_multivalued_attribute].add('added-givenname-2') |
| 228 |
result = writable_entry.entry_commit_changes() |
| 229 |
self.assertTrue(result) |
| 230 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 231 |
self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 232 |
self.assertTrue('added-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 233 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3) |
| 234 |
self.compare_entries(read_only_entry, writable_entry) |
| 235 |
|
| 236 |
def test_search_and_implicit_add_values_to_existing_multi_value(self): |
| 237 |
read_only_entry = self.get_entry('mod-1') |
| 238 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 239 |
writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-1' |
| 240 |
writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-2' |
| 241 |
result = writable_entry.entry_commit_changes() |
| 242 |
self.assertTrue(result) |
| 243 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 244 |
self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 245 |
self.assertTrue('implicit-added-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 246 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3) |
| 247 |
self.compare_entries(read_only_entry, writable_entry) |
| 248 |
|
| 249 |
def test_search_and_add_values_from_sequence_to_existing_multi_value(self): |
| 250 |
read_only_entry = self.get_entry('mod-1') |
| 251 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 252 |
writable_entry[test_multivalued_attribute].add(['added-givenname-1', 'added-givenname-2']) |
| 253 |
result = writable_entry.entry_commit_changes() |
| 254 |
self.assertTrue(result) |
| 255 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 256 |
self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 257 |
self.assertTrue('added-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 258 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3) |
| 259 |
self.compare_entries(read_only_entry, writable_entry) |
| 260 |
|
| 261 |
def test_search_and_implicit_add_values_from_sequence_to_existing_multi_value(self): |
| 262 |
read_only_entry = self.get_entry('mod-1') |
| 263 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 264 |
writable_entry[test_multivalued_attribute] += ['implicit-added-givenname-1', 'implicit-added-givenname-2'] |
| 265 |
result = writable_entry.entry_commit_changes() |
| 266 |
self.assertTrue(result) |
| 267 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 268 |
self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 269 |
self.assertTrue('implicit-added-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 270 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3) |
| 271 |
self.compare_entries(read_only_entry, writable_entry) |
| 272 |
|
| 273 |
def test_search_and_add_value_to_non_existing_multi_value(self): |
| 274 |
read_only_entry = self.get_entry('mod-1') |
| 275 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 276 |
writable_entry.postalAddress.add('postalAddress-1') |
| 277 |
result = writable_entry.entry_commit_changes() |
| 278 |
self.assertTrue(result) |
| 279 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 280 |
self.assertEqual(len(writable_entry.postalAddress), 1) |
| 281 |
self.compare_entries(read_only_entry, writable_entry) |
| 282 |
|
| 283 |
def test_search_and_implicit_add_value_to_non_existing_multi_value(self): |
| 284 |
read_only_entry = self.get_entry('mod-1') |
| 285 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 286 |
writable_entry.postalAddress += 'postalAddress-1' |
| 287 |
result = writable_entry.entry_commit_changes() |
| 288 |
self.assertTrue(result) |
| 289 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 290 |
self.assertEqual(len(writable_entry.postalAddress), 1) |
| 291 |
self.compare_entries(read_only_entry, writable_entry) |
| 292 |
|
| 293 |
def test_search_and_add_values_to_non_existing_multi_value(self): |
| 294 |
read_only_entry = self.get_entry('mod-1') |
| 295 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 296 |
writable_entry.postalAddress.add('postalAddress-1') |
| 297 |
writable_entry.postalAddress.add('postalAddress-2') |
| 298 |
result = writable_entry.entry_commit_changes() |
| 299 |
self.assertTrue(result) |
| 300 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 301 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 302 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 303 |
self.compare_entries(read_only_entry, writable_entry) |
| 304 |
|
| 305 |
def test_search_and_implicit_add_values_to_non_existing_multi_value(self): |
| 306 |
read_only_entry = self.get_entry('mod-1') |
| 307 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 308 |
writable_entry.postalAddress += 'postalAddress-1' |
| 309 |
writable_entry.postalAddress += 'postalAddress-2' |
| 310 |
result = writable_entry.entry_commit_changes() |
| 311 |
self.assertTrue(result) |
| 312 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 313 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 314 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 315 |
self.compare_entries(read_only_entry, writable_entry) |
| 316 |
|
| 317 |
def test_search_and_add_values_from_sequence_to_non_existing_multi_value(self): |
| 318 |
read_only_entry = self.get_entry('mod-1') |
| 319 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 320 |
writable_entry.postalAddress.add(['postalAddress-1', 'postalAddress-2']) |
| 321 |
result = writable_entry.entry_commit_changes() |
| 322 |
self.assertTrue(result) |
| 323 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 324 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 325 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 326 |
self.compare_entries(read_only_entry, writable_entry) |
| 327 |
|
| 328 |
def test_search_and_implicit_add_values_from_sequence_to_non_existing_multi_value(self): |
| 329 |
read_only_entry = self.get_entry('mod-1') |
| 330 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 331 |
writable_entry.postalAddress += ['postalAddress-1', 'postalAddress-2'] |
| 332 |
result = writable_entry.entry_commit_changes() |
| 333 |
self.assertTrue(result) |
| 334 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 335 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 336 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 337 |
self.compare_entries(read_only_entry, writable_entry) |
| 338 |
|
| 339 |
def test_search_and_set_value_to_existing_single_value(self): |
| 340 |
read_only_entry = self.get_entry('mod-2') |
| 341 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 342 |
writable_entry[test_singlevalued_attribute].set('single') |
| 343 |
result = writable_entry.entry_commit_changes() |
| 344 |
self.assertTrue(result) |
| 345 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'single') |
| 346 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 347 |
self.compare_entries(read_only_entry, writable_entry) |
| 348 |
|
| 349 |
def test_search_and_implicit_set_value_to_existing_single_value(self): |
| 350 |
read_only_entry = self.get_entry('mod-2') |
| 351 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 352 |
writable_entry[test_singlevalued_attribute] = 'single' |
| 353 |
result = writable_entry.entry_commit_changes() |
| 354 |
self.assertTrue(result) |
| 355 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'single') |
| 356 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 357 |
self.compare_entries(read_only_entry, writable_entry) |
| 358 |
|
| 359 |
def test_search_and_set_value_to_non_existing_single_value(self): |
| 360 |
read_only_entry = self.get_entry('mod-1') |
| 361 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 362 |
writable_entry[test_singlevalued_attribute].set('init') |
| 363 |
result = writable_entry.entry_commit_changes() |
| 364 |
self.assertTrue(result) |
| 365 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'init') |
| 366 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 367 |
self.compare_entries(read_only_entry, writable_entry) |
| 368 |
|
| 369 |
def test_search_and_implicit_set_value_to_non_existing_single_value(self): |
| 370 |
read_only_entry = self.get_entry('mod-1') |
| 371 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 372 |
writable_entry[test_singlevalued_attribute] = 'init' |
| 373 |
result = writable_entry.entry_commit_changes() |
| 374 |
self.assertTrue(result) |
| 375 |
self.assertEqual(writable_entry[test_singlevalued_attribute], 'init') |
| 376 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1) |
| 377 |
self.compare_entries(read_only_entry, writable_entry) |
| 378 |
|
| 379 |
def test_search_and_set_value_to_existing_multi_value(self): |
| 380 |
read_only_entry = self.get_entry('mod-1') |
| 381 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 382 |
writable_entry[test_multivalued_attribute].set('set-givenname-1') |
| 383 |
result = writable_entry.entry_commit_changes() |
| 384 |
self.assertTrue(result) |
| 385 |
self.assertTrue('set-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 386 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1) |
| 387 |
self.compare_entries(read_only_entry, writable_entry) |
| 388 |
|
| 389 |
def test_search_and_implicit_set_value_to_existing_multi_value(self): |
| 390 |
read_only_entry = self.get_entry('mod-1') |
| 391 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 392 |
writable_entry[test_multivalued_attribute] = 'implicit-set-givenname-1' |
| 393 |
result = writable_entry.entry_commit_changes() |
| 394 |
self.assertTrue(result) |
| 395 |
self.assertTrue('implicit-set-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 396 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1) |
| 397 |
self.compare_entries(read_only_entry, writable_entry) |
| 398 |
|
| 399 |
def test_search_and_set_values_from_sequence_to_existing_multi_value(self): |
| 400 |
read_only_entry = self.get_entry('mod-1') |
| 401 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 402 |
writable_entry[test_multivalued_attribute].set(['set-givenname-1', 'set-givenname-2']) |
| 403 |
result = writable_entry.entry_commit_changes() |
| 404 |
self.assertTrue(result) |
| 405 |
self.assertTrue('set-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 406 |
self.assertTrue('set-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 407 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 408 |
self.compare_entries(read_only_entry, writable_entry) |
| 409 |
|
| 410 |
def test_search_and_implicit_set_values_from_sequence_to_existing_multi_value(self): |
| 411 |
read_only_entry = self.get_entry('mod-1') |
| 412 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 413 |
writable_entry[test_multivalued_attribute] = ['implicit-set-givenname-1', 'implicit-set-givenname-2'] |
| 414 |
result = writable_entry.entry_commit_changes() |
| 415 |
self.assertTrue(result) |
| 416 |
self.assertTrue('implicit-set-givenname-1' in writable_entry[test_multivalued_attribute]) |
| 417 |
self.assertTrue('implicit-set-givenname-2' in writable_entry[test_multivalued_attribute]) |
| 418 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 419 |
self.compare_entries(read_only_entry, writable_entry) |
| 420 |
|
| 421 |
def test_search_and_set_value_to_non_existing_multi_value(self): |
| 422 |
read_only_entry = self.get_entry('mod-1') |
| 423 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 424 |
writable_entry.postalAddress.set('postalAddress-1') |
| 425 |
result = writable_entry.entry_commit_changes() |
| 426 |
self.assertTrue(result) |
| 427 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 428 |
self.assertEqual(len(writable_entry.postalAddress), 1) |
| 429 |
self.compare_entries(read_only_entry, writable_entry) |
| 430 |
|
| 431 |
def test_search_and_implicit_set_value_to_non_existing_multi_value(self): |
| 432 |
read_only_entry = self.get_entry('mod-1') |
| 433 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 434 |
writable_entry.postalAddress = 'postalAddress-1' |
| 435 |
result = writable_entry.entry_commit_changes() |
| 436 |
self.assertTrue(result) |
| 437 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 438 |
self.assertEqual(len(writable_entry.postalAddress), 1) |
| 439 |
self.compare_entries(read_only_entry, writable_entry) |
| 440 |
|
| 441 |
def test_search_and_set_values_from_sequence_to_non_existing_multi_value(self): |
| 442 |
read_only_entry = self.get_entry('mod-1') |
| 443 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 444 |
writable_entry.postalAddress.set(['postalAddress-1', 'postalAddress-2']) |
| 445 |
result = writable_entry.entry_commit_changes() |
| 446 |
self.assertTrue(result) |
| 447 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 448 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 449 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 450 |
self.compare_entries(read_only_entry, writable_entry) |
| 451 |
|
| 452 |
def test_search_and_implicit_set_values_from_sequence_to_non_existing_multi_value(self): |
| 453 |
read_only_entry = self.get_entry('mod-1') |
| 454 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 455 |
writable_entry.postalAddress = ['postalAddress-1', 'postalAddress-2'] |
| 456 |
result = writable_entry.entry_commit_changes() |
| 457 |
self.assertTrue(result) |
| 458 |
self.assertTrue('postalAddress-1' in writable_entry.postalAddress) |
| 459 |
self.assertTrue('postalAddress-2' in writable_entry.postalAddress) |
| 460 |
self.assertEqual(len(writable_entry.postalAddress), 2) |
| 461 |
self.compare_entries(read_only_entry, writable_entry) |
| 462 |
|
| 463 |
def test_search_and_remove_existing_attribute(self): |
| 464 |
read_only_entry = self.get_entry('mod-1') |
| 465 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 466 |
writable_entry[test_multivalued_attribute].remove() |
| 467 |
result = writable_entry.entry_commit_changes() |
| 468 |
self.assertTrue(result) |
| 469 |
self.assertEqual(writable_entry[test_multivalued_attribute].values, []) |
| 470 |
self.assertEqual(writable_entry[test_multivalued_attribute].virtual, True) |
| 471 |
|
| 472 |
def test_search_and_delete_value_from_existing_single_value(self): |
| 473 |
read_only_entry = self.get_entry('mod-2') |
| 474 |
writable_entry = read_only_entry.entry_writable('inetorgperson', attributes='preferreddeliverymethod') |
| 475 |
writable_entry[test_singlevalued_attribute].delete('init') |
| 476 |
result = writable_entry.entry_commit_changes() |
| 477 |
self.assertTrue(result) |
| 478 |
self.assertEqual(writable_entry[test_singlevalued_attribute].value, None) |
| 479 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 0) |
| 480 |
|
| 481 |
def test_search_and_implicit_delete_value_from_existing_single_value(self): |
| 482 |
read_only_entry = self.get_entry('mod-2') |
| 483 |
writable_entry = read_only_entry.entry_writable('inetorgperson', attributes='preferreddeliverymethod') |
| 484 |
writable_entry[test_singlevalued_attribute] -= 'init' |
| 485 |
result = writable_entry.entry_commit_changes() |
| 486 |
self.assertTrue(result) |
| 487 |
self.assertEqual(writable_entry[test_singlevalued_attribute].value, None) |
| 488 |
self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 0) |
| 489 |
|
| 490 |
def test_search_and_delete_value_from_existing_multi_value(self): |
| 491 |
read_only_entry = self.get_entry('mod-2') |
| 492 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 493 |
writable_entry[test_multivalued_attribute].delete('givenname-2a') |
| 494 |
result = writable_entry.entry_commit_changes() |
| 495 |
self.assertTrue(result) |
| 496 |
self.assertTrue('givenname-2b' in writable_entry[test_multivalued_attribute].value) |
| 497 |
self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value) |
| 498 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 499 |
|
| 500 |
def test_search_and_implicit_delete_value_from_existing_multi_value(self): |
| 501 |
read_only_entry = self.get_entry('mod-2') |
| 502 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 503 |
writable_entry[test_multivalued_attribute] -= 'givenname-2a' |
| 504 |
result = writable_entry.entry_commit_changes() |
| 505 |
self.assertTrue(result) |
| 506 |
self.assertTrue('givenname-2b' in writable_entry[test_multivalued_attribute].value) |
| 507 |
self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value) |
| 508 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2) |
| 509 |
|
| 510 |
def test_search_and_delete_values_from_existing_multi_value(self): |
| 511 |
read_only_entry = self.get_entry('mod-2') |
| 512 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 513 |
writable_entry[test_multivalued_attribute].delete(['givenname-2a', 'givenname-2b']) |
| 514 |
result = writable_entry.entry_commit_changes() |
| 515 |
self.assertTrue(result) |
| 516 |
self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value) |
| 517 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1) |
| 518 |
|
| 519 |
def test_search_and_implicit_delete_values_from_existing_multi_value(self): |
| 520 |
read_only_entry = self.get_entry('mod-2') |
| 521 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 522 |
writable_entry[test_multivalued_attribute] -= ['givenname-2a', 'givenname-2b'] |
| 523 |
result = writable_entry.entry_commit_changes() |
| 524 |
self.assertTrue(result) |
| 525 |
self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value) |
| 526 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1) |
| 527 |
|
| 528 |
def test_search_and_delete_all_values_from_existing_multi_value(self): |
| 529 |
read_only_entry = self.get_entry('mod-2') |
| 530 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 531 |
writable_entry[test_multivalued_attribute].delete(['givenname-2a', 'givenname-2b', 'givenname-2c']) |
| 532 |
result = writable_entry.entry_commit_changes() |
| 533 |
self.assertTrue(result) |
| 534 |
self.assertEqual(writable_entry[test_multivalued_attribute].value, None) |
| 535 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 0) |
| 536 |
|
| 537 |
def test_search_and_implicit_delete_all_values_from_existing_multi_value(self): |
| 538 |
read_only_entry = self.get_entry('mod-2') |
| 539 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 540 |
writable_entry[test_multivalued_attribute] -= ['givenname-2a', 'givenname-2b', 'givenname-2c'] |
| 541 |
result = writable_entry.entry_commit_changes() |
| 542 |
self.assertTrue(result) |
| 543 |
self.assertEqual(writable_entry[test_multivalued_attribute].value, None) |
| 544 |
self.assertEqual(len(writable_entry[test_multivalued_attribute]), 0) |
| 545 |
|
| 546 |
def test_search_and_add_value_to_existing_multi_value_using_alias(self): |
| 547 |
if test_server_type != 'AD': # AD doens't use alias for cn |
| 548 |
read_only_entry = self.get_entry('mod-1') |
| 549 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 550 |
self.assertTrue(testcase_id + 'mod-1' in writable_entry.cn) |
| 551 |
self.assertTrue(testcase_id + 'mod-1' in writable_entry.commonname) |
| 552 |
writable_entry.commonname.add('added-commonname-1') |
| 553 |
result = writable_entry.entry_commit_changes() |
| 554 |
self.assertTrue(result) |
| 555 |
self.assertTrue('added-commonname-1' in writable_entry.cn) |
| 556 |
self.assertTrue('added-commonname-1' in writable_entry.commonname) |
| 557 |
self.assertEqual(len(writable_entry.commonname), 2) |
| 558 |
self.compare_entries(read_only_entry, writable_entry) |
| 559 |
|
| 560 |
def test_search_and_implicit_add_value_to_existing_multi_value_using_alias(self): |
| 561 |
if test_server_type != 'AD': # AD doens't use alias for cn |
| 562 |
read_only_entry = self.get_entry('mod-1') |
| 563 |
writable_entry = read_only_entry.entry_writable('inetorgperson') |
| 564 |
self.assertTrue(testcase_id + 'mod-1' in writable_entry.cn) |
| 565 |
self.assertTrue(testcase_id + 'mod-1' in writable_entry.commonname) |
| 566 |
writable_entry.commonname += 'implicit-added-commonname-1' |
| 567 |
result = writable_entry.entry_commit_changes() |
| 568 |
self.assertTrue(result) |
| 569 |
self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute]) |
| 570 |
self.assertTrue('implicit-added-commonname-1' in writable_entry.cn) |
| 571 |
self.assertTrue('implicit-added-commonname-1' in writable_entry.commonname) |
| 572 |
self.assertEqual(len(writable_entry.commonname), 2) |
| 573 |
self.compare_entries(read_only_entry, writable_entry) |
| 574 |
|