| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2026 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 |
"""Exercise objectclass index entry IDs when the suffix is created after replication.""" |
| 10 |
|
| 11 |
import logging |
| 12 |
import os |
| 13 |
import re |
| 14 |
import pytest |
| 15 |
|
| 16 |
from lib389._constants import DEFAULT_BENAME, DEFAULT_SUFFIX |
| 17 |
from lib389.idm.domain import Domain |
| 18 |
from lib389.idm.organizationalunit import OrganizationalUnits |
| 19 |
from lib389.replica import Replicas |
| 20 |
from test389.topologies import topology_no_sample |
| 21 |
|
| 22 |
pytestmark = pytest.mark.tier2 |
| 23 |
|
| 24 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 25 |
if DEBUGGING: |
| 26 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 27 |
else: |
| 28 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 29 |
log = logging.getLogger(__name__) |
| 30 |
|
| 31 |
|
| 32 |
def _assert_oc_index_missing_key(inst, key): |
| 33 |
"""Dump the objectclass index with dbscan -r; equality key ``key`` must not appear.""" |
| 34 |
inst.stop() |
| 35 |
try: |
| 36 |
if inst.get_db_lib() == "mdb": |
| 37 |
path = os.path.join(inst.dbdir, DEFAULT_BENAME.lower(), "objectclass") |
| 38 |
else: |
| 39 |
path = os.path.join(inst.dbdir, DEFAULT_BENAME, "objectclass.db") |
| 40 |
out = inst.dbscan( |
| 41 |
None, |
| 42 |
None, |
| 43 |
args=["-f", path, "-r"], |
| 44 |
stopping=False, |
| 45 |
check_result=False, |
| 46 |
).decode("utf-8", errors="replace") |
| 47 |
finally: |
| 48 |
inst.start() |
| 49 |
log.info("dbscan objectclass index (expect no %s):\n%s", key, out) |
| 50 |
for line in out.splitlines(): |
| 51 |
if line.strip() == key: |
| 52 |
raise AssertionError( |
| 53 |
f"objectclass index unexpectedly contains equality key {key!r}:\n{out}" |
| 54 |
) |
| 55 |
|
| 56 |
|
| 57 |
def _assert_oc_index_key_contains_id(inst, key, eid): |
| 58 |
"""Run dbscan -r on the objectclass index; require key and entry ID (see dbscan idl_format).""" |
| 59 |
inst.stop() |
| 60 |
try: |
| 61 |
if inst.get_db_lib() == "mdb": |
| 62 |
path = os.path.join(inst.dbdir, DEFAULT_BENAME.lower(), "objectclass") |
| 63 |
else: |
| 64 |
path = os.path.join(inst.dbdir, DEFAULT_BENAME, "objectclass.db") |
| 65 |
out = inst.dbscan( |
| 66 |
None, |
| 67 |
None, |
| 68 |
args=["-f", path, "-k", key, "-r"], |
| 69 |
stopping=False, |
| 70 |
check_result=False, |
| 71 |
).decode("utf-8", errors="replace") |
| 72 |
finally: |
| 73 |
inst.start() |
| 74 |
log.info("dbscan -k %s output:\n%s", key, out) |
| 75 |
if not re.search(rf"\b{eid}\b", out): |
| 76 |
raise AssertionError( |
| 77 |
f"expected objectclass index key {key!r} to list id {eid}; output:\n{out}" |
| 78 |
) |
| 79 |
|
| 80 |
|
| 81 |
def test_objectclass_index_ids_repl_before_suffix(topology_no_sample): |
| 82 |
"""objectclass equality keys track entry IDs when the suffix is added after replication. |
| 83 |
|
| 84 |
:id: c4a8e2b1-7f3d-4a1e-9c02-8b6d5e4f3a10 |
| 85 |
:setup: Standalone instance with userRoot for dc=example,dc=com but no suffix entry; |
| 86 |
replication enabled as a single supplier. |
| 87 |
:steps: |
| 88 |
1. Enable replication on the backend (no suffix entry yet). |
| 89 |
2. dbscan objectclass index must not have an ``=domain`` key yet. |
| 90 |
3. dbscan objectclass index: ``=nstombstone`` must include ID 2 (RUV tombstone). |
| 91 |
4. Add the suffix entry (dc=example,dc=com). |
| 92 |
5. dbscan: ``=domain`` must include ID 1. |
| 93 |
6. Add an organizationalUnit under the suffix. |
| 94 |
7. dbscan: ``=organizationalunit`` must include ID 3. |
| 95 |
:expectedresults: |
| 96 |
1. Replication is configured. |
| 97 |
2. No domain objectclass key before the suffix exists. |
| 98 |
3. Tombstone objectclass is indexed for the RUV entry. |
| 99 |
4. Suffix entry exists. |
| 100 |
5. Domain objectclass maps to the suffix entry id. |
| 101 |
6. OU entry exists. |
| 102 |
7. organizationalUnit objectclass maps to the new entry id. |
| 103 |
""" |
| 104 |
inst = topology_no_sample.standalone |
| 105 |
|
| 106 |
log.info("Enable replication (supplier) without creating the suffix entry") |
| 107 |
replicas = Replicas(inst) |
| 108 |
replicas.create(properties={ |
| 109 |
'cn': 'replica', |
| 110 |
'nsDS5ReplicaRoot': DEFAULT_SUFFIX, |
| 111 |
'nsDS5ReplicaId': '1', |
| 112 |
'nsDS5Flags': '1', |
| 113 |
'nsDS5ReplicaType': '3', |
| 114 |
'nsDS5ReplicaBindDN': 'cn=replication manager,cn=config', |
| 115 |
}) |
| 116 |
|
| 117 |
log.info("Objectclass index must not have =domain before the suffix entry exists") |
| 118 |
_assert_oc_index_missing_key(inst, "=domain") |
| 119 |
|
| 120 |
log.info("Check RUV tombstone is indexed on objectclass with id 2") |
| 121 |
_assert_oc_index_key_contains_id(inst, "=nstombstone", 2) |
| 122 |
|
| 123 |
log.info("Create suffix entry %s", DEFAULT_SUFFIX) |
| 124 |
Domain(inst, DEFAULT_SUFFIX).create(properties={"dc": "example"}) |
| 125 |
|
| 126 |
log.info("Check domain objectclass is indexed with id 1") |
| 127 |
_assert_oc_index_key_contains_id(inst, "=domain", 1) |
| 128 |
|
| 129 |
log.info("Create organizational unit ou=testou under the suffix") |
| 130 |
OrganizationalUnits(inst, DEFAULT_SUFFIX).create(properties={"ou": "testou"}) |
| 131 |
|
| 132 |
log.info("Check organizationalUnit objectclass is indexed with id 3") |
| 133 |
_assert_oc_index_key_contains_id(inst, "=organizationalunit", 3) |