Skip to content

Commit 4993d4a

Browse files
authored
Do not decode attribute values of post read control
Fixes: python-ldap#399 python-ldap#400
1 parent 0ef6175 commit 4993d4a

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Doc/reference/ldap-controls.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ search.
197197

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

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

201204
.. autoclass:: ldap.controls.readentry.ReadEntryControl
202205
:members:

Lib/ldap/controls/readentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def decodeControlValue(self,encodedControlValue):
4242
self.dn = str(decodedEntry[0])
4343
self.entry = {}
4444
for attr in decodedEntry[1]:
45-
self.entry[str(attr[0])] = [ str(attr_value) for attr_value in attr[1] ]
45+
self.entry[str(attr[0])] = [ bytes(attr_value) for attr_value in attr[1] ]
4646

4747

4848
class PreReadControl(ReadEntryControl):

Tests/t_ldap_controls_readentry.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import unittest
3+
4+
# Switch off processing .ldaprc or ldap.conf before importing _ldap
5+
os.environ['LDAPNOINIT'] = '1'
6+
7+
from ldap.controls import readentry # noqa: E402
8+
9+
10+
PRC_ENC = b'db\x04)uid=Administrator,cn=users,l=school,l=dev0503\x04\tentryUUID1&\x04$5d96cc2c-8e13-103a-8ca5-2f74868e0e44'
11+
PRC_DEC = b'0\x0b\x04\tentryUUID'
12+
13+
14+
class TestLibldapControls(unittest.TestCase):
15+
16+
def test_pagedresults_encode(self):
17+
pr = readentry.PostReadControl(True, ['entryUUID'])
18+
self.assertEqual(pr.encodeControlValue(), PRC_DEC)
19+
20+
def test_readentry_decode(self):
21+
pr = readentry.PostReadControl(True, ['entryUUID'])
22+
pr.decodeControlValue(PRC_ENC)
23+
self.assertIsInstance(pr.dn, str)
24+
self.assertEqual(pr.entry, {'entryUUID': [b'5d96cc2c-8e13-103a-8ca5-2f74868e0e44']})
25+
26+
27+
if __name__ == '__main__':
28+
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy