Skip to content
Open
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
2 changes: 1 addition & 1 deletion docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
POSTGRES_HOST: postgres
# PYTHONTRACEMALLOC: 1
PYTHONDONTWRITEBYTECODE: 1
command: sh -c "python -B -m pytest -n auto -x -W ignore::DeprecationWarning -vv"
command: sh -c "python -B -m pytest -n auto -x -W ignore::DeprecationWarning -W ignore::coverage.exceptions.CoverageWarning -vv"
tty: true

postgres:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ show_missing = true

[tool.coverage.run]
concurrency = ["thread", "gevent"]
omit = [
"*/__dishka_factory_*",
]

# RUFF
# Ruff is a linter, not a type checker.
Expand Down
12 changes: 2 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@
from ldap_protocol.server import PoolClientHandler
from ldap_protocol.session_storage import RedisSessionStorage, SessionStorage
from ldap_protocol.session_storage.repository import SessionRepository
from ldap_protocol.utils.queries import get_base_directories, get_user
from ldap_protocol.utils.queries import get_user
from password_utils import PasswordUtils
from tests.constants import TEST_DATA, TEST_SYSTEM_ADMIN_DATA
from tests.constants import TEST_DATA


class TestProvider(Provider):
Expand Down Expand Up @@ -989,14 +989,6 @@ async def setup_session(
is_system=False,
)

domain = (await get_base_directories(session))[0]
await setup_gateway.create_dir(
data=TEST_SYSTEM_ADMIN_DATA,
is_system=True,
domain=domain,
parent=domain,
)

# NOTE: after setup environment we need base DN to be created
await password_use_cases.create_default_domain_policy()

