| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2014.03.29 |
| 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 test.config import test_server, test_user, test_password, test_lazy_connection, test_get_info, test_server_mode, test_base, test_strategy, test_server_type |
| 29 |
from ldap3 import Server, Connection, ServerPool, RESTARTABLE, ROUND_ROBIN, BASE, MOCK_SYNC, MOCK_ASYNC |
| 30 |
|
| 31 |
|
| 32 |
class Test(unittest.TestCase): |
| 33 |
def test_restartable_invalid_server(self): |
| 34 |
if test_server_type != 'NONE' and test_strategy not in [MOCK_SYNC, MOCK_ASYNC]: |
| 35 |
if isinstance(test_server, (list, tuple)): |
| 36 |
hosts = ['a.b.c.d'] + list(test_server) |
| 37 |
else: |
| 38 |
hosts = ['a.b.c.d', test_server] |
| 39 |
search_results = [] |
| 40 |
servers = [Server(host=host, port=636, use_ssl=True, get_info=test_get_info, mode=test_server_mode) for host in hosts] |
| 41 |
connection = Connection(ServerPool(servers, ROUND_ROBIN, active=True, exhaust=True), user=test_user, password=test_password, client_strategy=RESTARTABLE, lazy=test_lazy_connection, pool_name='pool1') |
| 42 |
|
| 43 |
with connection as c: |
| 44 |
c.search(search_base=test_base, search_filter='(' + test_base.split(',')[0] + ')', search_scope=BASE, attributes='*') |
| 45 |
|
| 46 |
for resp in connection.response: |
| 47 |
if resp['type'] == 'searchResEntry': |
| 48 |
search_results.append(resp['dn']) |
| 49 |
self.assertEqual(len(search_results), 1) |
| 50 |
|
| 51 |
def test_restartable_invalid_server2(self): |
| 52 |
if test_server_type not in ['NONE', 'AD']: |
| 53 |
if test_strategy not in [MOCK_SYNC, MOCK_ASYNC]: |
| 54 |
if isinstance(test_server, (list, tuple)): |
| 55 |
hosts = ['a.b.c.d'] + list(test_server) |
| 56 |
else: |
| 57 |
hosts = ['a.b.c.d', test_server] |
| 58 |
search_results = [] |
| 59 |
servers = [Server(host=host, port=389, use_ssl=False) for host in hosts] |
| 60 |
server_pool = ServerPool(servers, ROUND_ROBIN, active=True, exhaust=True) |
| 61 |
connection = Connection(server_pool, user=test_user, password=test_password, client_strategy=RESTARTABLE, lazy=False) |
| 62 |
connection.open() |
| 63 |
connection.bind() |
| 64 |
connection.search(search_base=test_base, search_filter='(' + test_base.split(',')[0] + ')', search_scope=BASE) |
| 65 |
if connection.response: |
| 66 |
for resp in connection.response: |
| 67 |
if resp['type'] == 'searchResEntry': |
| 68 |
search_results.append(resp['dn']) |
| 69 |
connection.unbind() |
| 70 |
self.assertEqual(len(search_results), 1) |