Debian Codegraph @

test/testExtendedOperations.py

raw
1 """
2 """
3
4 # Created on 2014.06.30
5 #
6 # Author: Giovanni Cannata
7 #
8 # Copyright 2014 - 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
28 from ldap3.core.exceptions import LDAPExtensionError
29 from test.config import test_user, test_server_context, test_server_edir_name, random_id, get_connection, drop_connection, add_user, test_server_type, \
30 test_name_attr, test_base, test_password
31
32
33 testcase_id = ''
34
35
36 class Test(unittest.TestCase):
37 def setUp(self):
38 global testcase_id
39 testcase_id = random_id()
40 self.connection = get_connection(check_names=True)
41 self.delete_at_teardown = []
42 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-1'))
43 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-2'))
44 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-3'))
45 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-4'))
46 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-5'))
47 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-6'))
48 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-7'))
49 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'pag-8'))
50
51 def tearDown(self):
52 drop_connection(self.connection, self.delete_at_teardown)
53 self.assertFalse(self.connection.bound)
54
55 def test_who_am_i_extension(self):
56 if test_server_type != 'EDIR':
57 if not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:
58 try:
59 if not self.connection.server.info:
60 self.connection.refresh_server_info()
61 user = self.connection.extend.standard.who_am_i()
62 self.assertTrue(user)
63 except LDAPExtensionError as e:
64 if not e.args[0] == 'extension not in DSA list of supported extensions':
65 raise
66
67 def test_get_bind_dn_extension(self):
68 if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:
69 result = self.connection.extend.novell.get_bind_dn()
70 self.assertTrue(test_user in result)
71
72 def test_paged_search_accumulator(self):
73 if not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:
74 responses = self.connection.extend.standard.paged_search(test_base, '(' + test_name_attr + '=' + testcase_id + 'pag-*)', generator=False, paged_size=3)
75 self.assertEqual(len(responses), 8)
76
77 def test_paged_search_generator(self):
78 if not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:
79 responses = []
80 for response in self.connection.extend.standard.paged_search(test_base, '(' + test_name_attr + '=' + testcase_id + 'pag-*)'):
81 responses.append(response)
82 self.assertEqual(len(responses), 8)
83
84 def test_novell_list_replicas(self):
85 if test_server_type == 'EDIR' and not self.connection.strategy.no_real_dsa:
86 result = self.connection.extend.novell.list_replicas('cn=' + test_server_edir_name + ',' + test_server_context)
87 self.assertEqual(result, ['', 'ou=referrals,o=test'])
88
89 def test_novell_replica_info(self):
90 if test_server_type == 'EDIR' and not self.connection.strategy.no_real_dsa:
91 result = self.connection.extend.novell.replica_info('cn=' + test_server_edir_name + ',' + test_server_context, '')
92 self.assertEqual(result, '')
93
94 def test_novell_partition_entry_count(self):
95 if test_server_type == 'EDIR' and not self.connection.strategy.no_real_dsa:
96 result = self.connection.extend.novell.partition_entry_count(test_base)
97 self.assertTrue(result > 0)
98
99 def test_novell_get_universal_password(self):
100 if test_server_type == 'EDIR' and not self.connection.strategy.no_real_dsa:
101 self.connection.start_tls()
102 result = self.connection.extend.novell.get_universal_password(test_user)
103 self.assertEqual(result, test_password)