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
|
import os
import unittest
# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'
from ldap.controls import pagedresults
from ldap.controls import libldap
PRC_BER = b'0\x0b\x02\x01\x05\x04\x06cookie'
SIZE = 5
COOKIE = b'cookie'
class TestLibldapControls(unittest.TestCase):
def test_pagedresults_encode(self):
pr = pagedresults.SimplePagedResultsControl(
size=SIZE, cookie=COOKIE
)
lib = libldap.SimplePagedResultsControl(
size=SIZE, cookie=COOKIE
)
self.assertEqual(pr.encodeControlValue(), lib.encodeControlValue())
self.assertEqual(pr.encodeControlValue(), PRC_BER)
def test_pagedresults_decode(self):
pr = pagedresults.SimplePagedResultsControl()
pr.decodeControlValue(PRC_BER)
self.assertEqual(pr.size, SIZE)
# LDAPString (OCTET STRING)
self.assertIsInstance(pr.cookie, bytes)
self.assertEqual(pr.cookie, COOKIE)
lib = libldap.SimplePagedResultsControl()
lib.decodeControlValue(PRC_BER)
self.assertEqual(lib.size, SIZE)
self.assertIsInstance(lib.cookie, bytes)
self.assertEqual(lib.cookie, COOKIE)
def test_matchedvalues(self):
mvc = libldap.MatchedValuesControl()
# unverified
self.assertEqual(mvc.encodeControlValue(), b'0\r\x87\x0bobjectClass')
def test_assertioncontrol(self):
ac = libldap.AssertionControl()
# unverified
self.assertEqual(ac.encodeControlValue(), b'\x87\x0bobjectClass')
if __name__ == '__main__':
unittest.main()
|