-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The RFC 2696 function decode_page_control() had a conversion error. `count` is an unsigned long. The correct format character for Py_BuildValue() is 'k', not 'l'. The problem caused the function to to return wrong value every now and then. I have seen 140728898420741 or 140728898420741 instead of 5. In Python 3, SimplePagedResultsControl converted cookie to text although it's an OCTET STRING. The cookie is now correctly converted to bytes. Add tests for all four uncovered helper functions. https://github.com/python-ldap/python-ldap/pull/10 Signed-off-by: Christian Heimes <cheimes@redhat.com>
- Loading branch information
Christian Heimes
authored and
Petr Viktorin
committed
Nov 25, 2017
1 parent
c296d61
commit 52077e8
Showing
5 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import unittest | ||
|
||
# Switch off processing .ldaprc or ldap.conf before importing _ldap | ||
os.environ['LDAPNOINIT'] = '1' | ||
|
||
import ldap | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters