| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022 William Brown <[email protected]> |
| 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 |
|
| 10 |
import pytest |
| 11 |
import time |
| 12 |
from lib389._constants import DEFAULT_SUFFIX |
| 13 |
from test389.topologies import topology_m2 |
| 14 |
|
| 15 |
from lib389.replica import ReplicationManager |
| 16 |
from lib389.idm.group import Groups |
| 17 |
from lib389.idm.user import nsUserAccounts |
| 18 |
from lib389.idm.organizationalunit import OrganizationalUnit as OrganisationalUnit |
| 19 |
|
| 20 |
from lib389.plugins import AutoMembershipPlugin, ReferentialIntegrityPlugin, AutoMembershipDefinitions, MemberOfPlugin |
| 21 |
|
| 22 |
pytestmark = pytest.mark.tier2 |
| 23 |
|
| 24 |
UCOUNT = 400 |
| 25 |
|
| 26 |
def _enable_plugins(inst, group_dn): |
| 27 |
# Enable automember |
| 28 |
amp = AutoMembershipPlugin(inst) |
| 29 |
amp.enable() |
| 30 |
|
| 31 |
# Create the automember definition |
| 32 |
automembers = AutoMembershipDefinitions(inst) |
| 33 |
|
| 34 |
automember = automembers.create(properties={ |
| 35 |
'cn': 'testgroup_definition', |
| 36 |
'autoMemberScope': DEFAULT_SUFFIX, |
| 37 |
'autoMemberFilter': 'objectclass=nsAccount', |
| 38 |
'autoMemberDefaultGroup': group_dn, |
| 39 |
'autoMemberGroupingAttr': 'member:dn', |
| 40 |
}) |
| 41 |
|
| 42 |
# Enable MemberOf |
| 43 |
mop = MemberOfPlugin(inst) |
| 44 |
mop.enable() |
| 45 |
|
| 46 |
# Enable referint |
| 47 |
rip = ReferentialIntegrityPlugin(inst) |
| 48 |
# We only need to enable the plugin, the default configuration is sane and |
| 49 |
# correctly coveres member as an enforced attribute. |
| 50 |
rip.enable() |
| 51 |
|
| 52 |
# Restart to make sure it's enabled and good to go. |
| 53 |
inst.restart() |
| 54 |
|
| 55 |
def test_rename_large_subtree(topology_m2): |
| 56 |
""" |
| 57 |
A report stated that the following configuration would lead |
| 58 |
to an operation failure: |
| 59 |
|
| 60 |
ou=int,ou=account,dc=... |
| 61 |
ou=s1,ou=int,ou=account,dc=... |
| 62 |
ou=s2,ou=int,ou=account,dc=... |
| 63 |
|
| 64 |
rename ou=s1 to re-parent to ou=account, leaving: |
| 65 |
|
| 66 |
ou=int,ou=account,dc=... |
| 67 |
ou=s1,ou=account,dc=... |
| 68 |
ou=s2,ou=account,dc=... |
| 69 |
|
| 70 |
The ou=s1 if it has < 100 entries below, is able to be reparented. |
| 71 |
|
| 72 |
If ou=s1 has > 400 entries, it fails. |
| 73 |
|
| 74 |
Other conditions was the presence of referential integrity - so one would |
| 75 |
assume that all users under s1 are a member of some group external to this. |
| 76 |
|
| 77 |
:id: 5915c38d-b3c2-4b7c-af76-8a1e002e27f7 |
| 78 |
|
| 79 |
:setup: standalone instance |
| 80 |
|
| 81 |
:steps: 1. Enable automember plugin |
| 82 |
2. Add UCOUNT users, and ensure they are members of a group. |
| 83 |
3. Enable refer-int plugin |
| 84 |
4. Move ou=s1 to a new parent |
| 85 |
|
| 86 |
:expectedresults: |
| 87 |
1. The plugin is enabled |
| 88 |
2. The users are members of the group |
| 89 |
3. The plugin is enabled |
| 90 |
4. The rename operation of ou=s1 succeeds |
| 91 |
""" |
| 92 |
|
| 93 |
st = topology_m2.ms["supplier1"] |
| 94 |
m2 = topology_m2.ms["supplier2"] |
| 95 |
|
| 96 |
# Create a default group |
| 97 |
gps = Groups(st, DEFAULT_SUFFIX) |
| 98 |
# Keep the group so we can get it's DN out. |
| 99 |
group = gps.create(properties={ |
| 100 |
'cn': 'default_group' |
| 101 |
}) |
| 102 |
|
| 103 |
_enable_plugins(st, group.dn) |
| 104 |
_enable_plugins(m2, group.dn) |
| 105 |
|
| 106 |
# Now unlike normal, we bypass the plural-create method, because we need control |
| 107 |
# over the exact DN of the OU to create. |
| 108 |
# Create the ou=account |
| 109 |
|
| 110 |
# We don't need to set a DN here because ... |
| 111 |
ou_account = OrganisationalUnit(st) |
| 112 |
|
| 113 |
# It's set in the .create step. |
| 114 |
ou_account.create( |
| 115 |
basedn = DEFAULT_SUFFIX, |
| 116 |
properties={ |
| 117 |
'ou': 'account' |
| 118 |
}) |
| 119 |
# create the ou=int,ou=account |
| 120 |
ou_int = OrganisationalUnit(st) |
| 121 |
ou_int.create( |
| 122 |
basedn = ou_account.dn, |
| 123 |
properties={ |
| 124 |
'ou': 'int' |
| 125 |
}) |
| 126 |
# Create the ou=s1,ou=int,ou=account |
| 127 |
ou_s1 = OrganisationalUnit(st) |
| 128 |
ou_s1.create( |
| 129 |
basedn = ou_int.dn, |
| 130 |
properties={ |
| 131 |
'ou': 's1' |
| 132 |
}) |
| 133 |
|
| 134 |
# Pause replication |
| 135 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 136 |
repl.disable_to_supplier(m2, [st, ]) |
| 137 |
|
| 138 |
# Create the users 1 -> UCOUNT in ou=s1 |
| 139 |
nsu = nsUserAccounts(st, basedn=ou_s1.dn, rdn=None) |
| 140 |
for i in range(1000, 1000 + UCOUNT): |
| 141 |
nsu.create_test_user(uid=i) |
| 142 |
|
| 143 |
# Enable replication |
| 144 |
|
| 145 |
repl.enable_to_supplier(m2, [st, ]) |
| 146 |
|
| 147 |
# Assert they are in the group as we expect |
| 148 |
members = group.get_attr_vals_utf8('member') |
| 149 |
assert len(members) == UCOUNT |
| 150 |
|
| 151 |
# Wait for replication |
| 152 |
repl.wait_for_replication(st, m2, timeout=60) |
| 153 |
|
| 154 |
for i in range(0, 5): |
| 155 |
# Move ou=s1 to ou=account as parent. We have to provide the rdn, |
| 156 |
# even though it's not changing. |
| 157 |
ou_s1.rename('ou=s1', newsuperior=ou_account.dn) |
| 158 |
time.sleep(2) |
| 159 |
|
| 160 |
members = group.get_attr_vals_utf8('member') |
| 161 |
assert len(members) == UCOUNT |
| 162 |
# Check that we really did refer-int properly, and ou=int is not in the members. |
| 163 |
for member in members: |
| 164 |
assert 'ou=int' not in member |
| 165 |
|
| 166 |
# Now move it back |
| 167 |
ou_s1.rename('ou=s1', newsuperior=ou_int.dn) |
| 168 |
time.sleep(2) |
| 169 |
members = group.get_attr_vals_utf8('member') |
| 170 |
assert len(members) == UCOUNT |
| 171 |
for member in members: |
| 172 |
assert 'ou=int' in member |
| 173 |
|
| 174 |
# Check everythig on the other side is good. |
| 175 |
repl.wait_for_replication(st, m2, timeout=60) |
| 176 |
|
| 177 |
group2 = Groups(m2, DEFAULT_SUFFIX).get('default_group') |
| 178 |
|
| 179 |
members = group2.get_attr_vals_utf8('member') |
| 180 |
assert len(members) == UCOUNT |
| 181 |
for member in members: |
| 182 |
assert 'ou=int' in member |