🤖 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:
1 parent
5b05311b82
commit
2ada724160
2 files changed
+41
-5
No files matched your search
@@ -88,13 +88,17 @@ class LdapSource:
|
||||
if self._settings.ldap_group_dns:
|
||||
members = self._group_members()
|
||||
results = [r for r in results if _normalize_dn(r["dn"]) in members]
|
||||
wanted = {a.lower() for a in attributes}
|
||||
# Clé : nom de base en minuscules -> orthographe du mapping.
|
||||
wanted = {a.lower(): a for a in attributes}
|
||||
entries: list[RawEntry] = []
|
||||
for result in results:
|
||||
raw = result.get("raw_attributes", {})
|
||||
entries.append(
|
||||
{name: list(values) for name, values in raw.items() if name.lower() in wanted and values}
|
||||
)
|
||||
entry: RawEntry = {}
|
||||
for name, values in result.get("raw_attributes", {}).items():
|
||||
# L'annuaire peut renvoyer l'attribut avec une option (jpegPhoto;binary).
|
||||
base = wanted.get(name.split(";", 1)[0].lower())
|
||||
if base and values:
|
||||
entry.setdefault(base, []).extend(values)
|
||||
entries.append(entry)
|
||||
return entries
|
||||
|
||||
def fetch_birthday_keys(self, key_attr: str) -> set[str]:
|
||||
|
||||
@@ -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"]
|
||||
Reference in new issue
Block a user