|
14 | 14 | as_datetime,
|
15 | 15 | dn_escape,
|
16 | 16 | parse_dn,
|
| 17 | + split_dn, |
17 | 18 | )
|
18 | 19 |
|
19 | 20 |
|
@@ -236,3 +237,61 @@ def test_parse_dn_invalid_attr_value_escape() -> None:
|
236 | 237 | expected = r"Found invalid escape sequence in attribute value at '\\1z"
|
237 | 238 | with pytest.raises(AnsibleFilterError, match=expected):
|
238 | 239 | parse_dn("foo=bar \\1z")
|
| 240 | + |
| 241 | + |
| 242 | +@pytest.mark.parametrize( |
| 243 | + "value, expected", |
| 244 | + [ |
| 245 | + ("", ""), |
| 246 | + ("CN=foo", "CN=foo"), |
| 247 | + (r"CN=foo,DC=bar", "CN=foo"), |
| 248 | + (r"CN=foo, DC=bar", "CN=foo"), |
| 249 | + (r"CN=foo , DC=bar", "CN=foo"), |
| 250 | + (r"CN=foo , DC=bar", "CN=foo"), |
| 251 | + (r"UID=jsmith,DC=example,DC=net", "UID=jsmith"), |
| 252 | + (r"OU=Sales+CN=J. Smith,DC=example,DC=net", "OU=Sales+CN=J. Smith"), |
| 253 | + (r"OU=Sales + CN=J. Smith,DC=example,DC=net", "OU=Sales+CN=J. Smith"), |
| 254 | + ( |
| 255 | + r"CN=James \"Jim\" Smith\, III,DC=example,DC=net", |
| 256 | + r"CN=James \"Jim\" Smith\, III", |
| 257 | + ), |
| 258 | + (r"CN=Before\0dAfter,DC=example,DC=net", r"CN=Before\0DAfter"), |
| 259 | + (r"1.3.6.1.4.1.1466.0=#FE04024869", "1.3.6.1.4.1.1466.0=\udcfe\x04\x02Hi"), |
| 260 | + (r"1.3.6.1.4.1.1466.0 = #FE04024869", "1.3.6.1.4.1.1466.0=\udcfe\x04\x02Hi"), |
| 261 | + (r"CN=Lu\C4\8Di\C4\87", "CN=Lučić"), |
| 262 | + ], |
| 263 | +) |
| 264 | +def test_split_dn_leaf(value: str, expected: str) -> None: |
| 265 | + actual = split_dn(value) |
| 266 | + assert actual == expected |
| 267 | + |
| 268 | + |
| 269 | +@pytest.mark.parametrize( |
| 270 | + "value, expected", |
| 271 | + [ |
| 272 | + ("", ""), |
| 273 | + ("CN=foo", ""), |
| 274 | + (r"CN=foo,DC=bar", "DC=bar"), |
| 275 | + (r"CN=foo, DC=bar", "DC=bar"), |
| 276 | + (r"CN=foo , DC=bar", "DC=bar"), |
| 277 | + (r"CN=foo , DC=bar", "DC=bar"), |
| 278 | + (r"UID=jsmith,DC=example,DC=net", "DC=example,DC=net"), |
| 279 | + (r"OU=Sales+CN=J. Smith,DC=example,DC=net", "DC=example,DC=net"), |
| 280 | + (r"OU=Sales + CN=J. Smith,DC=example,DC=net", "DC=example,DC=net"), |
| 281 | + ( |
| 282 | + r"CN=James \"Jim\" Smith\, III,DC=example,DC=net", |
| 283 | + r"DC=example,DC=net", |
| 284 | + ), |
| 285 | + (r"CN=Before\0dAfter,DC=example,DC=net", r"DC=example,DC=net"), |
| 286 | + (r"1.3.6.1.4.1.1466.0=#FE04024869", ""), |
| 287 | + (r"1.3.6.1.4.1.1466.0 = #FE04024869", ""), |
| 288 | + (r"CN=Lu\C4\8Di\C4\87", ""), |
| 289 | + ( |
| 290 | + r"CN=foo,DC=bar+C=US\, test+OU=Fake\+Test,DC=end", |
| 291 | + r"DC=bar+C=US\, test+OU=Fake\+Test,DC=end", |
| 292 | + ), |
| 293 | + ], |
| 294 | +) |
| 295 | +def test_split_dn_parent(value: str, expected: str) -> None: |
| 296 | + actual = split_dn(value, "parent") |
| 297 | + assert actual == expected |
0 commit comments