| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
import pytest |
| 10 |
import glob |
| 11 |
from lib389.tasks import * |
| 12 |
from lib389.utils import * |
| 13 |
from test389.topologies import topology_st |
| 14 |
|
| 15 |
from lib389._constants import DEFAULT_SUFFIX, HOST_STANDALONE, PORT_STANDALONE |
| 16 |
|
| 17 |
log = logging.getLogger(__name__) |
| 18 |
# Skip on versions 1.4.2 and before. Rewriters are expected in 1.4.3 |
| 19 |
pytestmark = [pytest.mark.tier2, |
| 20 |
pytest.mark.skipif(ds_is_older('1.4.3'), reason="Not implemented")] |
| 21 |
|
| 22 |
|
| 23 |
rewriters_container = "cn=rewriters,cn=config" |
| 24 |
|
| 25 |
def test_rewriters_container(topology_st): |
| 26 |
"""Test checks that rewriters container exists |
| 27 |
|
| 28 |
:id: 5514ae43-546b-4165-beac-896f7f0c9197 |
| 29 |
:setup: Standalone instance |
| 30 |
:steps: |
| 31 |
1. Check container of rewriteers |
| 32 |
:expectedresults: |
| 33 |
1. Search returns only one entry |
| 34 |
""" |
| 35 |
|
| 36 |
# Check container of rewriters |
| 37 |
ents = topology_st.standalone.search_s(rewriters_container, ldap.SCOPE_BASE, '(objectclass=*)') |
| 38 |
assert len(ents) == 1 |
| 39 |
|
| 40 |
log.info('Test PASSED') |
| 41 |
|
| 42 |
def test_foo_filter_rewriter(topology_st): |
| 43 |
"""Test that example filter rewriter 'foo' is register and search use it |
| 44 |
|
| 45 |
:id: d16cf7e9-4973-4747-8694-65818156a28e |
| 46 |
:setup: Standalone instance |
| 47 |
:steps: |
| 48 |
1. Register foo filter rewriters |
| 49 |
2. Restart the server |
| 50 |
3. Check that the filter 'foo=foo' is rewritten into 'cn=foo' |
| 51 |
:expectedresults: |
| 52 |
1. Success |
| 53 |
2. Success |
| 54 |
3. Success |
| 55 |
""" |
| 56 |
|
| 57 |
libslapd = os.path.join( topology_st.standalone.ds_paths.lib_dir, 'dirsrv/libslapd.so') |
| 58 |
if not os.path.exists(libslapd): |
| 59 |
libslapd = os.path.join( topology_st.standalone.ds_paths.lib_dir, 'dirsrv/libslapd.so.0') |
| 60 |
# register foo filter rewriters |
| 61 |
topology_st.standalone.add_s(Entry(( |
| 62 |
"cn=foo_filter,cn=rewriters,cn=config", { |
| 63 |
"objectClass": "top", |
| 64 |
"objectClass": "extensibleObject", |
| 65 |
"cn": "foo_filter", |
| 66 |
"nsslapd-libpath": libslapd, |
| 67 |
"nsslapd-filterrewriter": "example_foo2cn_filter_rewriter", |
| 68 |
} |
| 69 |
))) |
| 70 |
|
| 71 |
|
| 72 |
topology_st.standalone.restart(60) |
| 73 |
|
| 74 |
# Check that the filter 'foo=foo' is rewritten into 'cn=foo' |
| 75 |
ents = topology_st.standalone.search_s(rewriters_container, ldap.SCOPE_SUBTREE, '(foo=foo_filter)') |
| 76 |
assert len(ents) > 0 |
| 77 |
assert ents[0].dn == "cn=foo_filter,cn=rewriters,cn=config" |
| 78 |
|
| 79 |
log.info('Test PASSED') |
| 80 |
|