[PR #6688/032996e0 backport][stable-6] Fix composites comparison for role in is_struct_included keycloak.py … (#6689)

Fix composites comparison for role in is_struct_included keycloak.py … (#6688)

* Fix composites comparison for role in is_struct_included keycloak.py function

* Add changelog fragment and unit tests

* Update changelogs/fragments/6688-is-struct-included-bug-in-keycloak-py.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 032996e005)

Co-authored-by: Philippe Gauthier <philippe.gauthier@inspq.qc.ca>
This commit is contained in:
patchback[bot] 2023-06-14 23:30:30 +02:00 committed by GitHub
parent e7e2f095ee
commit e1f4be1e01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 3 deletions

View file

@ -207,24 +207,30 @@ def is_struct_included(struct1, struct2, exclude=None):
Return True if all element of dict 1 are present in dict 2, return false otherwise.
"""
if isinstance(struct1, list) and isinstance(struct2, list):
if not struct1 and not struct2:
return True
for item1 in struct1:
if isinstance(item1, (list, dict)):
for item2 in struct2:
if not is_struct_included(item1, item2, exclude):
return False
if is_struct_included(item1, item2, exclude):
break
else:
return False
else:
if item1 not in struct2:
return False
return True
elif isinstance(struct1, dict) and isinstance(struct2, dict):
if not struct1 and not struct2:
return True
try:
for key in struct1:
if not (exclude and key in exclude):
if not is_struct_included(struct1[key], struct2[key], exclude):
return False
return True
except KeyError:
return False
return True
elif isinstance(struct1, bool) and isinstance(struct2, bool):
return struct1 == struct2
else: