| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2013.08.26 |
| 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 unicodedata import lookup |
| 28 |
# |
| 29 |
# from ldap3.protocol.sasl.sasl import validate_simple_password |
| 30 |
|
| 31 |
import unittest |
| 32 |
from unicodedata import lookup |
| 33 |
|
| 34 |
from ldap3.protocol.sasl.sasl import validate_simple_password |
| 35 |
|
| 36 |
|
| 37 |
class Test(unittest.TestCase): |
| 38 |
def test_valid_simple_alphanumeric_password(self): |
| 39 |
password = 'abcdefg1234567890ABCDEFG' |
| 40 |
validated = validate_simple_password(password) |
| 41 |
self.assertEqual(b'abcdefg1234567890ABCDEFG', validated) |
| 42 |
|
| 43 |
def test_valid_simple_alphanumeric_bytes_password(self): |
| 44 |
password = b'abcdefg1234567890ABCDEFG' |
| 45 |
validated = validate_simple_password(password) |
| 46 |
self.assertEqual(b'abcdefg1234567890ABCDEFG', validated) |
| 47 |
|
| 48 |
def test_valid_simple_alphanumeric_password_with_ascii_characters(self): |
| 49 |
password = b'abcdefg1234567890ABCDEFG!"$%&/()=' |
| 50 |
validated = validate_simple_password(password) |
| 51 |
self.assertEqual(password, validated) |
| 52 |
|
| 53 |
def test_valid_simple_alphanumeric_password_with_non_ascii_characters(self): |
| 54 |
password = ''.join(['123', lookup('POUND SIGN'), 'abc']) |
| 55 |
validated = validate_simple_password(password) |
| 56 |
self.assertEqual(b'123\xc2\xa3abc', validated) |
| 57 |
|
| 58 |
def test_valid_simple_alphanumeric_password_with_mapped_to_nothing_characters(self): |
| 59 |
password = ''.join(['123', lookup('SOFT HYPHEN'), 'abc']) |
| 60 |
validated = validate_simple_password(password) |
| 61 |
self.assertEqual(b'123abc', validated) |
| 62 |
|
| 63 |
def test_valid_simple_alphanumeric_password_with_mapped_to_space_characters(self): |
| 64 |
password = ''.join(['123', lookup('FIGURE SPACE'), 'abc']) |
| 65 |
validated = validate_simple_password(password) |
| 66 |
self.assertEqual(b'123 abc', validated) |