2021-04-22 22:56:30 +02:00
|
|
|
import pytest
|
|
|
|
|
2023-05-03 16:57:52 -04:00
|
|
|
from datahub.ingestion.source.ldap import parse_groups, parse_ldap_dn, parse_users
|
2022-04-08 20:48:48 +05:30
|
|
|
|
2021-04-22 22:56:30 +02:00
|
|
|
|
2023-05-03 16:57:52 -04:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input, expected",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
b"uid=firstname.surname,ou=People,dc=internal,dc=machines",
|
|
|
|
"firstname.surname",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
b"cn=group_name,ou=Groups,dc=internal,dc=machines",
|
|
|
|
"group_name",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
b"cn=comma group (one\\, two\\, three),ou=Groups,dc=internal,dc=machines",
|
|
|
|
"comma group (one, two, three)",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_parse_ldap_dn(input, expected):
|
|
|
|
assert parse_ldap_dn(input) == expected
|
2021-04-22 22:56:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input, expected",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"admins": [
|
|
|
|
b"uid=A.B,ou=People,dc=internal,dc=machines",
|
|
|
|
b"uid=C.D,ou=People,dc=internal,dc=machines",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
["urn:li:corpuser:A.B", "urn:li:corpuser:C.D"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"not_admins": [
|
|
|
|
b"doesntmatter",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2023-05-03 16:57:52 -04:00
|
|
|
def test_parse_users(input, expected):
|
2021-04-22 22:56:30 +02:00
|
|
|
assert (
|
2023-05-03 16:57:52 -04:00
|
|
|
parse_users(
|
2021-04-22 22:56:30 +02:00
|
|
|
input,
|
|
|
|
"admins",
|
|
|
|
)
|
|
|
|
== expected
|
|
|
|
)
|
2023-05-03 16:57:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input, expected",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"memberOf": [
|
|
|
|
b"cn=group1,ou=Groups,dc=internal,dc=machines",
|
|
|
|
b"cn=group2,ou=Groups,dc=internal,dc=machines",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
["urn:li:corpGroup:group1", "urn:li:corpGroup:group2"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"not_member": [
|
|
|
|
b"doesntmatter",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_parse_groups(input, expected):
|
|
|
|
assert (
|
|
|
|
parse_groups(
|
|
|
|
input,
|
|
|
|
"memberOf",
|
|
|
|
)
|
|
|
|
== expected
|
|
|
|
)
|