| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
|
| 3 |
# Copyright (C) 2025 Red Hat, Inc. |
| 4 |
# All rights reserved. |
| 5 |
# |
| 6 |
# License: GPL (version 3 or any later version). |
| 7 |
# See LICENSE for details. |
| 8 |
# --- END COPYRIGHT BLOCK --- |
| 9 |
# |
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
import time |
| 14 |
import ldap |
| 15 |
from lib389._constants import * |
| 16 |
from test389.topologies import topology_st as topo |
| 17 |
from lib389.plugins import MemberOfPlugin |
| 18 |
from lib389.config import LMDB_LDBMConfig |
| 19 |
from lib389.utils import get_default_db_lib |
| 20 |
from lib389.idm.user import UserAccounts |
| 21 |
from lib389.idm.group import Groups |
| 22 |
|
| 23 |
log = logging.getLogger(__name__) |
| 24 |
|
| 25 |
DEBUGGING = os.getenv('DEBUGGING', False) |
| 26 |
if DEBUGGING: |
| 27 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 28 |
else: |
| 29 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 30 |
|
| 31 |
|
| 32 |
@pytest.mark.skipif(get_default_db_lib() != "mdb", reason="Not supported over bdb") |
| 33 |
def test_memberof_deferred_update_lmdb_rejection(topo): |
| 34 |
"""Test that memberOf plugin rejects deferred update configuration with LMDB backend |
| 35 |
|
| 36 |
:id: a7f079dd-d269-41ca-95ec-91428e77626f |
| 37 |
:setup: Standalone Instance with LMDB backend |
| 38 |
:steps: |
| 39 |
1. Enable memberOf plugin |
| 40 |
2. Try to set deferred_update to "on" |
| 41 |
3. Check error log for appropriate error message |
| 42 |
:expectedresults: |
| 43 |
1. Plugin enables successfully |
| 44 |
2. Setting deferred_update fails |
| 45 |
3. Error log contains "deferred_update is not supported with LMDB backend" |
| 46 |
""" |
| 47 |
|
| 48 |
inst = topo.standalone |
| 49 |
|
| 50 |
# Enable memberOf plugin |
| 51 |
log.info("Step 1: Enabling memberOf plugin") |
| 52 |
memberof_plugin = MemberOfPlugin(inst) |
| 53 |
memberof_plugin.enable() |
| 54 |
log.info("✓ MemberOf plugin enabled") |
| 55 |
inst.deleteErrorLogs(restart=True) |
| 56 |
|
| 57 |
# Try to set deferred_update to "on" |
| 58 |
log.info("Step 2: Attempting to set deferred_update to 'on'") |
| 59 |
|
| 60 |
# Try to modify the plugin configuration |
| 61 |
plugin_dn = f"cn={PLUGIN_MEMBER_OF},cn=plugins,cn=config" |
| 62 |
memberof_plugin.set_memberofdeferredupdate('on') |
| 63 |
|
| 64 |
# Check error log for appropriate error message |
| 65 |
log.info("Step 3: Checking error log for LMDB-specific error message") |
| 66 |
assert inst.ds_error_log.match(".*deferred_update is not supported with LMDB backend.*") |
| 67 |
|
| 68 |
log.info("✓ Test completed successfully - memberOf plugin correctly rejects deferred update with LMDB backend") |
| 69 |
|
| 70 |
|
| 71 |
@pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not supported over mdb") |
| 72 |
def test_memberof_deferred_update_non_lmdb_success(topo): |
| 73 |
"""Test that memberOf plugin allows deferred update configuration with non-LMDB backends |
| 74 |
|
| 75 |
:id: a4b640c8-ef54-4cbf-8d1a-8b29fcdd59d1 |
| 76 |
:setup: Standalone Instance with non-LMDB backend (BDB) |
| 77 |
:steps: |
| 78 |
1. Enable memberOf plugin |
| 79 |
2. Set deferred_update to "on" |
| 80 |
3. Verify the operation succeeds |
| 81 |
4. Verify deferred_update remains "on" |
| 82 |
:expectedresults: |
| 83 |
1. Plugin enables successfully |
| 84 |
2. Setting deferred_update succeeds |
| 85 |
3. No error occurs |
| 86 |
4. deferred_update is "on" |
| 87 |
""" |
| 88 |
|
| 89 |
inst = topo.standalone |
| 90 |
|
| 91 |
# Enable memberOf plugin |
| 92 |
log.info("Step 1: Enabling memberOf plugin") |
| 93 |
memberof_plugin = MemberOfPlugin(inst) |
| 94 |
memberof_plugin.enable() |
| 95 |
log.info("✓ MemberOf plugin enabled") |
| 96 |
inst.deleteErrorLogs(restart=True) |
| 97 |
|
| 98 |
# Set deferred_update to "on" |
| 99 |
log.info("Step 2: Setting deferred_update to 'on'") |
| 100 |
|
| 101 |
# Try to modify the plugin configuration |
| 102 |
try: |
| 103 |
memberof_plugin.set_memberofdeferredupdate('on') |
| 104 |
log.info("✓ Successfully set deferred_update to 'on'") |
| 105 |
except Exception as e: |
| 106 |
assert False, f"Expected success when setting deferred_update with non-LMDB backend, got: {type(e).__name__}: {e}" |
| 107 |
|
| 108 |
# Verify no error occurred |
| 109 |
log.info("Step 3: Verifying no error occurred") |
| 110 |
assert not inst.ds_error_log.match(".*deferred_update is not supported with LMDB backend.*") |
| 111 |
|
| 112 |
log.info("✓ No LMDB-related error messages found") |
| 113 |
|
| 114 |
# Verify deferred_update remains "on" |
| 115 |
log.info("Step 4: Verifying deferred_update is 'on'") |
| 116 |
current_deferred = memberof_plugin.get_memberofdeferredupdate() |
| 117 |
assert current_deferred is None or current_deferred.lower() == 'on', \ |
| 118 |
f"Expected deferred_update to be 'on', got: {current_deferred}" |
| 119 |
log.info("✓ deferred_update is 'on'") |
| 120 |
|
| 121 |
log.info("✓ Test completed successfully - memberOf plugin correctly allows deferred update with non-LMDB backend") |
| 122 |
|
| 123 |
|
| 124 |
if __name__ == '__main__': |
| 125 |
# Run isolated |
| 126 |
# -s for DEBUG mode |
| 127 |
CURRENT_FILE = os.path.realpath(__file__) |
| 128 |
pytest.main(["-s", CURRENT_FILE]) |
| 129 |
|