| 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 |
import logging |
| 10 |
import json |
| 11 |
import os |
| 12 |
import subprocess |
| 13 |
import pytest |
| 14 |
from test389.topologies import topology_st as topo |
| 15 |
|
| 16 |
log = logging.getLogger(__name__) |
| 17 |
|
| 18 |
|
| 19 |
def execute_dsconf_command(dsconf_cmd, subcommands): |
| 20 |
"""Execute dsconf command and return output and return code""" |
| 21 |
|
| 22 |
cmdline = dsconf_cmd + subcommands |
| 23 |
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE) |
| 24 |
out, _ = proc.communicate() |
| 25 |
return out.decode('utf-8'), proc.returncode |
| 26 |
|
| 27 |
|
| 28 |
def get_dsconf_base_cmd(topo): |
| 29 |
"""Return base dsconf command list""" |
| 30 |
return ['/usr/sbin/dsconf', topo.standalone.serverid, |
| 31 |
'-j', 'schema'] |
| 32 |
|
| 33 |
|
| 34 |
def test_schema_oc_superior(topo): |
| 35 |
"""Specify a test case purpose or name here |
| 36 |
|
| 37 |
:id: d12aab4a-1436-43eb-802a-0661281a13d0 |
| 38 |
:setup: Standalone Instance |
| 39 |
:steps: |
| 40 |
1. List all the schema |
| 41 |
2. List all the schema and include superior OC's attrs |
| 42 |
3. Get objectclass list |
| 43 |
4. Get objectclass list and include superior OC's attrs |
| 44 |
5. Get objectclass |
| 45 |
6. Get objectclass and include superior OC's attrs |
| 46 |
:expectedresults: |
| 47 |
1. Success |
| 48 |
2. Success |
| 49 |
3. Success |
| 50 |
4. Success |
| 51 |
""" |
| 52 |
|
| 53 |
dsconf_cmd = get_dsconf_base_cmd(topo) |
| 54 |
|
| 55 |
# Test default schema list |
| 56 |
output, rc = execute_dsconf_command(dsconf_cmd, ['list']) |
| 57 |
assert rc == 0 |
| 58 |
json_result = json.loads(output) |
| 59 |
for schema_item in json_result: |
| 60 |
if 'name' in schema_item and schema_item['name'] == 'inetOrgPerson': |
| 61 |
assert len(schema_item['must']) == 0 |
| 62 |
break |
| 63 |
|
| 64 |
# Test including the OC superior attributes |
| 65 |
output, rc = execute_dsconf_command(dsconf_cmd, ['list', |
| 66 |
'--include-oc-sup']) |
| 67 |
assert rc == 0 |
| 68 |
json_result = json.loads(output) |
| 69 |
for schema_item in json_result: |
| 70 |
if 'name' in schema_item and schema_item['name'] == 'inetOrgPerson': |
| 71 |
assert len(schema_item['must']) > 0 and \ |
| 72 |
'cn' in schema_item['must'] and 'sn' in schema_item['must'] |
| 73 |
break |
| 74 |
|
| 75 |
# Test default objectclass list |
| 76 |
output, rc = execute_dsconf_command(dsconf_cmd, ['objectclasses', 'list']) |
| 77 |
assert rc == 0 |
| 78 |
json_result = json.loads(output) |
| 79 |
for schema_item in json_result: |
| 80 |
if 'name' in schema_item and schema_item['name'] == 'inetOrgPerson': |
| 81 |
assert len(schema_item['must']) == 0 |
| 82 |
break |
| 83 |
|
| 84 |
# Test objectclass list and inslude superior attributes |
| 85 |
output, rc = execute_dsconf_command(dsconf_cmd, ['objectclasses', 'list', |
| 86 |
'--include-sup']) |
| 87 |
assert rc == 0 |
| 88 |
json_result = json.loads(output) |
| 89 |
for schema_item in json_result: |
| 90 |
if 'name' in schema_item and schema_item['name'] == 'inetOrgPerson': |
| 91 |
assert len(schema_item['must']) > 0 and \ |
| 92 |
'cn' in schema_item['must'] and 'sn' in schema_item['must'] |
| 93 |
break |
| 94 |
|
| 95 |
# Test default objectclass query |
| 96 |
output, rc = execute_dsconf_command(dsconf_cmd, ['objectclasses', 'query', |
| 97 |
'inetOrgPerson']) |
| 98 |
assert rc == 0 |
| 99 |
result = json.loads(output) |
| 100 |
schema_item = result['oc'] |
| 101 |
assert 'names' in schema_item |
| 102 |
assert schema_item['names'][0] == 'inetOrgPerson' |
| 103 |
assert len(schema_item['must']) == 0 |
| 104 |
|
| 105 |
# Test objectclass query and include superior attributes |
| 106 |
output, rc = execute_dsconf_command(dsconf_cmd, ['objectclasses', 'query', |
| 107 |
'inetOrgPerson', |
| 108 |
'--include-sup']) |
| 109 |
assert rc == 0 |
| 110 |
result = json.loads(output) |
| 111 |
schema_item = result['oc'] |
| 112 |
assert 'names' in schema_item |
| 113 |
assert schema_item['names'][0] == 'inetOrgPerson' |
| 114 |
assert len(schema_item['must']) > 0 and 'cn' in schema_item['must'] \ |
| 115 |
and 'sn' in schema_item['must'] |
| 116 |
|
| 117 |
|
| 118 |
if __name__ == '__main__': |
| 119 |
# Run isolated |
| 120 |
# -s for DEBUG mode |
| 121 |
CURRENT_FILE = os.path.realpath(__file__) |
| 122 |
pytest.main(["-s", CURRENT_FILE]) |