| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 |
"""Test dsconf CLI with MemberOf plugin configuration""" |
| 10 |
|
| 11 |
import json |
| 12 |
import subprocess |
| 13 |
import logging |
| 14 |
import pytest |
| 15 |
from lib389._constants import DN_DM |
| 16 |
from test389.topologies import topology_st as topo |
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier1 |
| 19 |
|
| 20 |
log = logging.getLogger(__name__) |
| 21 |
|
| 22 |
# MemberOf plugin configuration options to test |
| 23 |
MEMBEROF_SETTINGS = [ |
| 24 |
# ('attr', 'memberOf'), Already set by default |
| 25 |
('groupattr', ['member', 'uniquemember']), |
| 26 |
('allbackends', 'on'), |
| 27 |
('allbackends', 'off'), |
| 28 |
('skipnested', 'on'), |
| 29 |
('skipnested', 'off'), |
| 30 |
('scope', ['dc=example,dc=com', 'ou=groups,dc=example,dc=com']), |
| 31 |
('exclude', ['ou=excluded,dc=example,dc=com']), |
| 32 |
('autoaddoc', 'inetuser'), |
| 33 |
('deferredupdate', 'on'), |
| 34 |
('deferredupdate', 'off'), |
| 35 |
('launchfixup', 'on'), |
| 36 |
('launchfixup', 'off'), |
| 37 |
('specific-group-oc', 'groupofnames'), |
| 38 |
] |
| 39 |
|
| 40 |
# Config entry specific settings |
| 41 |
CONFIG_ENTRY_SETTINGS = [ |
| 42 |
('attr', 'memberOf'), |
| 43 |
('groupattr', ['member', 'uniquemember']), |
| 44 |
('allbackends', 'on'), |
| 45 |
('skipnested', 'on'), |
| 46 |
('scope', ['dc=example,dc=com']), |
| 47 |
('exclude', ['ou=excluded,dc=example,dc=com']), |
| 48 |
('autoaddoc', 'inetuser'), |
| 49 |
('specific-group-oc', 'groupofnames'), |
| 50 |
] |
| 51 |
|
| 52 |
MEMBEROF_ATTR_SETTINGS = [ |
| 53 |
('specific-group-filter', '(entrydn=cn=group1,ou=groups,dc=example,dc=com)'), |
| 54 |
('exclude-specific-group-filter', '(entrydn=cn=excluded,ou=groups,dc=example,dc=com)'), |
| 55 |
] |
| 56 |
|
| 57 |
|
| 58 |
def execute_dsconf_command(dsconf_cmd, subcommands): |
| 59 |
"""Execute dsconf command and return output and return code""" |
| 60 |
|
| 61 |
cmdline = dsconf_cmd + subcommands |
| 62 |
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 63 |
out, err = proc.communicate() |
| 64 |
|
| 65 |
if proc.returncode != 0 and err: |
| 66 |
log.error(f"Command failed: {' '.join(cmdline)}") |
| 67 |
log.error(f"Stderr: {err.decode('utf-8')}") |
| 68 |
|
| 69 |
return out.decode('utf-8'), proc.returncode |
| 70 |
|
| 71 |
|
| 72 |
def get_dsconf_base_cmd(topo): |
| 73 |
"""Return base dsconf command list""" |
| 74 |
return ['/usr/sbin/dsconf', topo.standalone.serverid, |
| 75 |
'-j', '-D', DN_DM, '-w', 'password', 'plugin', 'memberof'] |
| 76 |
|
| 77 |
|
| 78 |
def test_memberof_plugin_status(topo): |
| 79 |
"""Test memberof plugin status and basic operations |
| 80 |
|
| 81 |
:id: memberof-status-test |
| 82 |
:setup: Standalone DS instance |
| 83 |
:steps: |
| 84 |
1. Check plugin status |
| 85 |
2. Enable plugin if needed |
| 86 |
3. Verify plugin is enabled |
| 87 |
:expectedresults: |
| 88 |
1. Success |
| 89 |
2. Success |
| 90 |
3. Success |
| 91 |
""" |
| 92 |
|
| 93 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 94 |
|
| 95 |
# Check plugin status |
| 96 |
output, rc = execute_dsconf_command(dsconf_cmd, ['status']) |
| 97 |
assert rc == 0 |
| 98 |
log.info(f"Plugin status: {output}") |
| 99 |
|
| 100 |
# Enable plugin if not already enabled |
| 101 |
output, rc = execute_dsconf_command(dsconf_cmd, ['enable']) |
| 102 |
assert rc == 0 |
| 103 |
log.info(f"Plugin enable result: {output}") |
| 104 |
|
| 105 |
# Verify plugin is enabled |
| 106 |
output, rc = execute_dsconf_command(dsconf_cmd, ['status']) |
| 107 |
assert rc == 0 |
| 108 |
json_result = json.loads(output) |
| 109 |
assert json_result.get('msg') == 'enabled' |
| 110 |
|
| 111 |
|
| 112 |
def test_memberof_plugin_get(topo): |
| 113 |
"""Test memberof plugin get command |
| 114 |
|
| 115 |
:id: memberof-get-test |
| 116 |
:setup: Standalone DS instance |
| 117 |
:steps: |
| 118 |
1. Get plugin configuration |
| 119 |
:expectedresults: |
| 120 |
1. Success |
| 121 |
""" |
| 122 |
|
| 123 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 124 |
|
| 125 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 126 |
assert rc == 0 |
| 127 |
log.info(f"Plugin configuration: {output}") |
| 128 |
|
| 129 |
# Parse JSON output to verify structure |
| 130 |
json_result = json.loads(output) |
| 131 |
assert json_result.get('type') == 'entry' |
| 132 |
|
| 133 |
|
| 134 |
@pytest.mark.parametrize("attr,value", MEMBEROF_SETTINGS) |
| 135 |
def test_memberof_plugin_set(topo, attr, value): |
| 136 |
"""Test memberof plugin set command with various configuration options |
| 137 |
|
| 138 |
:id: memberof-set-test |
| 139 |
:setup: Standalone DS instance |
| 140 |
:steps: |
| 141 |
1. Set various memberof plugin configuration options |
| 142 |
2. Verify the setting was applied |
| 143 |
3. Reset to default values |
| 144 |
:expectedresults: |
| 145 |
1. Success |
| 146 |
2. Success |
| 147 |
3. Success |
| 148 |
""" |
| 149 |
|
| 150 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 151 |
|
| 152 |
# Build the set command |
| 153 |
set_cmd = ['set', f'--{attr}'] |
| 154 |
if isinstance(value, list): |
| 155 |
set_cmd.extend(value) |
| 156 |
else: |
| 157 |
set_cmd.append(value) |
| 158 |
|
| 159 |
# Set the configuration |
| 160 |
output, rc = execute_dsconf_command(dsconf_cmd, set_cmd) |
| 161 |
assert rc == 0, f"Failed to set {attr}={value}: {output}" |
| 162 |
log.info(f"Set {attr}={value} successfully") |
| 163 |
|
| 164 |
# Verify the setting was applied by getting the configuration |
| 165 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 166 |
assert rc == 0 |
| 167 |
json_result = json.loads(output) |
| 168 |
|
| 169 |
# Check if the attribute was set correctly |
| 170 |
if attr == 'groupattr' and isinstance(value, list): |
| 171 |
# For multi-valued attributes, check if all values are present |
| 172 |
config_value = json_result['attrs']['memberofgroupattr'] |
| 173 |
if isinstance(config_value, str): |
| 174 |
config_value = [config_value] |
| 175 |
for val in value: |
| 176 |
assert val in config_value, f"Expected {val} in {config_value}" |
| 177 |
elif attr in ['scope', 'exclude'] and isinstance(value, list): |
| 178 |
# For multi-valued attributes |
| 179 |
config_attr = f'memberof{attr.title().replace("-", "")}' |
| 180 |
if attr == 'scope': |
| 181 |
config_attr = 'memberofentryscope' |
| 182 |
elif attr == 'exclude': |
| 183 |
config_attr = 'memberofentryscopeexcludesubtree' |
| 184 |
|
| 185 |
config_value = json_result['attrs'][config_attr] |
| 186 |
if isinstance(config_value, str): |
| 187 |
config_value = [config_value] |
| 188 |
for val in value: |
| 189 |
assert val in config_value, f"Expected {val} in {config_value}" |
| 190 |
else: |
| 191 |
# For single-valued attributes |
| 192 |
config_attr = f'memberof{attr.title().replace("-", "")}' |
| 193 |
if attr == 'attr': |
| 194 |
config_attr = 'memberofattr' |
| 195 |
elif attr == 'groupattr': |
| 196 |
config_attr = 'memberofgroupattr' |
| 197 |
elif attr == 'allbackends': |
| 198 |
config_attr = 'memberofallbackends' |
| 199 |
elif attr == 'skipnested': |
| 200 |
config_attr = 'memberofskipnested' |
| 201 |
elif attr == 'autoaddoc': |
| 202 |
config_attr = 'memberofautoaddoc' |
| 203 |
elif attr == 'deferredupdate': |
| 204 |
config_attr = 'memberofdeferredupdate' |
| 205 |
elif attr == 'launchfixup': |
| 206 |
config_attr = 'memberoflaunchfixup' |
| 207 |
elif attr == 'specific-group-oc': |
| 208 |
config_attr = 'memberofspecificgroupoc' |
| 209 |
|
| 210 |
if config_attr not in json_result['attrs']: |
| 211 |
config_value = "" |
| 212 |
else: |
| 213 |
config_value = json_result['attrs'][config_attr][0].lower() |
| 214 |
if attr in ['allbackends', 'skipnested', 'deferredupdate', 'launchfixup']: |
| 215 |
expected_value = 'on' if value == 'on' else 'off' |
| 216 |
assert config_value == expected_value, f"Expected {expected_value}, got {config_value}" |
| 217 |
else: |
| 218 |
assert config_value == value.lower(), f"Expected {value}, got {config_value}" |
| 219 |
|
| 220 |
# Reset to default values (delete the attribute) |
| 221 |
reset_cmd = ['set', f'--{attr}', 'delete'] |
| 222 |
|
| 223 |
output, rc = execute_dsconf_command(dsconf_cmd, reset_cmd) |
| 224 |
# Some attributes might not be deletable, so we don't assert on return code |
| 225 |
log.info(f"Reset {attr}: {output}") |
| 226 |
|
| 227 |
|
| 228 |
@pytest.mark.parametrize("attr,value", MEMBEROF_ATTR_SETTINGS) |
| 229 |
def test_memberof_plugin_add_del_attr(topo, attr, value): |
| 230 |
"""Test memberof plugin add-attr/del-attr command with various |
| 231 |
configuration options |
| 232 |
|
| 233 |
:id: 8b3a2d38-e8ec-4b1e-8d45-ba86fbf0360c |
| 234 |
:setup: Standalone DS instance |
| 235 |
:steps: |
| 236 |
1. Add various memberof plugin attributes |
| 237 |
:expectedresults: |
| 238 |
1. Success |
| 239 |
""" |
| 240 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 241 |
|
| 242 |
# Build the set command |
| 243 |
add_cmd = ['add-attr', f'--{attr}', value] |
| 244 |
|
| 245 |
# Set the configuration |
| 246 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 247 |
assert rc == 0, f"Failed to add {attr}={value}: {output}" |
| 248 |
log.info(f"Set {attr}={value} successfully") |
| 249 |
|
| 250 |
# Verify the setting was applied by getting the configuration |
| 251 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 252 |
assert rc == 0 |
| 253 |
json_result = json.loads(output) |
| 254 |
config_attr = f'memberof{attr.replace("-", "")}' |
| 255 |
config_value = json_result['attrs'][config_attr][0] |
| 256 |
assert config_value == value, f"Expected {value} in {config_value}" |
| 257 |
|
| 258 |
# Now delete the attributes |
| 259 |
delete_cmd = ['del-attr', f'--{attr}', value] |
| 260 |
output, rc = execute_dsconf_command(dsconf_cmd, delete_cmd) |
| 261 |
assert rc == 0, f"Failed to delete {attr}={value}: {output}" |
| 262 |
log.info(f"Deleted {attr}={value} successfully") |
| 263 |
|
| 264 |
# Verify the setting was applied by getting the configuration |
| 265 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 266 |
assert rc == 0 |
| 267 |
json_result = json.loads(output) |
| 268 |
config_dict= json_result['attrs'] |
| 269 |
assert config_attr not in config_dict, f"Expected {config_attr} not to be present" |
| 270 |
|
| 271 |
|
| 272 |
def test_memberof_config_entry_operations(topo): |
| 273 |
"""Test memberof config-entry operations |
| 274 |
|
| 275 |
:id: memberof-config-entry-test |
| 276 |
:setup: Standalone DS instance |
| 277 |
:steps: |
| 278 |
1. Add a config entry |
| 279 |
2. Show the config entry |
| 280 |
3. Edit the config entry |
| 281 |
4. Delete the config entry |
| 282 |
:expectedresults: |
| 283 |
1. Success |
| 284 |
2. Success |
| 285 |
3. Success |
| 286 |
4. Success |
| 287 |
""" |
| 288 |
|
| 289 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 290 |
config_dn = 'cn=test-config,cn=memberof plugin,cn=plugins,cn=config' |
| 291 |
|
| 292 |
# Add config entry |
| 293 |
add_cmd = ['config-entry', 'add', config_dn, '--attr', 'memberOf', '--groupattr', 'member'] |
| 294 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 295 |
assert rc == 0, f"Failed to add config entry: {output}" |
| 296 |
log.info(f"Added config entry: {output}") |
| 297 |
|
| 298 |
# Show config entry |
| 299 |
show_cmd = ['config-entry', 'show', config_dn] |
| 300 |
output, rc = execute_dsconf_command(dsconf_cmd, show_cmd) |
| 301 |
assert rc == 0, f"Failed to show config entry: {output}" |
| 302 |
log.info(f"Config entry details: {output}") |
| 303 |
|
| 304 |
# Edit config entry |
| 305 |
edit_cmd = ['config-entry', 'set', config_dn, '--attr', 'memberOf', '--groupattr', 'uniqueMember'] |
| 306 |
output, rc = execute_dsconf_command(dsconf_cmd, edit_cmd) |
| 307 |
assert rc == 0, f"Failed to edit config entry: {output}" |
| 308 |
log.info(f"Edited config entry: {output}") |
| 309 |
|
| 310 |
# Show config entry again to verify changes |
| 311 |
output, rc = execute_dsconf_command(dsconf_cmd, show_cmd) |
| 312 |
assert rc == 0, f"Failed to show updated config entry: {output}" |
| 313 |
json_result = json.loads(output) |
| 314 |
assert json_result['attrs']['memberofgroupattr'][0] == 'uniqueMember' |
| 315 |
|
| 316 |
# Delete config entry |
| 317 |
delete_cmd = ['config-entry', 'delete', config_dn] |
| 318 |
output, rc = execute_dsconf_command(dsconf_cmd, delete_cmd) |
| 319 |
assert rc == 0, f"Failed to delete config entry: {output}" |
| 320 |
log.info(f"Deleted config entry: {output}") |
| 321 |
|
| 322 |
|
| 323 |
@pytest.mark.parametrize("attr,value", CONFIG_ENTRY_SETTINGS) |
| 324 |
def test_memberof_config_entry_set(topo, attr, value): |
| 325 |
"""Test memberof config-entry set command with various configuration options |
| 326 |
|
| 327 |
:id: memberof-config-entry-set-test |
| 328 |
:setup: Standalone DS instance |
| 329 |
:steps: |
| 330 |
1. Add a config entry with specific settings |
| 331 |
2. Verify the settings were applied |
| 332 |
3. Delete the config entry |
| 333 |
:expectedresults: |
| 334 |
1. Success |
| 335 |
2. Success |
| 336 |
3. Success |
| 337 |
""" |
| 338 |
|
| 339 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 340 |
config_dn = f'cn=test-config-{attr},cn=memberof plugin,cn=plugins,cn=config' |
| 341 |
|
| 342 |
# Build the add command |
| 343 |
add_cmd = ['config-entry', 'add', config_dn, '--attr', 'memberOf'] |
| 344 |
if attr != 'groupattr': |
| 345 |
add_cmd.extend(['--groupattr', 'memberof'] ) |
| 346 |
|
| 347 |
if isinstance(value, list): |
| 348 |
add_cmd.extend([f'--{attr}'] + value) |
| 349 |
else: |
| 350 |
add_cmd.extend([f'--{attr}', value]) |
| 351 |
|
| 352 |
# Add config entry |
| 353 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 354 |
assert rc == 0, f"Failed to add config entry with {attr}={value}: {output}" |
| 355 |
log.info(f"Added config entry with {attr}={value}") |
| 356 |
|
| 357 |
# Show config entry to verify it worked |
| 358 |
show_cmd = ['config-entry', 'show', config_dn] |
| 359 |
output, rc = execute_dsconf_command(dsconf_cmd, show_cmd) |
| 360 |
assert rc == 0, f"Failed to show config entry: {output}" |
| 361 |
json_result = json.loads(output) |
| 362 |
|
| 363 |
# Verify the setting was applied |
| 364 |
if attr == 'groupattr': |
| 365 |
config_attr = 'memberofgroupattr' |
| 366 |
else: |
| 367 |
config_attr = f'memberof{attr.replace("-", "")}' |
| 368 |
if attr == 'scope': |
| 369 |
config_attr = 'memberofentryscope' |
| 370 |
elif attr == 'exclude': |
| 371 |
config_attr = 'memberofentryscopeexcludesubtree' |
| 372 |
|
| 373 |
config_value = json_result['attrs'][config_attr] |
| 374 |
if isinstance(value, list): |
| 375 |
if isinstance(config_value, str): |
| 376 |
config_value = [config_value] |
| 377 |
for val in value: |
| 378 |
assert val in config_value, f"Expected {val} in {config_value}" |
| 379 |
else: |
| 380 |
assert config_value[0] == value, f"Expected {value}, got {config_value}" |
| 381 |
|
| 382 |
# |
| 383 |
# Finally delete the config entry |
| 384 |
# |
| 385 |
delete_cmd = ['config-entry', 'delete', config_dn] |
| 386 |
output, rc = execute_dsconf_command(dsconf_cmd, delete_cmd) |
| 387 |
assert rc == 0, f"Failed to delete config entry: {output}" |
| 388 |
log.info(f"Deleted config entry: {output}") |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
@pytest.mark.parametrize("attr,value", MEMBEROF_ATTR_SETTINGS) |
| 393 |
def test_memberof_plugin_config_add_del_attr(topo, attr, value): |
| 394 |
"""Test memberof plugin config entry add-attr/del-attr command with various |
| 395 |
configuration options |
| 396 |
|
| 397 |
:id: fa27012e-624e-43cd-8b18-5accd0f090d4 |
| 398 |
:setup: Standalone DS instance |
| 399 |
:steps: |
| 400 |
1. Add various memberof plugin attributes |
| 401 |
:expectedresults: |
| 402 |
1. Success |
| 403 |
""" |
| 404 |
|
| 405 |
# |
| 406 |
# Add config entry |
| 407 |
# |
| 408 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 409 |
config_dn = f'cn=test-config-add-del-{attr},cn=memberof plugin,cn=plugins,cn=config' |
| 410 |
add_cmd = ['config-entry', 'add', config_dn, '--attr', 'memberOf'] |
| 411 |
if attr != 'groupattr': |
| 412 |
add_cmd.extend(['--groupattr', 'memberof'] ) |
| 413 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 414 |
assert rc == 0, f"Failed to add config entry with {attr}={value}: {output}" |
| 415 |
log.info(f"Added config entry with {attr}={value}") |
| 416 |
|
| 417 |
# Show config entry to verify it was added |
| 418 |
show_cmd = ['config-entry', 'show', config_dn] |
| 419 |
output, rc = execute_dsconf_command(dsconf_cmd, show_cmd) |
| 420 |
assert rc == 0, f"Failed to show config entry: {output}" |
| 421 |
json_result = json.loads(output) |
| 422 |
|
| 423 |
# |
| 424 |
# Add the attribute to the config entry |
| 425 |
# |
| 426 |
config_attr = f'memberof{attr.replace("-", "")}' |
| 427 |
set_cmd = ['config-entry', 'add-attr', config_dn, f'--{attr}', value] |
| 428 |
output, rc = execute_dsconf_command(dsconf_cmd, set_cmd) |
| 429 |
assert rc == 0, f"Failed to set {attr}={value}: {output}" |
| 430 |
log.info(f"Set {attr}={value} successfully") |
| 431 |
|
| 432 |
# Verify the setting was applied by getting the configuration |
| 433 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 434 |
assert rc == 0 |
| 435 |
json_result = json.loads(output) |
| 436 |
assert attr not in json_result['attrs'], f"Unexpectedly found {attr} in config entry" |
| 437 |
|
| 438 |
# |
| 439 |
# Now delete the attribute from the config entry |
| 440 |
# |
| 441 |
delete_cmd = ['config-entry', 'del-attr', config_dn, f'--{attr}', value] |
| 442 |
output, rc = execute_dsconf_command(dsconf_cmd, delete_cmd) |
| 443 |
assert rc == 0, f"Failed to delete {attr}={value}: {output}" |
| 444 |
log.info(f"Deleted {attr}={value} successfully") |
| 445 |
|
| 446 |
# Verify the setting was applied by getting the configuration |
| 447 |
output, rc = execute_dsconf_command(dsconf_cmd, ['show']) |
| 448 |
assert rc == 0 |
| 449 |
json_result = json.loads(output) |
| 450 |
config_dict= json_result['attrs'] |
| 451 |
assert config_attr not in config_dict, f"Expected {config_attr} not to be present" |
| 452 |
|
| 453 |
# |
| 454 |
# Finally delete the config entry |
| 455 |
# |
| 456 |
delete_cmd = ['config-entry', 'delete', config_dn] |
| 457 |
output, rc = execute_dsconf_command(dsconf_cmd, delete_cmd) |
| 458 |
assert rc == 0, f"Failed to delete config entry: {output}" |
| 459 |
log.info(f"Deleted config entry: {output}") |
| 460 |
|
| 461 |
|
| 462 |
def test_memberof_fixup_operations(topo): |
| 463 |
"""Test memberof fixup operations |
| 464 |
|
| 465 |
:id: memberof-fixup-test |
| 466 |
:setup: Standalone DS instance |
| 467 |
:steps: |
| 468 |
1. Test fixup command with a base DN |
| 469 |
2. Test fixup-status command |
| 470 |
:expectedresults: |
| 471 |
1. Success |
| 472 |
2. Success |
| 473 |
""" |
| 474 |
|
| 475 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 476 |
base_dn = 'dc=example,dc=com' |
| 477 |
|
| 478 |
# Test fixup command (this will create a task entry) |
| 479 |
fixup_cmd = ['fixup', base_dn] |
| 480 |
output, rc = execute_dsconf_command(dsconf_cmd, fixup_cmd) |
| 481 |
# Fixup might fail if the base DN doesn't exist, which is expected |
| 482 |
log.info(f"Fixup command result: {output}") |
| 483 |
|
| 484 |
# Test fixup-status command |
| 485 |
status_cmd = ['fixup-status'] |
| 486 |
output, rc = execute_dsconf_command(dsconf_cmd, status_cmd) |
| 487 |
# Status command should work even if no tasks exist |
| 488 |
log.info(f"Fixup status: {output}") |
| 489 |
|
| 490 |
|
| 491 |
def test_memberof_invalid_configurations(topo): |
| 492 |
"""Test memberof plugin with invalid configurations |
| 493 |
|
| 494 |
:id: memberof-invalid-config-test |
| 495 |
:setup: Standalone DS instance |
| 496 |
:steps: |
| 497 |
1. Test with invalid attribute values |
| 498 |
2. Test with invalid DN values |
| 499 |
3. Test with missing required parameters |
| 500 |
:expectedresults: |
| 501 |
1. Should fail gracefully |
| 502 |
2. Should fail gracefully |
| 503 |
3. Should fail gracefully |
| 504 |
""" |
| 505 |
|
| 506 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 507 |
|
| 508 |
# Test with invalid attribute value |
| 509 |
output, rc = execute_dsconf_command(dsconf_cmd, ['set', '--attr', '']) |
| 510 |
# This might succeed or fail depending on validation |
| 511 |
log.info(f"Empty attr test: {output}") |
| 512 |
|
| 513 |
# Test with invalid DN in config entry |
| 514 |
invalid_dn = 'invalid-dn-format' |
| 515 |
add_cmd = ['config-entry', 'add', invalid_dn, '--attr', 'memberOf'] |
| 516 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 517 |
# This should fail |
| 518 |
assert rc != 0, f"Expected failure for invalid DN, but got success: {output}" |
| 519 |
log.info(f"Invalid DN test failed as expected: {output}") |
| 520 |
|
| 521 |
# Test with missing required parameters in config entry |
| 522 |
config_dn = 'cn=test-invalid,cn=memberof config,cn=plugins,cn=config' |
| 523 |
add_cmd = ['config-entry', 'add', config_dn] # Missing --attr |
| 524 |
output, rc = execute_dsconf_command(dsconf_cmd, add_cmd) |
| 525 |
# This should fail |
| 526 |
assert rc != 0, f"Expected failure for missing required parameters, but got success: {output}" |
| 527 |
log.info(f"Missing parameters test failed as expected: {output}") |
| 528 |
|
| 529 |
|
| 530 |
def test_memberof_plugin_disable_enable(topo): |
| 531 |
"""Test memberof plugin disable and enable operations |
| 532 |
|
| 533 |
:id: memberof-disable-enable-test |
| 534 |
:setup: Standalone DS instance |
| 535 |
:steps: |
| 536 |
1. Disable the plugin |
| 537 |
2. Verify plugin is disabled |
| 538 |
3. Enable the plugin |
| 539 |
4. Verify plugin is enabled |
| 540 |
:expectedresults: |
| 541 |
1. Success |
| 542 |
2. Success |
| 543 |
3. Success |
| 544 |
4. Success |
| 545 |
""" |
| 546 |
|
| 547 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 548 |
|
| 549 |
# Disable plugin |
| 550 |
output, rc = execute_dsconf_command(dsconf_cmd, ['disable']) |
| 551 |
assert rc == 0, f"Failed to disable plugin: {output}" |
| 552 |
log.info(f"Disabled plugin: {output}") |
| 553 |
|
| 554 |
# Verify plugin is disabled |
| 555 |
output, rc = execute_dsconf_command(dsconf_cmd, ['status']) |
| 556 |
assert rc == 0 |
| 557 |
json_result = json.loads(output) |
| 558 |
assert json_result.get('msg') == 'disabled' |
| 559 |
|
| 560 |
# Enable plugin |
| 561 |
output, rc = execute_dsconf_command(dsconf_cmd, ['enable']) |
| 562 |
assert rc == 0, f"Failed to enable plugin: {output}" |
| 563 |
log.info(f"Enabled plugin: {output}") |
| 564 |
|
| 565 |
# Verify plugin is enabled |
| 566 |
output, rc = execute_dsconf_command(dsconf_cmd, ['status']) |
| 567 |
assert rc == 0 |
| 568 |
json_result = json.loads(output) |
| 569 |
assert json_result.get('msg') == 'enabled' |
| 570 |
|
| 571 |
|
| 572 |
if __name__ == '__main__': |
| 573 |
# Run isolated |
| 574 |
# -s for DEBUG mode |
| 575 |
CURRENT_FILE = os.path.realpath(__file__) |
| 576 |
pytest.main(["-s", CURRENT_FILE]) |