2021-04-13 17:30:24 -07:00
|
|
|
import time
|
|
|
|
|
2021-04-01 12:15:05 -07:00
|
|
|
import pytest
|
2021-02-18 20:05:39 -08:00
|
|
|
|
|
|
|
from datahub.ingestion.run.pipeline import Pipeline
|
2025-05-19 08:39:53 +02:00
|
|
|
from datahub.testing import mce_helpers
|
2021-04-13 17:30:24 -07:00
|
|
|
from tests.test_helpers.docker_helpers import wait_for_port
|
2021-02-18 20:05:39 -08:00
|
|
|
|
|
|
|
|
2021-07-14 20:02:48 -07:00
|
|
|
@pytest.mark.integration
|
2021-04-13 17:30:24 -07:00
|
|
|
def test_ldap_ingest(docker_compose_runner, pytestconfig, tmp_path, mock_time):
|
2021-02-18 20:05:39 -08:00
|
|
|
test_resources_dir = pytestconfig.rootpath / "tests/integration/ldap"
|
|
|
|
|
2021-04-13 17:30:24 -07:00
|
|
|
with docker_compose_runner(
|
|
|
|
test_resources_dir / "docker-compose.yml", "ldap"
|
|
|
|
) as docker_services:
|
|
|
|
# The openldap container loads the sample data after exposing the port publicly. As such,
|
|
|
|
# we must wait a little bit extra to ensure that the sample data is loaded.
|
|
|
|
wait_for_port(docker_services, "openldap", 389)
|
2023-08-09 21:13:27 +04:00
|
|
|
# without this ldap server can provide empty results
|
2021-04-13 17:30:24 -07:00
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
pipeline = Pipeline.create(
|
|
|
|
{
|
|
|
|
"run_id": "ldap-test",
|
|
|
|
"source": {
|
|
|
|
"type": "ldap",
|
|
|
|
"config": {
|
|
|
|
"ldap_server": "ldap://localhost",
|
|
|
|
"ldap_user": "cn=admin,dc=example,dc=org",
|
|
|
|
"ldap_password": "admin",
|
|
|
|
"base_dn": "dc=example,dc=org",
|
2022-06-21 15:01:00 -04:00
|
|
|
"group_attrs_map": {
|
|
|
|
"members": "memberUid",
|
|
|
|
},
|
2023-02-01 19:37:14 -05:00
|
|
|
"custom_props_list": ["givenName"],
|
2021-04-13 17:30:24 -07:00
|
|
|
},
|
2021-02-18 20:05:39 -08:00
|
|
|
},
|
2021-04-13 17:30:24 -07:00
|
|
|
"sink": {
|
|
|
|
"type": "file",
|
|
|
|
"config": {
|
|
|
|
"filename": f"{tmp_path}/ldap_mces.json",
|
|
|
|
},
|
2021-02-18 20:05:39 -08:00
|
|
|
},
|
2021-04-13 17:30:24 -07:00
|
|
|
}
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
2021-02-18 20:05:39 -08:00
|
|
|
|
2021-06-30 16:53:20 -07:00
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
|
|
|
output_path=tmp_path / "ldap_mces.json",
|
|
|
|
golden_path=test_resources_dir / "ldap_mces_golden.json",
|
2021-04-13 17:30:24 -07:00
|
|
|
)
|
2022-08-02 01:04:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.integration
|
|
|
|
def test_ldap_memberof_ingest(docker_compose_runner, pytestconfig, tmp_path, mock_time):
|
|
|
|
test_resources_dir = pytestconfig.rootpath / "tests/integration/ldap"
|
|
|
|
|
|
|
|
with docker_compose_runner(
|
|
|
|
test_resources_dir / "docker-compose.yml", "ldap"
|
|
|
|
) as docker_services:
|
|
|
|
# The openldap container loads the sample data after exposing the port publicly. As such,
|
|
|
|
# we must wait a little bit extra to ensure that the sample data is loaded.
|
|
|
|
wait_for_port(docker_services, "openldap", 389)
|
2023-08-09 21:13:27 +04:00
|
|
|
# without this ldap server can provide empty results
|
2022-08-02 01:04:30 +03:00
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
pipeline = Pipeline.create(
|
|
|
|
{
|
|
|
|
"run_id": "ldap-test",
|
|
|
|
"source": {
|
|
|
|
"type": "ldap",
|
|
|
|
"config": {
|
|
|
|
"ldap_server": "ldap://localhost",
|
|
|
|
"ldap_user": "cn=admin,dc=example,dc=org",
|
|
|
|
"ldap_password": "admin",
|
|
|
|
"base_dn": "dc=example,dc=org",
|
|
|
|
"filter": "(memberOf=cn=HR Department,dc=example,dc=org)",
|
|
|
|
"attrs_list": ["+", "*"],
|
|
|
|
"group_attrs_map": {
|
|
|
|
"members": "member",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"sink": {
|
|
|
|
"type": "file",
|
|
|
|
"config": {
|
|
|
|
"filename": f"{tmp_path}/ldap_memberof_mces.json",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
|
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
|
|
|
output_path=tmp_path / "ldap_memberof_mces.json",
|
|
|
|
golden_path=test_resources_dir / "ldap_memberof_mces_golden.json",
|
|
|
|
)
|
2023-08-16 10:33:18 +05:30
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.integration
|
|
|
|
def test_ldap_ingest_with_email_as_username(
|
|
|
|
docker_compose_runner, pytestconfig, tmp_path, mock_time
|
|
|
|
):
|
|
|
|
test_resources_dir = pytestconfig.rootpath / "tests/integration/ldap"
|
|
|
|
|
|
|
|
with docker_compose_runner(
|
|
|
|
test_resources_dir / "docker-compose.yml", "ldap"
|
|
|
|
) as docker_services:
|
|
|
|
# The openldap container loads the sample data after exposing the port publicly. As such,
|
|
|
|
# we must wait a little bit extra to ensure that the sample data is loaded.
|
|
|
|
wait_for_port(docker_services, "openldap", 389)
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
pipeline = Pipeline.create(
|
|
|
|
{
|
|
|
|
"run_id": "ldap-test",
|
|
|
|
"source": {
|
|
|
|
"type": "ldap",
|
|
|
|
"config": {
|
|
|
|
"ldap_server": "ldap://localhost",
|
|
|
|
"ldap_user": "cn=admin,dc=example,dc=org",
|
|
|
|
"ldap_password": "admin",
|
|
|
|
"base_dn": "dc=example,dc=org",
|
|
|
|
"user_attrs_map": {"email": "mail"},
|
|
|
|
"group_attrs_map": {
|
|
|
|
"members": "memberUid",
|
|
|
|
"email": "mail",
|
|
|
|
},
|
|
|
|
"use_email_as_username": True,
|
|
|
|
"custom_props_list": ["givenName"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"sink": {
|
|
|
|
"type": "file",
|
|
|
|
"config": {
|
|
|
|
"filename": f"{tmp_path}/ldap_mces.json",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
|
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
|
|
|
output_path=tmp_path / "ldap_mces.json",
|
|
|
|
golden_path=test_resources_dir / "ldap_mces_golden.json",
|
|
|
|
)
|