Skip to content

Commit 428e470

Browse files
authored
Merge pull request #613 from MultiDirectoryLab/fix_kerberos_entity
fix: ensure case-insensitive object class name checks in DAO
2 parents a6f7049 + 60593be commit 428e470

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

app/extra/setup_dev.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from ldap_protocol.utils.queries import get_domain_object_class
2929
from models import (
3030
Attribute,
31-
AttributeType,
3231
Directory,
3332
DirectoryMembership,
3433
Group,
@@ -186,28 +185,6 @@ async def setup_enviroment(
186185
domain.rdname = ""
187186

188187
async with session.begin_nested():
189-
session.add(
190-
AttributeType(
191-
oid="1.2.3.4.5.6.7.8",
192-
name="attr_with_bvalue",
193-
syntax="1.3.6.1.4.1.1466.115.121.1.40", # Octet String
194-
single_value=True,
195-
no_user_modification=False,
196-
is_system=True,
197-
)
198-
)
199-
session.add(
200-
AttributeType(
201-
oid="1.2.3.4.5.6.7.8.9",
202-
name="testing_attr",
203-
syntax="1.3.6.1.4.1.1466.115.121.1.15",
204-
single_value=True,
205-
no_user_modification=False,
206-
is_system=True,
207-
)
208-
)
209-
await session.flush()
210-
211188
session.add(domain)
212189
session.add(
213190
NetworkPolicy(

app/ldap_protocol/ldap_schema/object_class_dao.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def _count_exists_object_class_by_names(
161161
count_query = (
162162
select(func.count())
163163
.select_from(ObjectClass)
164-
.where(ObjectClass.name.in_(object_class_names))
164+
.where(func.lower(ObjectClass.name).in_(object_class_names))
165165
)
166166
result = await self.__session.scalars(count_query)
167167
return result.one()
@@ -176,7 +176,9 @@ async def is_all_object_classes_exists(
176176
:raise ObjectClassNotFoundError: If Object Class not found.
177177
:return bool.
178178
"""
179-
object_class_names = set(object_class_names)
179+
object_class_names = set(
180+
object_class.lower() for object_class in object_class_names
181+
)
180182

181183
count_ = await self._count_exists_object_class_by_names(
182184
object_class_names

tests/conftest.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from ldap_protocol.server import PoolClientHandler
6161
from ldap_protocol.session_storage import RedisSessionStorage, SessionStorage
6262
from ldap_protocol.utils.queries import get_user
63-
from models import Directory
63+
from models import AttributeType, Directory
6464

6565

6666
class TestProvider(Provider):
@@ -431,6 +431,26 @@ async def setup_session(session: AsyncSession) -> None:
431431
groups=["cn=domain admins,cn=groups," + domain.path_dn],
432432
session=session,
433433
)
434+
session.add(
435+
AttributeType(
436+
oid="1.2.3.4.5.6.7.8",
437+
name="attr_with_bvalue",
438+
syntax="1.3.6.1.4.1.1466.115.121.1.40", # Octet String
439+
single_value=True,
440+
no_user_modification=False,
441+
is_system=True,
442+
)
443+
)
444+
session.add(
445+
AttributeType(
446+
oid="1.2.3.4.5.6.7.8.9",
447+
name="testing_attr",
448+
syntax="1.3.6.1.4.1.1466.115.121.1.15",
449+
single_value=True,
450+
no_user_modification=False,
451+
is_system=True,
452+
)
453+
)
434454
await session.commit()
435455

436456

0 commit comments

Comments
 (0)