Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/alembic/versions/708b01eaf025_convert_schema_to_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ldap_protocol.ldap_schema.directory_create_use_case import (
DirectoryCreateUseCase,
)
from ldap_protocol.ldap_schema.dto import AttributeDTO, CreateDirDTO
from ldap_protocol.ldap_schema.dto import AttributeDTO, DirCreateDTO
from ldap_protocol.ldap_schema.entity_type.entity_type_use_case import (
EntityTypeUseCase,
)
Expand Down Expand Up @@ -77,7 +77,7 @@ async def _create_ldap_configuration_directory(
if not base_dirs:
return

_dto = CreateDirDTO(
_dto = DirCreateDTO(
name=CONFIGURATION_DIR_NAME,
entity_type_name=EntityTypeNames.CONFIGURATION,
attributes=(
Expand Down
4 changes: 2 additions & 2 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@
{
"name": CONFIGURATION_DIR_NAME,
"entity_type_name": EntityTypeNames.CONFIGURATION,
"object_class": "",
"attributes": {"objectClass": ["top", "container", "configuration"]},
"object_class": "container",
"attributes": {"objectClass": ["top", "configuration"]},
},
{
"name": GROUPS_CONTAINER_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ldap_protocol.ldap_schema.dto import (
AttributeDTO,
AttributeTypeDTO,
CreateDirDTO,
DirCreateDTO,
)
from ldap_protocol.ldap_schema.exceptions import (
AttributeTypeAlreadyExistsError,
Expand Down Expand Up @@ -85,7 +85,7 @@ async def create(self, dto: AttributeTypeDTO) -> None:
if not dto.ldap_display_name:
dto.ldap_display_name = f"{dto.name[0].lower()}{dto.name.replace('-', '')[1:]}" # noqa: E501 # fmt: skip

_dto = CreateDirDTO(
_dto = DirCreateDTO(
name=dto.name,
entity_type_name=EntityTypeNames.ATTRIBUTE_TYPE,
attributes=(
Expand Down
4 changes: 2 additions & 2 deletions app/ldap_protocol/ldap_schema/directory_create_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ldap_protocol.ldap_schema.attribute_dao import AttributeDAO
from ldap_protocol.ldap_schema.directory_dao import DirectoryDAO
from ldap_protocol.ldap_schema.dto import AttributeDTO, CreateDirDTO
from ldap_protocol.ldap_schema.dto import AttributeDTO, DirCreateDTO
from ldap_protocol.ldap_schema.entity_type.entity_type_use_case import (
EntityTypeUseCase,
)
Expand Down Expand Up @@ -64,7 +64,7 @@ async def delete_configuration_dir(self) -> None:

async def create_dir(
self,
dto: CreateDirDTO,
dto: DirCreateDTO,
parent_dir: "Directory",
) -> None:
"""Create."""
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_schema/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AttributeDTO:


@dataclass
class CreateDirDTO:
class DirCreateDTO:
name: str
entity_type_name: EntityTypeNames
attributes: tuple[AttributeDTO, ...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ async def update(self, name: str, dto: EntityTypeDTO) -> None:
"""Update Entity Type."""
try:
entity_type = await self.get(name)

except EntityTypeNotFoundError:
raise EntityTypeCantModifyError
raise EntityTypeCantModifyError(
"Can't update non-existent Entity Type.",
)

if entity_type.is_system:
raise EntityTypeCantModifyError(
f"Entity Type '{dto.name}' is system and cannot be modified.",
)

if name != dto.name:
await self._validate_name(name=dto.name)

Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_schema/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ObjectClassNotFoundError(LdapSchemaError):


class ObjectClassNotSetKindError(LdapSchemaError):
"""Raised when an object class is not found."""
"""Raised when an object class is not set kind (structural, auxiliary or abstract).""" # noqa: E501

code = ErrorCodes.OBJECT_CLASS_NOT_SET_KIND_ERROR

Expand Down
50 changes: 28 additions & 22 deletions app/ldap_protocol/ldap_schema/object_class/object_class_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from ldap_protocol.ldap_schema.dto import (
AttributeDTO,
CreateDirDTO,
DirCreateDTO,
ObjectClassDTO,
)
from ldap_protocol.ldap_schema.entity_type.entity_type_dao import EntityTypeDAO
Expand Down Expand Up @@ -116,34 +116,40 @@ async def create(self, dto: ObjectClassDTO[None, str]) -> None:
"not found in schema.",
)

_dto = CreateDirDTO(
name=dto.name,
entity_type_name=EntityTypeNames.OBJECT_CLASS,
attributes=(
AttributeDTO(
name=Names.OBJECT_CLASS,
values=OBJECT_CLASS_OBJECT_CLASS_NAMES,
),
AttributeDTO(name=Names.OID, values=[str(dto.oid)]),
attributes = [
AttributeDTO(
name=Names.OBJECT_CLASS,
values=OBJECT_CLASS_OBJECT_CLASS_NAMES,
),
AttributeDTO(name=Names.OID, values=[str(dto.oid)]),
AttributeDTO(name=Names.KIND, values=[dto.kind.value]),
AttributeDTO(
name=Names.ATTRIBUTE_TYPES_MUST,
values=dto.attribute_types_must,
),
AttributeDTO(
name=Names.ATTRIBUTE_TYPES_MAY,
values=dto.attribute_types_may,
),
]

if dto.superior_name:
attributes.append(
AttributeDTO(
name=Names.SUPERIOR_NAME,
values=[str(dto.superior_name)],
values=[dto.superior_name],
),
AttributeDTO(name=Names.KIND, values=[str(dto.kind)]),
AttributeDTO(
name=Names.ATTRIBUTE_TYPES_MUST,
values=dto.attribute_types_must,
),
AttributeDTO(
name=Names.ATTRIBUTE_TYPES_MAY,
values=dto.attribute_types_may,
),
),
)

_dir_create_dto = DirCreateDTO(
name=dto.name,
entity_type_name=EntityTypeNames.OBJECT_CLASS,
attributes=tuple(attributes),
is_system=dto.is_system,
)
try:
await self.__directory_create_use_case.create_dir(
dto=_dto,
dto=_dir_create_dto,
parent_dir=self.__parent_dir,
)
except IntegrityError:
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_schema/raw_definition_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def collect_object_class_dto_from_info(
"""Create Object Class by ObjectClassInfo."""
name = RawDefinitionParser._list_to_string(object_class_info.name)
if not name:
raise ValueError("Attribute Type name is required")
raise ValueError("Object Class name is required")

return ObjectClassDTO(
oid=object_class_info.oid,
Expand Down
5 changes: 4 additions & 1 deletion app/ldap_protocol/roles/access_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def _check_search_access(
elif ace.is_allow and ace.attribute_type_name is None:
return True, forbidden_attributes, set()

elif ace.attribute_type_name is not None:
allowed_attributes.add(ace.attribute_type_name.lower())

else:
allowed_attributes.add(ace.attribute_type_name.lower()) # type: ignore
raise ValueError(f"Invalid ACE configuration: {ace}")

if not allowed_attributes:
return False, set(), set()
Expand Down
2 changes: 1 addition & 1 deletion interface
16 changes: 8 additions & 8 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@

user_data_dict = {
"sam_account_name": "user0",
"user_principal_name": "user0",
"mail": "user0@mail.com",
"user_principal_name": "user0@md.test",
"mail": "user0@md.test",
"display_name": "user0",
"password": "password",
"groups": [DOMAIN_ADMIN_GROUP_NAME],
}

admin_user_data_dict = {
"sam_account_name": "user_admin",
"user_principal_name": "user_admin",
"mail": "user_admin@mail.com",
"user_principal_name": "user_admin@md.test",
"mail": "user_admin@md.test",
"display_name": "user_admin",
"password": "password",
"groups": [DOMAIN_ADMIN_GROUP_NAME],
}

user_with_login_perm_data_dict = {
"sam_account_name": "user_admin_for_roles",
"user_principal_name": "user_admin_for_roles",
"mail": "user_admin_for_roles@mail.com",
"user_principal_name": "user_admin_for_roles@md.test",
"mail": "user_admin_for_roles@md.test",
"display_name": "user_admin_for_roles",
"password": "password",
"groups": ["admin login only"],
Expand Down Expand Up @@ -462,8 +462,8 @@
{
"name": CONFIGURATION_DIR_NAME,
"entity_type_name": EntityTypeNames.CONFIGURATION,
"object_class": "",
"attributes": {"objectClass": ["top", "container", "configuration"]},
"object_class": "container",
"attributes": {"objectClass": ["top", "configuration"]},
"children": [],
},
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ldap/test_ldap3_whoami.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ async def test_bind_whoami(
"""Test anonymous pwd change."""
result = await ldap_client.whoami()

assert result == "u:user0"
assert result == "u:user0@md.test"
2 changes: 1 addition & 1 deletion tests/test_ldap/test_util/test_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def test_ldap_base_modify(

directory = (await session.scalars(query)).one()

assert directory.user.mail == "user0@mail.com" # type: ignore
assert directory.user.mail == "user0@md.test" # type: ignore

attributes = defaultdict(list)

Expand Down
Loading