Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue #399: do not decode attribute values of post read control #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/reference/ldap-controls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ search.

:rfc:`4527` - Lightweight Directory Access Protocol (LDAP): Read Entry Controls

.. versionchanged:: 4.0
The attribute values of the entry now consists of `bytes` instead of ISO8859-1 decoded `str`.


.. autoclass:: ldap.controls.readentry.ReadEntryControl
:members:
Expand Down
2 changes: 1 addition & 1 deletion Lib/ldap/controls/readentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def decodeControlValue(self,encodedControlValue):
self.dn = str(decodedEntry[0])
self.entry = {}
for attr in decodedEntry[1]:
self.entry[str(attr[0])] = [ str(attr_value) for attr_value in attr[1] ]
self.entry[str(attr[0])] = [ bytes(attr_value) for attr_value in attr[1] ]


class PreReadControl(ReadEntryControl):
Expand Down
28 changes: 28 additions & 0 deletions Tests/t_ldap_controls_readentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import unittest

# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'

from ldap.controls import readentry # noqa: E402


PRC_ENC = b'db\x04)uid=Administrator,cn=users,l=school,l=dev0503\x04\tentryUUID1&\x04$5d96cc2c-8e13-103a-8ca5-2f74868e0e44'
PRC_DEC = b'0\x0b\x04\tentryUUID'


class TestLibldapControls(unittest.TestCase):

def test_pagedresults_encode(self):
pr = readentry.PostReadControl(True, ['entryUUID'])
self.assertEqual(pr.encodeControlValue(), PRC_DEC)

def test_readentry_decode(self):
pr = readentry.PostReadControl(True, ['entryUUID'])
pr.decodeControlValue(PRC_ENC)
self.assertIsInstance(pr.dn, str)
self.assertEqual(pr.entry, {'entryUUID': [b'5d96cc2c-8e13-103a-8ca5-2f74868e0e44']})


if __name__ == '__main__':
unittest.main()