| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2013.06.06 |
| 5 |
# |
| 6 |
# Author: Giovanni Cannata |
| 7 |
# |
| 8 |
# Copyright 2013 - 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 copy import deepcopy |
| 28 |
from time import sleep |
| 29 |
|
| 30 |
from test.config import get_connection, drop_connection, add_user, random_id, get_add_user_attributes,\ |
| 31 |
test_user_password, generate_dn, test_base |
| 32 |
|
| 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_add(self): |
| 49 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'add-operation-1')) |
| 50 |
self.assertEqual('success', self.delete_at_teardown[0][1]['description']) |
| 51 |
|
| 52 |
def test_add_bytes(self): |
| 53 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'add-operation-2', test_bytes=True)) |
| 54 |
self.assertEqual('success', self.delete_at_teardown[0][1]['description']) |
| 55 |
|
| 56 |
def test_unmodified_attributes_dict(self): |
| 57 |
attributes = get_add_user_attributes(testcase_id, 'add-operation-3', test_user_password) |
| 58 |
object_class = attributes.pop('objectClass') |
| 59 |
copy_of_attributes = deepcopy(attributes) |
| 60 |
dn = generate_dn(test_base, testcase_id, 'add-operation-3') |
| 61 |
self.connection.add(dn, object_class, attributes) |
| 62 |
sleep(2) |
| 63 |
self.connection.delete(dn) |
| 64 |
self.assertDictEqual(copy_of_attributes, attributes) |
| 65 |
|
| 66 |
def test_add_binary(self): |
| 67 |
try: |
| 68 |
bin1 = open('512b-rsa-example-cert.der', 'rb') |
| 69 |
except Exception: |
| 70 |
bin1 = open('test/512b-rsa-example-cert.der', 'rb') |
| 71 |
|
| 72 |
try: |
| 73 |
bin2 = open('1024b-rsa-example-cert.der', 'rb') |
| 74 |
except Exception: |
| 75 |
bin2 = open('test/1024b-rsa-example-cert.der', 'rb') |
| 76 |
|
| 77 |
der_certificates = [bin1.read(), bin2.read()] |
| 78 |
bin1.close() |
| 79 |
bin2.close() |
| 80 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'add-operation-4', attributes={'userCertificate;binary': der_certificates})) |
| 81 |
self.assertEqual('success', self.delete_at_teardown[0][1]['description']) |