Skip to content

Commit

Permalink
SF#66 and fixed constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Feb 5, 2016
1 parent 00e0773 commit 747adca
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions Tests/t_cext.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _init(self, reuse_existing=True, bind=True):
# Perform a simple bind
l.set_option(_ldap.OPT_PROTOCOL_VERSION, _ldap.VERSION3)
m = l.simple_bind(server.get_root_dn(), server.get_root_password())
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ONE, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ONE, self.timeout)
self.assertTrue(result, _ldap.RES_BIND)
return l

Expand All @@ -56,7 +56,7 @@ def test_constants(self):
self.assertEquals(_ldap.VERSION2, 2)
self.assertEquals(_ldap.VERSION3, 3)

# constants for result3()
# constants for result4()
self.assertEquals(_ldap.RES_BIND, 0x61)
self.assertEquals(_ldap.RES_SEARCH_ENTRY, 0x64)
self.assertEquals(_ldap.RES_SEARCH_RESULT, 0x65)
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_constants(self):
self.assertNotNone(_ldap.MOD_INCREMENT)
self.assertNotNone(_ldap.MOD_BVALUES)

# for result3()
# for result4()
self.assertNotNone(_ldap.MSG_ONE)
self.assertNotNone(_ldap.MSG_ALL)
self.assertNotNone(_ldap.MSG_RECEIVED)
Expand Down Expand Up @@ -144,8 +144,8 @@ def test_constants(self):
self.assertNotNone(_ldap.AVA_NONPRINTABLE)

# these two constants are pointless? XXX
self.assertEquals(_ldap.LDAP_OPT_ON, 1)
self.assertEquals(_ldap.LDAP_OPT_OFF, 0)
self.assertEquals(_ldap.OPT_ON, 1)
self.assertEquals(_ldap.OPT_OFF, 0)

# these constants useless after ldap_url_parse() was dropped XXX
self.assertNotNone(_ldap.URL_ERR_BADSCOPE)
Expand All @@ -157,15 +157,15 @@ def test_simple_bind(self):
def test_simple_anonymous_bind(self):
l = self._init(bind=False)
m = l.simple_bind("", "")
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertTrue(result, _ldap.RES_BIND)
self.assertEquals(msgid, m)
self.assertEquals(pmsg, [])
self.assertEquals(ctrls, [])

# see if we can get the rootdse while we're here
m = l.search_ext("", _ldap.SCOPE_BASE, '(objectClass=*)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(pmsg[0][0], "") # rootDSE has no dn
self.assertEquals(msgid, m)
Expand All @@ -185,7 +185,7 @@ def test_search_ext_individual(self):

m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE,
'(objectClass=dcObject)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ONE, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ONE, self.timeout)

# Expect to get just one object
self.assertEquals(result, _ldap.RES_SEARCH_ENTRY)
Expand All @@ -198,7 +198,7 @@ def test_search_ext_individual(self):
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])

result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ONE, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ONE, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(pmsg, [])
self.assertEquals(msgid, m)
Expand All @@ -214,7 +214,7 @@ def test_abandon(self):

got_timeout = False
try:
r = l.result3(m, _ldap.MSG_ALL, 0.3) # (timeout /could/ be longer)
r = l.result4(m, _ldap.MSG_ALL, 0.3) # (timeout /could/ be longer)
except _ldap.TIMEOUT, e:
got_timeout = True
self.assertTrue(got_timeout)
Expand All @@ -223,7 +223,7 @@ def test_search_ext_all(self):
l = self._init()

m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(objectClass=*)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)

# Expect to get some objects
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
Expand All @@ -240,15 +240,15 @@ def test_add(self):
('description', 'testing'),
])

result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)
self.assertEquals(pmsg, [])
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])

# search for it back
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=Foo)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)

