| 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 logging |
| 10 |
import time |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
from lib389._constants import PW_DM, DEFAULT_SUFFIX |
| 14 |
from lib389.idm.organization import Organization |
| 15 |
from test389.topologies import topology_m1c1 as topo |
| 16 |
from lib389.idm.role import FilteredRoles, ManagedRoles |
| 17 |
from lib389.cos import CosClassicDefinition, CosClassicDefinitions, CosTemplate |
| 18 |
from lib389.replica import ReplicationManager |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
pytestmark = pytest.mark.tier1 |
| 24 |
|
| 25 |
DNBASE = "o=acivattr,{}".format(DEFAULT_SUFFIX) |
| 26 |
|
| 27 |
|
| 28 |
@pytest.fixture(scope="function") |
| 29 |
def reset_ignore_vattr(topo, request): |
| 30 |
s = topo.ms['supplier1'] |
| 31 |
c = topo.cs['consumer1'] |
| 32 |
default_ignore_vattr_value = s.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') |
| 33 |
default_ignore_vattr_value = c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') |
| 34 |
|
| 35 |
def fin(): |
| 36 |
s.config.set('nsslapd-ignore-virtual-attrs', default_ignore_vattr_value) |
| 37 |
c.config.set('nsslapd-ignore-virtual-attrs', default_ignore_vattr_value) |
| 38 |
|
| 39 |
request.addfinalizer(fin) |
| 40 |
|
| 41 |
def test_vattr_on_cos_definition_with_replication(topo, reset_ignore_vattr): |
| 42 |
"""Test nsslapd-ignore-virtual-attrs configuration attribute |
| 43 |
The attribute is ON by default. If a cos definition is |
| 44 |
added it is moved to OFF in replication scenario |
| 45 |
|
| 46 |
:id: c1fd8fa1-bd13-478b-9b33-e33b49c587bd |
| 47 |
:customerscenario: True |
| 48 |
:setup: Supplier Consumer |
| 49 |
:steps: |
| 50 |
1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config over consumer |
| 51 |
2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON over consumer |
| 52 |
3. Create a cos definition for employeeType in supplier |
| 53 |
4. Check the value of nsslapd-ignore-virtual-attrs should be OFF (with a delay for postop processing) over consumer |
| 54 |
5. Check a message "slapi_vattrspi_regattr - Because employeeType,.." in error logs of consumer |
| 55 |
6. Check after deleting cos definition value of attribute nsslapd-ignore-virtual-attrs is set back to ON over consumer |
| 56 |
:expectedresults: |
| 57 |
1. This should be successful |
| 58 |
2. This should be successful |
| 59 |
3. This should be successful |
| 60 |
4. This should be successful |
| 61 |
5. This should be successful |
| 62 |
6. This should be successful |
| 63 |
""" |
| 64 |
s = topo.ms['supplier1'] |
| 65 |
c = topo.cs['consumer1'] |
| 66 |
log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config over consumer") |
| 67 |
assert c.config.present('nsslapd-ignore-virtual-attrs') |
| 68 |
|
| 69 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON over consumer") |
| 70 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 71 |
|
| 72 |
# creating CosClassicDefinition in supplier |
| 73 |
log.info("Create a cos definition") |
| 74 |
properties = {'cosTemplateDn': 'cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,{}'.format(DEFAULT_SUFFIX), |
| 75 |
'cosAttribute': 'employeeType', |
| 76 |
'cosSpecifier': 'nsrole', |
| 77 |
'cn': 'cosClassicGenerateEmployeeTypeUsingnsrole'} |
| 78 |
cosdef = CosClassicDefinition(s,'cn=cosClassicGenerateEmployeeTypeUsingnsrole,{}'.format(DEFAULT_SUFFIX))\ |
| 79 |
.create(properties=properties) |
| 80 |
|
| 81 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs is OFF over consumer") |
| 82 |
time.sleep(2) |
| 83 |
assert c.config.present('nsslapd-ignore-virtual-attrs', 'off') |
| 84 |
|
| 85 |
#stop both supplier and consumer |
| 86 |
c.stop() |
| 87 |
assert c.searchErrorsLog("slapi_vattrspi_regattr - Because employeeType is a new registered virtual attribute , nsslapd-ignore-virtual-attrs was set to \'off\'") |
| 88 |
c.start() |
| 89 |
log.info("Delete a cos definition") |
| 90 |
cosdef.delete() |
| 91 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 92 |
log.info("Check Delete was propagated") |
| 93 |
repl.wait_for_replication(s, c) |
| 94 |
|
| 95 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs is back to ON over consumer") |
| 96 |
s.restart() |
| 97 |
c.restart() |
| 98 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 99 |
|
| 100 |
def test_vattr_on_filtered_role_with_replication(topo, request): |
| 101 |
"""Test nsslapd-ignore-virtual-attrs configuration attribute |
| 102 |
The attribute is ON by default. If a filtered role is |
| 103 |
added it is moved to OFF in replication scenario |
| 104 |
|
| 105 |
:id: 7b29be88-c8ca-409b-bbb7-ce3962f73f91 |
| 106 |
:customerscenario: True |
| 107 |
:setup: Supplier Consumer |
| 108 |
:steps: |
| 109 |
1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config over consumer |
| 110 |
2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON over consumer |
| 111 |
3. Create a filtered role in supplier |
| 112 |
4. Check the value of nsslapd-ignore-virtual-attrs should be OFF over consumer |
| 113 |
5. Check a message "roles_cache_trigger_update_role - Because of virtual attribute.." in error logs of consumer |
| 114 |
6. Check after deleting role definition value of attribute nsslapd-ignore-virtual-attrs is set back to ON over consumer |
| 115 |
:expectedresults: |
| 116 |
1. This should be successful |
| 117 |
2. This should be successful |
| 118 |
3. This should be successful |
| 119 |
4. This should be successful |
| 120 |
5. This should be successful |
| 121 |
6. This should be successful |
| 122 |
""" |
| 123 |
s = topo.ms['supplier1'] |
| 124 |
c = topo.cs['consumer1'] |
| 125 |
|
| 126 |
log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config over consumer") |
| 127 |
assert c.config.present('nsslapd-ignore-virtual-attrs') |
| 128 |
|
| 129 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON over consumer") |
| 130 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 131 |
|
| 132 |
log.info("Create a filtered role") |
| 133 |
try: |
| 134 |
Organization(s).create(properties={"o": "acivattr"}, basedn=DEFAULT_SUFFIX) |
| 135 |
except: |
| 136 |
pass |
| 137 |
roles = FilteredRoles(s, DNBASE) |
| 138 |
roles.create(properties={'cn': 'FILTERROLEENGROLE', 'nsRoleFilter': 'cn=eng*'}) |
| 139 |
|
| 140 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be OFF over consumer") |
| 141 |
time.sleep(5) |
| 142 |
assert c.config.present('nsslapd-ignore-virtual-attrs', 'off') |
| 143 |
|
| 144 |
c.stop() |
| 145 |
assert c.searchErrorsLog("roles_cache_trigger_update_role - Because of virtual attribute definition \(role\), nsslapd-ignore-virtual-attrs was set to \'off\'") |
| 146 |
|
| 147 |
def fin(): |
| 148 |
s.restart() |
| 149 |
c.restart() |
| 150 |
try: |
| 151 |
filtered_roles = FilteredRoles(s, DEFAULT_SUFFIX) |
| 152 |
for i in filtered_roles.list(): |
| 153 |
i.delete() |
| 154 |
except: |
| 155 |
pass |
| 156 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs is back to ON over consumer") |
| 157 |
s.restart() |
| 158 |
c.restart() |
| 159 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 160 |
|
| 161 |
request.addfinalizer(fin) |
| 162 |
|
| 163 |
def test_vattr_on_managed_role_replication(topo, request): |
| 164 |
"""Test nsslapd-ignore-virtual-attrs configuration attribute |
| 165 |
The attribute is ON by default. If a managed role is |
| 166 |
added it is moved to OFF in replcation scenario |
| 167 |
|
| 168 |
:id: 446f2fc3-bbb2-4835-b14a-cb855db78c6f |
| 169 |
:customerscenario: True |
| 170 |
:setup: Supplier Consumer |
| 171 |
:steps: |
| 172 |
1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config over consumer |
| 173 |
2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON over consumer |
| 174 |
3. Create a managed role in supplier |
| 175 |
4. Check the value of nsslapd-ignore-virtual-attrs should be OFF over consumer |
| 176 |
5. Check a message "roles_cache_trigger_update_role - Because of virtual attribute.." in error logs of consumer |
| 177 |
6. Check after deleting role definition value of attribute nsslapd-ignore-virtual-attrs is set back to ON over consumer |
| 178 |
:expectedresults: |
| 179 |
1. This should be successful |
| 180 |
2. This should be successful |
| 181 |
3. This should be successful |
| 182 |
4. This should be successful |
| 183 |
5. This should be successful |
| 184 |
6. This should be successful |
| 185 |
""" |
| 186 |
s = topo.ms['supplier1'] |
| 187 |
c = topo.cs['consumer1'] |
| 188 |
log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config") |
| 189 |
assert c.config.present('nsslapd-ignore-virtual-attrs') |
| 190 |
|
| 191 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON") |
| 192 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 193 |
|
| 194 |
log.info("Create a managed role") |
| 195 |
roles = ManagedRoles(s, DEFAULT_SUFFIX) |
| 196 |
role = roles.create(properties={"cn": 'ROLE1'}) |
| 197 |
|
| 198 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be OFF") |
| 199 |
time.sleep(5) |
| 200 |
assert c.config.present('nsslapd-ignore-virtual-attrs', 'off') |
| 201 |
|
| 202 |
c.stop() |
| 203 |
assert c.searchErrorsLog("roles_cache_trigger_update_role - Because of virtual attribute definition \(role\), nsslapd-ignore-virtual-attrs was set to \'off\'") |
| 204 |
|
| 205 |
def fin(): |
| 206 |
s.restart() |
| 207 |
c.restart() |
| 208 |
try: |
| 209 |
filtered_roles = ManagedRoles(s, DEFAULT_SUFFIX) |
| 210 |
for i in filtered_roles.list(): |
| 211 |
i.delete() |
| 212 |
except: |
| 213 |
pass |
| 214 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs is back to ON") |
| 215 |
s.restart() |
| 216 |
c.restart() |
| 217 |
assert c.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 218 |
|
| 219 |
request.addfinalizer(fin) |
| 220 |
|
| 221 |
if __name__ == "__main__": |
| 222 |
CURRENT_FILE = os.path.realpath(__file__) |
| 223 |
pytest.main("-s -v %s" % CURRENT_FILE) |