-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathtest_ldap_source.py
88 lines (81 loc) · 1.92 KB
/
test_ldap_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pytest
from datahub.ingestion.source.ldap import parse_groups, parse_ldap_dn, parse_users
@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
@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",
]
},
[],
),
],
)
def test_parse_users(input, expected):
assert (
parse_users(
input,
"admins",
)
== expected
)
@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
)