# Expect to get the objects
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
Expand All @@ -272,14 +272,14 @@ def test_compare(self):
('cn', 'CompareTest'),
('userPassword', 'the_password'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

# try a false compare
m = l.compare_ext(dn, "userPassword", "bad_string")
compared_false = False
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail(repr(r))
except _ldap.COMPARE_FALSE:
compared_false = True
Expand All @@ -289,7 +289,7 @@ def test_compare(self):
m = l.compare_ext(dn, "userPassword", "the_password")
compared_true = False
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail(repr(r))
except _ldap.COMPARE_TRUE:
compared_true = True
Expand All @@ -298,7 +298,7 @@ def test_compare(self):
m = l.compare_ext(dn, "badAttribute", "ignoreme")
raised_error = False
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail(repr(r))
except _ldap.error:
raised_error = True
Expand All @@ -311,7 +311,7 @@ def test_delete_no_such_object(self):
not_found = False
m = l.delete_ext("cn=DoesNotExist,"+self.base)
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail(r)
except _ldap.NO_SUCH_OBJECT:
not_found = True
Expand All @@ -325,11 +325,11 @@ def test_delete(self):
('objectClass','organizationalRole'),
('cn', 'Deleteme'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

m = l.delete_ext(dn)
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_DELETE)
self.assertEquals(msgid, m)
self.assertEquals(pmsg, [])
Expand All @@ -344,7 +344,7 @@ def test_modify_no_such_object(self):
(_ldap.MOD_ADD, 'description', ['blah']),
])
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail(r)
except _ldap.NO_SUCH_OBJECT:
not_found = True
Expand All @@ -360,7 +360,7 @@ def DISABLED_test_modify_no_such_object_empty_attrs(self):
(_ldap.MOD_ADD, 'description', []),
])
self.assertTrue(isinstance(m, int))
r = l.result3(m, _ldap.MSG_ALL, self.timeout) # what should happen??
r = l.result4(m, _ldap.MSG_ALL, self.timeout) # what should happen??
self.fail(r)

def test_modify(self):
Expand All @@ -373,21 +373,21 @@ def test_modify(self):
('sn', 'Modify'),
('description', 'a description'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

m = l.modify_ext(dn, [
(_ldap.MOD_ADD, 'description', ['b desc', 'c desc']),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_MODIFY)
self.assertEquals(pmsg, [])
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])

# search for it back
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=AddToMe)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)

# Expect to get the objects
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
Expand All @@ -407,20 +407,20 @@ def test_rename(self):
('objectClass','organizationalRole'),
('cn', 'RenameMe'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

# do the rename with same parent
m = l.rename(dn, "cn=IAmRenamed")
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_MODRDN)
self.assertEquals(msgid, m)
self.assertEquals(pmsg, [])
self.assertEquals(ctrls, [])

# make sure the old one is gone
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=RenameMe)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(len(pmsg), 0) # expect no results
self.assertEquals(msgid, m)
Expand All @@ -429,7 +429,7 @@ def test_rename(self):
# check that the new one looks right
dn2 = "cn=IAmRenamed,"+self.base
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=IAmRenamed)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])
Expand All @@ -443,7 +443,7 @@ def test_rename(self):
('objectClass','organizationalUnit'),
('ou', 'RenameContainer'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

# WORKAROUND bug in slapd. (Without an existing child,
Expand All @@ -454,34 +454,34 @@ def test_rename(self):
('objectClass','organizationalRole'),
('cn', 'Bogus'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

# now rename from dn2 to the conater
dn3 = "cn=IAmRenamedAgain," + containerDn

# Now try renaming dn2 across container (simultaneous name change)
m = l.rename(dn2, "cn=IAmRenamedAgain", containerDn)
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_MODRDN)
self.assertEquals(msgid, m)
self.assertEquals(pmsg, [])
self.assertEquals(ctrls, [])

# make sure dn2 is gone
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=IAmRenamed)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(len(pmsg), 0) # expect no results
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])

m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(objectClass=*)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)

# make sure dn3 is there
m = l.search_ext(self.base, _ldap.SCOPE_SUBTREE, '(cn=IAmRenamedAgain)')
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_SEARCH_RESULT)
self.assertEquals(msgid, m)
self.assertEquals(ctrls, [])
Expand All @@ -507,7 +507,7 @@ def test_whoami_anonymous(self):

# Anonymous bind
m = l.simple_bind("", "")
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertTrue(result, _ldap.RES_BIND)

r = l.whoami_s()
Expand All @@ -524,20 +524,20 @@ def test_passwd(self):
('cn', 'PasswordTest'),
('userPassword', 'initial'),
])
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(result, _ldap.RES_ADD)

# try changing password with a wrong old-pw
m = l.passwd(dn, "bogus", "ignored")
try:
r = l.result3(m, _ldap.MSG_ALL, self.timeout)
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.fail("expected UNWILLING_TO_PERFORM")
except _ldap.UNWILLING_TO_PERFORM:
pass

# try changing password with a correct old-pw
m = l.passwd(dn, "initial", "changed")
result,pmsg,msgid,ctrls = l.result3(m, _ldap.MSG_ALL, self.timeout)
result,pmsg,msgid,ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
self.assertEquals(msgid, m)
self.assertEquals(pmsg, [])
self.assertEquals(result, _ldap.RES_EXTENDED)
Expand Down

0 comments on commit 747adca

Please sign in to comment.