forked from zulip/fakeldap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
60 lines (48 loc) · 1.66 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from nose.tools import *
from fakeldap import MockLDAP
import unittest
directory = {
"cn=admin,dc=30loops,dc=net": {
"userPassword": "ldaptest"
}
}
class TestLdapOperations(unittest.TestCase):
def setUp(self):
self.mock_ldap = MockLDAP(directory)
def tearDown(self):
self.mock_ldap.reset()
def test_simple_bind_s_operation(self):
"""Try to bind a user."""
# Make a valid bind
eq_(
(97,[]),
self.mock_ldap.simple_bind_s("cn=admin,dc=30loops,dc=net", "ldaptest")
)
# Supply the wrong password
assert_raises(
MockLDAP.INVALID_CREDENTIALS,
self.mock_ldap.simple_bind_s,
who="cn=admin,dc=30loops,dc=net", cred="wrong"
)
def test_add_s_operation(self):
"""Test the addition of records to the mock ldap object."""
record = [
('uid', 'crito'),
('userPassword', 'secret'),
]
eq_((105,[],1,[]), self.mock_ldap.add_s(
"uid=crito,ou=people,dc=30loops,dc=net", record
))
directory = {
"cn=admin,dc=30loops,dc=net": {"userPassword": "ldaptest"},
"uid=crito,ou=people,dc=30loops,dc=net": {
"uid": "crito", "userPassword": "secret"}
}
eq_(directory, self.mock_ldap.directory)
record = [
('uid', 'bas'),
('userPassword', 'secret'),
]
eq_((105,[],2,[]), self.mock_ldap.add_s(
"uid=bas,ou=people,dc=30loops,dc=net", record
))