Expand Down
4 changes: 0 additions & 4 deletions tests/search_request_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
{
"filter": f"(useraccountcontrol:1.2.840.113556.1.4.803:={UserAccountControlFlag.NORMAL_ACCOUNT})", # noqa: E501
"objects": [
"cn=System Administrator,dc=md,dc=test",
"cn=user0,cn=users,dc=md,dc=test",
"cn=user_admin,cn=users,dc=md,dc=test",
"cn=user_admin_for_roles,cn=users,dc=md,dc=test",
Expand Down Expand Up @@ -84,7 +83,6 @@
{
"filter": f"(!(userAccountControl:1.2.840.113556.1.4.803:={UserAccountControlFlag.ACCOUNTDISABLE}))", # noqa: E501
"objects": [
"cn=System Administrator,dc=md,dc=test",
"cn=user0,cn=users,dc=md,dc=test",
"cn=user_admin,cn=users,dc=md,dc=test",
"cn=user_admin_for_roles,cn=users,dc=md,dc=test",
Expand All @@ -106,7 +104,6 @@
+ UserAccountControlFlag.NORMAL_ACCOUNT
})",
"objects": [
"cn=System Administrator,dc=md,dc=test",
"cn=user0,cn=users,dc=md,dc=test",
"cn=user_admin,cn=users,dc=md,dc=test",
"cn=user_admin_for_roles,cn=users,dc=md,dc=test",
Expand All @@ -127,7 +124,6 @@
{
"filter": f"(!(userAccountControl:1.2.840.113556.1.4.804:={UserAccountControlFlag.ACCOUNTDISABLE}))", # noqa: E501
"objects": [
"cn=System Administrator,dc=md,dc=test",
"cn=user0,cn=users,dc=md,dc=test",
"cn=user_admin,cn=users,dc=md,dc=test",
"cn=user_admin_for_roles,cn=users,dc=md,dc=test",
Expand Down
49 changes: 49 additions & 0 deletions tests/test_api/test_main/test_router/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Test router config.

Copyright (c) 2026 MultiFactor
License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE
"""

import pytest_asyncio
from sqlalchemy.ext.asyncio import AsyncSession

from ldap_protocol.auth.setup_gateway import SetupGateway
from ldap_protocol.ldap_schema.attribute_value_validator import (
AttributeValueValidator,
)
from ldap_protocol.ldap_schema.entity_type_dao import EntityTypeDAO
from ldap_protocol.ldap_schema.object_class_dao import ObjectClassDAO
from ldap_protocol.utils.queries import get_base_directories
from password_utils import PasswordUtils
from tests.constants import TEST_SYSTEM_ADMIN_DATA


@pytest_asyncio.fixture(scope="function")
async def add_system_administrator(
session: AsyncSession,
password_utils: PasswordUtils,
setup_session: None, # noqa: ARG001
) -> None:
"""Create system administrator user for tests that require it."""
object_class_dao = ObjectClassDAO(session)
attribute_value_validator = AttributeValueValidator()
entity_type_dao = EntityTypeDAO(
session,
object_class_dao=object_class_dao,
attribute_value_validator=attribute_value_validator,
)

setup_gateway = SetupGateway(
session,
password_utils,
entity_type_dao,
attribute_value_validator=attribute_value_validator,
)

domain = (await get_base_directories(session))[0]
await setup_gateway.create_dir(
data=TEST_SYSTEM_ADMIN_DATA,
is_system=True,
domain=domain,
parent=domain,
)
1 change: 1 addition & 0 deletions tests/test_api/test_main/test_router/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def test_api_correct_delete(http_client: AsyncClient) -> None:
@pytest.mark.asyncio
@pytest.mark.usefixtures("setup_session")
@pytest.mark.usefixtures("session")
@pytest.mark.usefixtures("add_system_administrator")
async def test_api_cant_delete_system_directory(
http_client: AsyncClient,
) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_api/test_main/test_router/test_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ async def test_api_modify_non_exist_object(http_client: AsyncClient) -> None:

@pytest.mark.asyncio
@pytest.mark.usefixtures("session")
@pytest.mark.usefixtures("add_system_administrator")
async def test_api_cant_modify_system_directory(
http_client: AsyncClient,
) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_api/test_main/test_router/test_modify_dn.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ async def test_api_update_dn_non_exist_superior(
@pytest.mark.asyncio
@pytest.mark.usefixtures("setup_session")
@pytest.mark.usefixtures("session")
@pytest.mark.usefixtures("add_system_administrator")
async def test_api_cant_update_system_directory(
http_client: AsyncClient,
) -> None:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_api/test_main/test_router/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ async def test_api_search(http_client: AsyncClient) -> None:
assert response["resultCode"] == LDAPCodes.SUCCESS

sub_dirs = {
"cn=System Administrator,dc=md,dc=test",
"cn=groups,dc=md,dc=test",
"cn=users,dc=md,dc=test",
"ou=testModifyDn1,dc=md,dc=test",
Expand Down Expand Up @@ -281,7 +280,6 @@ async def test_api_search_recursive_memberof(http_client: AsyncClient) -> None:
"""Test api search."""
group = "cn=domain admins,cn=groups,dc=md,dc=test"
members = [
"cn=System Administrator,dc=md,dc=test",
"cn=developers,cn=groups,dc=md,dc=test",
"cn=user0,cn=users,dc=md,dc=test",
"cn=user_admin,cn=users,dc=md,dc=test",
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ldap/test_roles/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ async def test_role_search_3(
creds=creds,
search_base=BASE_DN,
expected_dn=[
"dn: cn=System Administrator,dc=md,dc=test",
"dn: cn=groups,dc=md,dc=test",
"dn: cn=users,dc=md,dc=test",
"dn: cn=user_non_admin,cn=users,dc=md,dc=test",
Expand Down Expand Up @@ -190,7 +189,6 @@ async def test_role_search_5(
creds=creds,
search_base=BASE_DN,
expected_dn=[
"dn: cn=System Administrator,dc=md,dc=test",
"dn: cn=user1,cn=moscow,cn=russia,cn=users,dc=md,dc=test",
"dn: cn=user_non_admin,cn=users,dc=md,dc=test",
"dn: cn=user_admin_for_roles,cn=users,dc=md,dc=test",
Expand Down
Loading