| 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 ldap3 import MODIFY_REPLACE |
| 30 |
from ldap3.protocol.controls import build_control |
| 31 |
from ldap3.protocol.novell import Integer |
| 32 |
from test.config import add_user, get_connection, drop_connection, random_id, test_server_type, get_response_values |
| 33 |
|
| 34 |
testcase_id = '' |
| 35 |
|
| 36 |
|
| 37 |
class Test(unittest.TestCase): |
| 38 |
def setUp(self): |
| 39 |
global testcase_id |
| 40 |
testcase_id = random_id() |
| 41 |
self.connection = get_connection() |
| 42 |
self.delete_at_teardown = [] |
| 43 |
|
| 44 |
def tearDown(self): |
| 45 |
drop_connection(self.connection, self.delete_at_teardown) |
| 46 |
self.assertFalse(self.connection.bound) |
| 47 |
|
| 48 |
def test_commit_transaction(self): |
| 49 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 50 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-1')) |
| 51 |
transaction_control = self.connection.extend.novell.start_transaction() |
| 52 |
self.connection.modify(self.delete_at_teardown[0][0], {'givenName': (MODIFY_REPLACE, ['user-1b'])}, controls=[transaction_control]) |
| 53 |
self.connection.modify(self.delete_at_teardown[0][0], {'sn': (MODIFY_REPLACE, ['sn-user-1b'])}, controls=[transaction_control]) |
| 54 |
self.connection.extend.novell.end_transaction(commit=True, controls=[transaction_control]) |
| 55 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['givenName', 'sn']), self.connection) |
| 56 |
|
| 57 |
if response: |
| 58 |
self.assertEqual(response[0]['attributes']['givenName'][0], 'user-1b') |
| 59 |
self.assertEqual(response[0]['attributes']['sn'][0], 'sn-user-1b') |
| 60 |
else: |
| 61 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 62 |
|
| 63 |
def test_abort_transaction(self): |
| 64 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 65 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-1')) |
| 66 |
transaction_control = self.connection.extend.novell.start_transaction() |
| 67 |
self.connection.modify(self.delete_at_teardown[0][0], {'givenName': (MODIFY_REPLACE, ['user-1b'])}, controls=[transaction_control]) |
| 68 |
self.connection.modify(self.delete_at_teardown[0][0], {'sn': (MODIFY_REPLACE, ['sn-user-1b'])}, controls=[transaction_control]) |
| 69 |
self.connection.extend.novell.end_transaction(commit=False, controls=[transaction_control]) |
| 70 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['givenName', 'sn']), self.connection) |
| 71 |
if response: |
| 72 |
# self.assertEqual(response[0]['attributes']['givenName'][0], 'user-1b') |
| 73 |
self.assertEqual(response[0]['attributes']['sn'][0], 'user-1') |
| 74 |
else: |
| 75 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |
| 76 |
|
| 77 |
def test_invalid_transaction_cookie(self): |
| 78 |
if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa: |
| 79 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-1')) |
| 80 |
transaction_control = self.connection.extend.novell.start_transaction() |
| 81 |
invalid_transaction_control = build_control('2.16.840.1.113719.1.27.103.7', True, Integer(12345678), encode_control_value=True) |
| 82 |
self.connection.modify(self.delete_at_teardown[0][0], {'givenName': (MODIFY_REPLACE, ['user-1b'])}, controls=[transaction_control]) |
| 83 |
self.connection.modify(self.delete_at_teardown[0][0], {'sn': (MODIFY_REPLACE, ['sn-user-1b'])}, controls=[invalid_transaction_control]) |
| 84 |
self.connection.extend.novell.end_transaction(commit=True, controls=[transaction_control]) |
| 85 |
status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['givenName', 'sn']), self.connection) |
| 86 |
if response: |
| 87 |
self.assertEqual(response[0]['attributes']['givenName'][0], 'user-1b') |
| 88 |
self.assertEqual(response[0]['attributes']['sn'][0], 'user-1') |
| 89 |
else: |
| 90 |
self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found') |