🤖 Lire les attributs LDAP renvoyés avec une option (jpegPhoto;binary)

L'annuaire renvoie la photo de certaines fiches sous jpegPhoto;binary.
Ce nom ne correspondait pas à l'attribut demandé : la photo était
ignorée. Les attributs sont désormais rattachés à leur nom de base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
zeguiguiandClaude Opus 5.5 committed 2026-11-17 13:45:43 +01:00
1 parent 5b05311b82
commit 2ada724160
2 files changed
+41 -5

No files matched your search

+32
View File
@@ -94,3 +94,35 @@ def test_photo_returned_as_raw_bytes(connection, ldif_entries):
if "jpegPhoto" in attrs:
assert by_uid[attrs["uid"][0]]["jpegPhoto"] == attrs["jpegPhoto"]
break
class _StubConnection:
"""Connexion minimale qui renvoie les attributs tels que l'annuaire réel les nomme."""
def __init__(self, raw_attributes):
stub = self
class _Standard:
def paged_search(self, **kwargs):
return [{"type": "searchResEntry", "dn": "uid=x,ou=personnes,dc=example,dc=org",
"raw_attributes": stub.raw_attributes}]
class _Extend:
standard = _Standard()
self.raw_attributes = raw_attributes
self.extend = _Extend()
def test_attribute_with_binary_option_is_kept_under_its_base_name():
conn = _StubConnection({
"uid": [b"x"], "jpegPhoto;binary": [b"\xff\xd8photo"], "usrMotifAbsence": [b"ABC"],
})
entries = LdapSource(SETTINGS, conn).fetch_entries(required_attributes(MAPPING))
assert entries == [{"uid": [b"x"], "jpegPhoto": [b"\xff\xd8photo"]}]
def test_values_of_same_attribute_with_and_without_option_are_merged():
conn = _StubConnection({"uid": [b"x"], "jpegPhoto": [b"a"], "jpegPhoto;binary": [b"b"]})
entries = LdapSource(SETTINGS, conn).fetch_entries(required_attributes(MAPPING))
assert entries[0]["jpegPhoto"] == [b"a", b"b"]