| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Tests various schema replication scenarios |
| 5 |
# |
| 6 |
# Copyright (C) Kamen Mazdrashki <[email protected]> 2011 |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
# |
| 21 |
|
| 22 |
# |
| 23 |
# Usage: |
| 24 |
# export DC1=dc1_dns_name |
| 25 |
# export DC2=dc2_dns_name |
| 26 |
# export SUBUNITRUN=$samba4srcdir/scripting/bin/subunitrun |
| 27 |
# PYTHONPATH="$PYTHONPATH:$samba4srcdir/torture/drs/python" $SUBUNITRUN replica_sync -U"$DOMAIN/$DC_USERNAME"%"$DC_PASSWORD" |
| 28 |
# |
| 29 |
|
| 30 |
import drs_base |
| 31 |
import samba.tests |
| 32 |
import time |
| 33 |
import ldb |
| 34 |
|
| 35 |
from ldb import ( |
| 36 |
SCOPE_BASE, LdbError, ERR_NO_SUCH_OBJECT) |
| 37 |
|
| 38 |
|
| 39 |
class DrsReplicaSyncTestCase(drs_base.DrsBaseTestCase): |
| 40 |
"""Intended as a black box test case for DsReplicaSync |
| 41 |
implementation. It should test the behavior of this |
| 42 |
case in cases when inbound replication is disabled""" |
| 43 |
|
| 44 |
def setUp(self): |
| 45 |
super(DrsReplicaSyncTestCase, self).setUp() |
| 46 |
|
| 47 |
# This OU avoids this test conflicting with anything |
| 48 |
# that may already be in the DB |
| 49 |
self.top_ou = samba.tests.create_test_ou(self.ldb_dc1, |
| 50 |
"replica_sync") |
| 51 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True) |
| 52 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True) |
| 53 |
self.ou1 = None |
| 54 |
self.ou2 = None |
| 55 |
|
| 56 |
def tearDown(self): |
| 57 |
self._cleanup_object(self.ou1) |
| 58 |
self._cleanup_object(self.ou2) |
| 59 |
self._cleanup_dn(self.top_ou) |
| 60 |
|
| 61 |
# re-enable replication |
| 62 |
self._enable_inbound_repl(self.dnsname_dc1) |
| 63 |
self._enable_inbound_repl(self.dnsname_dc2) |
| 64 |
|
| 65 |
super(DrsReplicaSyncTestCase, self).tearDown() |
| 66 |
|
| 67 |
def _cleanup_dn(self, dn): |
| 68 |
try: |
| 69 |
self.ldb_dc2.delete(dn, ["tree_delete:1"]) |
| 70 |
except LdbError as e: |
| 71 |
(num, _) = e.args |
| 72 |
self.assertEqual(num, ERR_NO_SUCH_OBJECT) |
| 73 |
try: |
| 74 |
self.ldb_dc1.delete(dn, ["tree_delete:1"]) |
| 75 |
except LdbError as e1: |
| 76 |
(num, _) = e1.args |
| 77 |
self.assertEqual(num, ERR_NO_SUCH_OBJECT) |
| 78 |
|
| 79 |
def _cleanup_object(self, guid): |
| 80 |
"""Cleans up a test object, if it still exists""" |
| 81 |
if guid is not None: |
| 82 |
self._cleanup_dn('<GUID=%s>' % guid) |
| 83 |
|
| 84 |
def test_ReplEnabled(self): |
| 85 |
"""Tests we can replicate when replication is enabled""" |
| 86 |
self._enable_inbound_repl(self.dnsname_dc1) |
| 87 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=False) |
| 88 |
|
| 89 |
def test_ReplDisabled(self): |
| 90 |
"""Tests we can't replicate when replication is disabled""" |
| 91 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 92 |
|
| 93 |
ccache_name = self.get_creds_ccache_name() |
| 94 |
|
| 95 |
# Tunnel the command line credentials down to the |
| 96 |
# subcommand to avoid a new kinit |
| 97 |
cmdline_auth = "--use-krb5-ccache=%s" % ccache_name |
| 98 |
|
| 99 |
# bin/samba-tool drs <drs_command> <cmdline_auth> |
| 100 |
cmd_list = ["drs", "replicate", cmdline_auth] |
| 101 |
|
| 102 |
nc_dn = self.domain_dn |
| 103 |
# bin/samba-tool drs replicate <Dest_DC_NAME> <Src_DC_NAME> <Naming Context> |
| 104 |
cmd_list += [self.dnsname_dc1, self.dnsname_dc2, nc_dn] |
| 105 |
|
| 106 |
(result, out, err) = self.runsubcmd(*cmd_list) |
| 107 |
self.assertCmdFail(result) |
| 108 |
self.assertTrue('WERR_DS_DRA_SINK_DISABLED' in err) |
| 109 |
|
| 110 |
def test_ReplDisabledForced(self): |
| 111 |
"""Tests we can force replicate when replication is disabled""" |
| 112 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 113 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True) |
| 114 |
|
| 115 |
def test_ReplLocal(self): |
| 116 |
"""Tests we can replicate direct to the local db""" |
| 117 |
self._enable_inbound_repl(self.dnsname_dc1) |
| 118 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=False, local=True, full_sync=True) |
| 119 |
|
| 120 |
def _create_ou(self, samdb, name): |
| 121 |
ldif = """ |
| 122 |
dn: %s,%s |
| 123 |
objectClass: organizationalUnit |
| 124 |
""" % (name, self.top_ou) |
| 125 |
samdb.add_ldif(ldif) |
| 126 |
res = samdb.search(base="%s,%s" % (name, self.top_ou), |
| 127 |
scope=SCOPE_BASE, attrs=["objectGUID"]) |
| 128 |
return self._GUID_string(res[0]["objectGUID"][0]) |
| 129 |
|
| 130 |
def _check_deleted(self, sam_ldb, guid): |
| 131 |
# search the user by guid as it may be deleted |
| 132 |
res = sam_ldb.search(base='<GUID=%s>' % guid, |
| 133 |
controls=["show_deleted:1"], |
| 134 |
attrs=["isDeleted", "objectCategory", "ou"]) |
| 135 |
self.assertEqual(len(res), 1) |
| 136 |
ou_cur = res[0] |
| 137 |
# Deleted Object base DN |
| 138 |
dodn = self._deleted_objects_dn(sam_ldb) |
| 139 |
# now check properties of the user |
| 140 |
name_cur = ou_cur["ou"][0] |
| 141 |
self.assertEqual(ou_cur["isDeleted"][0], b"TRUE") |
| 142 |
self.assertTrue(not("objectCategory" in ou_cur)) |
| 143 |
self.assertTrue(dodn in str(ou_cur["dn"]), |
| 144 |
"OU %s is deleted but it is not located under %s!" % (name_cur, dodn)) |
| 145 |
|
| 146 |
def test_ReplConflictsFullSync(self): |
| 147 |
"""Tests that objects created in conflict become conflict DNs (honour full sync override)""" |
| 148 |
|
| 149 |
# First confirm local replication (so when we test against windows, this fails fast without creating objects) |
| 150 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, local=True, forced=True, full_sync=True) |
| 151 |
|
| 152 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 153 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 154 |
|
| 155 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 156 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Full Sync") |
| 157 |
# We have to sleep to ensure that the two objects have different timestamps |
| 158 |
time.sleep(1) |
| 159 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Full Sync") |
| 160 |
|
| 161 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, local=True, forced=True, full_sync=True) |
| 162 |
|
| 163 |
# Check that DC2 got the DC1 object, and OU1 was make into conflict |
| 164 |
res1 = self.ldb_dc2.search(base="<GUID=%s>" % self.ou1, |
| 165 |
scope=SCOPE_BASE, attrs=["name"]) |
| 166 |
res2 = self.ldb_dc2.search(base="<GUID=%s>" % self.ou2, |
| 167 |
scope=SCOPE_BASE, attrs=["name"]) |
| 168 |
print(res1[0]["name"][0]) |
| 169 |
print(res2[0]["name"][0]) |
| 170 |
self.assertFalse('CNF:%s' % self.ou2 in str(res2[0]["name"][0])) |
| 171 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 172 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc2, self.domain_dn) not in str(res1[0].dn)) |
| 173 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc2, self.domain_dn) not in str(res2[0].dn)) |
| 174 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 175 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 176 |
|
| 177 |
# Delete both objects by GUID on DC2 |
| 178 |
|
| 179 |
self.ldb_dc2.delete('<GUID=%s>' % self.ou1) |
| 180 |
self.ldb_dc2.delete('<GUID=%s>' % self.ou2) |
| 181 |
|
| 182 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=True) |
| 183 |
|
| 184 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 185 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 186 |
# Check deleted on DC2 |
| 187 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 188 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 189 |
|
| 190 |
def test_ReplConflictsRemoteWin(self): |
| 191 |
"""Tests that objects created in conflict become conflict DNs""" |
| 192 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 193 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 194 |
|
| 195 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 196 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Remote Conflict") |
| 197 |
# We have to sleep to ensure that the two objects have different timestamps |
| 198 |
time.sleep(1) |
| 199 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Remote Conflict") |
| 200 |
|
| 201 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 202 |
|
| 203 |
# Check that DC2 got the DC1 object, and OU1 was make into conflict |
| 204 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 205 |
scope=SCOPE_BASE, attrs=["name"]) |
| 206 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 207 |
scope=SCOPE_BASE, attrs=["name"]) |
| 208 |
print(res1[0]["name"][0]) |
| 209 |
print(res2[0]["name"][0]) |
| 210 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 211 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 212 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 213 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 214 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 215 |
|
| 216 |
# Delete both objects by GUID on DC1 |
| 217 |
|
| 218 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 219 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 220 |
|
| 221 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 222 |
|
| 223 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 224 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 225 |
# Check deleted on DC2 |
| 226 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 227 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 228 |
|
| 229 |
def test_ReplConflictsLocalWin(self): |
| 230 |
"""Tests that objects created in conflict become conflict DNs""" |
| 231 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 232 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 233 |
|
| 234 |
# Create conflicting objects on DC1 and DC2, with DC2 object created first |
| 235 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Local Conflict") |
| 236 |
# We have to sleep to ensure that the two objects have different timestamps |
| 237 |
time.sleep(1) |
| 238 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Local Conflict") |
| 239 |
|
| 240 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 241 |
|
| 242 |
# Check that DC2 got the DC1 object, and OU2 was make into conflict |
| 243 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 244 |
scope=SCOPE_BASE, attrs=["name"]) |
| 245 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 246 |
scope=SCOPE_BASE, attrs=["name"]) |
| 247 |
print(res1[0]["name"][0]) |
| 248 |
print(res2[0]["name"][0]) |
| 249 |
self.assertTrue('CNF:%s' % self.ou2 in str(res2[0]["name"][0]), "Got %s for %s" % (str(res2[0]["name"][0]), self.ou2)) |
| 250 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 251 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 252 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 253 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 254 |
|
| 255 |
# Delete both objects by GUID on DC1 |
| 256 |
|
| 257 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 258 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 259 |
|
| 260 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 261 |
|
| 262 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 263 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 264 |
# Check deleted on DC2 |
| 265 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 266 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 267 |
|
| 268 |
def test_ReplConflictsRemoteWin_with_child(self): |
| 269 |
"""Tests that objects created in conflict become conflict DNs""" |
| 270 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 271 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 272 |
|
| 273 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 274 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Parent Remote Conflict") |
| 275 |
# We have to sleep to ensure that the two objects have different timestamps |
| 276 |
time.sleep(1) |
| 277 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Parent Remote Conflict") |
| 278 |
# Create children on DC2 |
| 279 |
ou1_child = self._create_ou(self.ldb_dc1, "OU=Test Child,OU=Test Parent Remote Conflict") |
| 280 |
ou2_child = self._create_ou(self.ldb_dc2, "OU=Test Child,OU=Test Parent Remote Conflict") |
| 281 |
|
| 282 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 283 |
|
| 284 |
# Check that DC2 got the DC1 object, and SELF.OU1 was make into conflict |
| 285 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 286 |
scope=SCOPE_BASE, attrs=["name"]) |
| 287 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 288 |
scope=SCOPE_BASE, attrs=["name"]) |
| 289 |
print(res1[0]["name"][0]) |
| 290 |
print(res2[0]["name"][0]) |
| 291 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 292 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 293 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 294 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 295 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 296 |
|
| 297 |
# Delete both objects by GUID on DC1 |
| 298 |
|
| 299 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1, ["tree_delete:1"]) |
| 300 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2, ["tree_delete:1"]) |
| 301 |
|
| 302 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 303 |
|
| 304 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 305 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 306 |
# Check deleted on DC2 |
| 307 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 308 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 309 |
|
| 310 |
self._check_deleted(self.ldb_dc1, ou1_child) |
| 311 |
self._check_deleted(self.ldb_dc1, ou2_child) |
| 312 |
# Check deleted on DC2 |
| 313 |
self._check_deleted(self.ldb_dc2, ou1_child) |
| 314 |
self._check_deleted(self.ldb_dc2, ou2_child) |
| 315 |
|
| 316 |
def test_ReplConflictsRenamedVsNewRemoteWin(self): |
| 317 |
"""Tests resolving a DN conflict between a renamed object and a new object""" |
| 318 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 319 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 320 |
|
| 321 |
# Create an OU and rename it on DC1 |
| 322 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Remote Rename Conflict orig") |
| 323 |
self.ldb_dc1.rename("<GUID=%s>" % self.ou1, "OU=Test Remote Rename Conflict,%s" % self.top_ou) |
| 324 |
|
| 325 |
# We have to sleep to ensure that the two objects have different timestamps |
| 326 |
time.sleep(1) |
| 327 |
|
| 328 |
# create a conflicting object with the same DN on DC2 |
| 329 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Remote Rename Conflict") |
| 330 |
|
| 331 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 332 |
|
| 333 |
# Check that DC2 got the DC1 object, and SELF.OU1 was made into conflict |
| 334 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 335 |
scope=SCOPE_BASE, attrs=["name"]) |
| 336 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 337 |
scope=SCOPE_BASE, attrs=["name"]) |
| 338 |
print(res1[0]["name"][0]) |
| 339 |
print(res2[0]["name"][0]) |
| 340 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 341 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 342 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 343 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 344 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 345 |
|
| 346 |
# Delete both objects by GUID on DC1 |
| 347 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 348 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 349 |
|
| 350 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 351 |
|
| 352 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 353 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 354 |
# Check deleted on DC2 |
| 355 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 356 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 357 |
|
| 358 |
def test_ReplConflictsRenamedVsNewLocalWin(self): |
| 359 |
"""Tests resolving a DN conflict between a renamed object and a new object""" |
| 360 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 361 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 362 |
|
| 363 |
# Create conflicting objects on DC1 and DC2, where the DC2 object has been renamed |
| 364 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Rename Local Conflict orig") |
| 365 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou2, "OU=Test Rename Local Conflict,%s" % self.top_ou) |
| 366 |
# We have to sleep to ensure that the two objects have different timestamps |
| 367 |
time.sleep(1) |
| 368 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Rename Local Conflict") |
| 369 |
|
| 370 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 371 |
|
| 372 |
# Check that DC2 got the DC1 object, and OU2 was made into conflict |
| 373 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 374 |
scope=SCOPE_BASE, attrs=["name"]) |
| 375 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 376 |
scope=SCOPE_BASE, attrs=["name"]) |
| 377 |
print(res1[0]["name"][0]) |
| 378 |
print(res2[0]["name"][0]) |
| 379 |
self.assertTrue('CNF:%s' % self.ou2 in str(res2[0]["name"][0])) |
| 380 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 381 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 382 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 383 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 384 |
|
| 385 |
# Delete both objects by GUID on DC1 |
| 386 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 387 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 388 |
|
| 389 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 390 |
|
| 391 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 392 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 393 |
# Check deleted on DC2 |
| 394 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 395 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 396 |
|
| 397 |
def test_ReplConflictsRenameRemoteWin(self): |
| 398 |
"""Tests that objects created in conflict become conflict DNs""" |
| 399 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 400 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 401 |
|
| 402 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 403 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Remote Rename Conflict") |
| 404 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Remote Rename Conflict 2") |
| 405 |
|
| 406 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 407 |
|
| 408 |
self.ldb_dc1.rename("<GUID=%s>" % self.ou1, "OU=Test Remote Rename Conflict 3,%s" % self.top_ou) |
| 409 |
# We have to sleep to ensure that the two objects have different timestamps |
| 410 |
time.sleep(1) |
| 411 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou2, "OU=Test Remote Rename Conflict 3,%s" % self.top_ou) |
| 412 |
|
| 413 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 414 |
|
| 415 |
# Check that DC2 got the DC1 object, and SELF.OU1 was make into conflict |
| 416 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 417 |
scope=SCOPE_BASE, attrs=["name"]) |
| 418 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 419 |
scope=SCOPE_BASE, attrs=["name"]) |
| 420 |
print(res1[0]["name"][0]) |
| 421 |
print(res2[0]["name"][0]) |
| 422 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 423 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 424 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 425 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 426 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 427 |
|
| 428 |
# Delete both objects by GUID on DC1 |
| 429 |
|
| 430 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 431 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 432 |
|
| 433 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 434 |
|
| 435 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 436 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 437 |
# Check deleted on DC2 |
| 438 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 439 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 440 |
|
| 441 |
def test_ReplConflictsRenameRemoteWin_with_child(self): |
| 442 |
"""Tests that objects created in conflict become conflict DNs""" |
| 443 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 444 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 445 |
|
| 446 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 447 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Parent Remote Rename Conflict") |
| 448 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Parent Remote Rename Conflict 2") |
| 449 |
# Create children on DC2 |
| 450 |
ou1_child = self._create_ou(self.ldb_dc1, "OU=Test Child,OU=Test Parent Remote Rename Conflict") |
| 451 |
ou2_child = self._create_ou(self.ldb_dc2, "OU=Test Child,OU=Test Parent Remote Rename Conflict 2") |
| 452 |
|
| 453 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 454 |
|
| 455 |
self.ldb_dc1.rename("<GUID=%s>" % self.ou1, "OU=Test Parent Remote Rename Conflict 3,%s" % self.top_ou) |
| 456 |
# We have to sleep to ensure that the two objects have different timestamps |
| 457 |
time.sleep(1) |
| 458 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou2, "OU=Test Parent Remote Rename Conflict 3,%s" % self.top_ou) |
| 459 |
|
| 460 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 461 |
|
| 462 |
# Check that DC2 got the DC1 object, and SELF.OU1 was make into conflict |
| 463 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 464 |
scope=SCOPE_BASE, attrs=["name"]) |
| 465 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 466 |
scope=SCOPE_BASE, attrs=["name"]) |
| 467 |
print(res1[0]["name"][0]) |
| 468 |
print(res2[0]["name"][0]) |
| 469 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 470 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 471 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 472 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 473 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 474 |
|
| 475 |
# Delete both objects by GUID on DC1 |
| 476 |
|
| 477 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1, ["tree_delete:1"]) |
| 478 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2, ["tree_delete:1"]) |
| 479 |
|
| 480 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 481 |
|
| 482 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 483 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 484 |
# Check deleted on DC2 |
| 485 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 486 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 487 |
|
| 488 |
self._check_deleted(self.ldb_dc1, ou1_child) |
| 489 |
self._check_deleted(self.ldb_dc1, ou2_child) |
| 490 |
# Check deleted on DC2 |
| 491 |
self._check_deleted(self.ldb_dc2, ou1_child) |
| 492 |
self._check_deleted(self.ldb_dc2, ou2_child) |
| 493 |
|
| 494 |
def test_ReplConflictsRenameLocalWin(self): |
| 495 |
"""Tests that objects created in conflict become conflict DNs""" |
| 496 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 497 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 498 |
|
| 499 |
# Create conflicting objects on DC1 and DC2, with DC1 object created first |
| 500 |
self.ou1 = self._create_ou(self.ldb_dc1, "OU=Test Rename Local Conflict") |
| 501 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Test Rename Local Conflict 2") |
| 502 |
|
| 503 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 504 |
|
| 505 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou2, "OU=Test Rename Local Conflict 3,%s" % self.top_ou) |
| 506 |
# We have to sleep to ensure that the two objects have different timestamps |
| 507 |
time.sleep(1) |
| 508 |
self.ldb_dc1.rename("<GUID=%s>" % self.ou1, "OU=Test Rename Local Conflict 3,%s" % self.top_ou) |
| 509 |
|
| 510 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 511 |
|
| 512 |
# Check that DC2 got the DC1 object, and OU2 was make into conflict |
| 513 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 514 |
scope=SCOPE_BASE, attrs=["name"]) |
| 515 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 516 |
scope=SCOPE_BASE, attrs=["name"]) |
| 517 |
print(res1[0]["name"][0]) |
| 518 |
print(res2[0]["name"][0]) |
| 519 |
self.assertTrue('CNF:%s' % self.ou2 in str(res2[0]["name"][0])) |
| 520 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res1[0].dn)) |
| 521 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) not in str(res2[0].dn)) |
| 522 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 523 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 524 |
|
| 525 |
# Delete both objects by GUID on DC1 |
| 526 |
|
| 527 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 528 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 529 |
|
| 530 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 531 |
|
| 532 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 533 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 534 |
# Check deleted on DC2 |
| 535 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 536 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 537 |
|
| 538 |
def test_ReplLostAndFound(self): |
| 539 |
"""Tests that objects created under a OU deleted eleswhere end up in lostAndFound""" |
| 540 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 541 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 542 |
|
| 543 |
# Create two OUs on DC2 |
| 544 |
self.ou1 = self._create_ou(self.ldb_dc2, "OU=Deleted parent") |
| 545 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Deleted parent 2") |
| 546 |
|
| 547 |
# replicate them from DC2 to DC1 |
| 548 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 549 |
|
| 550 |
# Delete both objects by GUID on DC1 |
| 551 |
|
| 552 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 553 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 554 |
|
| 555 |
# Create children on DC2 |
| 556 |
ou1_child = self._create_ou(self.ldb_dc2, "OU=Test Child,OU=Deleted parent") |
| 557 |
ou2_child = self._create_ou(self.ldb_dc2, "OU=Test Child,OU=Deleted parent 2") |
| 558 |
|
| 559 |
# Replicate from DC2 |
| 560 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 561 |
|
| 562 |
# Check the sub-OUs are now in lostAndFound and the first one is a conflict DN |
| 563 |
|
| 564 |
# Check that DC2 got the DC1 object, and one or other object was make into conflict |
| 565 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % ou1_child, |
| 566 |
scope=SCOPE_BASE, attrs=["name"]) |
| 567 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % ou2_child, |
| 568 |
scope=SCOPE_BASE, attrs=["name"]) |
| 569 |
print(res1[0]["name"][0]) |
| 570 |
print(res2[0]["name"][0]) |
| 571 |
self.assertTrue('CNF:%s' % ou1_child in str(res1[0]["name"][0]) or 'CNF:%s' % ou2_child in str(res2[0]["name"][0])) |
| 572 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) in str(res1[0].dn)) |
| 573 |
self.assertTrue(self._lost_and_found_dn(self.ldb_dc1, self.domain_dn) in str(res2[0].dn)) |
| 574 |
self.assertEqual(str(res1[0]["name"][0]), res1[0].dn.get_rdn_value()) |
| 575 |
self.assertEqual(str(res2[0]["name"][0]), res2[0].dn.get_rdn_value()) |
| 576 |
|
| 577 |
# Delete all objects by GUID on DC1 |
| 578 |
|
| 579 |
self.ldb_dc1.delete('<GUID=%s>' % ou1_child) |
| 580 |
self.ldb_dc1.delete('<GUID=%s>' % ou2_child) |
| 581 |
|
| 582 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 583 |
|
| 584 |
# Check all deleted on DC1 |
| 585 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 586 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 587 |
self._check_deleted(self.ldb_dc1, ou1_child) |
| 588 |
self._check_deleted(self.ldb_dc1, ou2_child) |
| 589 |
# Check all deleted on DC2 |
| 590 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 591 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 592 |
self._check_deleted(self.ldb_dc2, ou1_child) |
| 593 |
self._check_deleted(self.ldb_dc2, ou2_child) |
| 594 |
|
| 595 |
def test_ReplRenames(self): |
| 596 |
"""Tests that objects created under a OU deleted eleswhere end up in lostAndFound""" |
| 597 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 598 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 599 |
|
| 600 |
# Create two OUs on DC2 |
| 601 |
self.ou1 = self._create_ou(self.ldb_dc2, "OU=Original parent") |
| 602 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Original parent 2") |
| 603 |
|
| 604 |
# replicate them from DC2 to DC1 |
| 605 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 606 |
|
| 607 |
# Create children on DC1 |
| 608 |
ou1_child = self._create_ou(self.ldb_dc1, "OU=Test Child,OU=Original parent") |
| 609 |
ou2_child = self._create_ou(self.ldb_dc1, "OU=Test Child 2,OU=Original parent") |
| 610 |
ou3_child = self._create_ou(self.ldb_dc1, "OU=Test Case Child,OU=Original parent") |
| 611 |
|
| 612 |
# replicate them from DC1 to DC2 |
| 613 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 614 |
|
| 615 |
self.ldb_dc1.rename("<GUID=%s>" % ou2_child, "OU=Test Child 3,OU=Original parent 2,%s" % self.top_ou) |
| 616 |
self.ldb_dc1.rename("<GUID=%s>" % ou1_child, "OU=Test Child 2,OU=Original parent 2,%s" % self.top_ou) |
| 617 |
self.ldb_dc1.rename("<GUID=%s>" % ou2_child, "OU=Test Child,OU=Original parent 2,%s" % self.top_ou) |
| 618 |
self.ldb_dc1.rename("<GUID=%s>" % ou3_child, "OU=Test CASE Child,OU=Original parent,%s" % self.top_ou) |
| 619 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou2, "OU=Original parent 3,%s" % self.top_ou) |
| 620 |
self.ldb_dc2.rename("<GUID=%s>" % self.ou1, "OU=Original parent 2,%s" % self.top_ou) |
| 621 |
|
| 622 |
# replicate them from DC1 to DC2 |
| 623 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 624 |
|
| 625 |
# Check the sub-OUs are now under Original Parent 3 (original |
| 626 |
# parent 2 for Test CASE Child), and both have the right names |
| 627 |
|
| 628 |
# Check that DC2 got the DC1 object, and the renames are all correct |
| 629 |
res1 = self.ldb_dc2.search(base="<GUID=%s>" % ou1_child, |
| 630 |
scope=SCOPE_BASE, attrs=["name"]) |
| 631 |
res2 = self.ldb_dc2.search(base="<GUID=%s>" % ou2_child, |
| 632 |
scope=SCOPE_BASE, attrs=["name"]) |
| 633 |
res3 = self.ldb_dc2.search(base="<GUID=%s>" % ou3_child, |
| 634 |
scope=SCOPE_BASE, attrs=["name"]) |
| 635 |
print(res1[0].dn) |
| 636 |
print(res2[0].dn) |
| 637 |
print(res3[0].dn) |
| 638 |
self.assertEqual('Test Child 2', str(res1[0]["name"][0])) |
| 639 |
self.assertEqual('Test Child', str(res2[0]["name"][0])) |
| 640 |
self.assertEqual('Test CASE Child', str(res3[0]["name"][0])) |
| 641 |
self.assertEqual(str(res1[0].dn), "OU=Test Child 2,OU=Original parent 3,%s" % self.top_ou) |
| 642 |
self.assertEqual(str(res2[0].dn), "OU=Test Child,OU=Original parent 3,%s" % self.top_ou) |
| 643 |
self.assertEqual(str(res3[0].dn), "OU=Test CASE Child,OU=Original parent 2,%s" % self.top_ou) |
| 644 |
|
| 645 |
# replicate them from DC2 to DC1 |
| 646 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 647 |
|
| 648 |
# Check that DC1 got the DC2 object, and the renames are all correct |
| 649 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % ou1_child, |
| 650 |
scope=SCOPE_BASE, attrs=["name"]) |
| 651 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % ou2_child, |
| 652 |
scope=SCOPE_BASE, attrs=["name"]) |
| 653 |
res3 = self.ldb_dc1.search(base="<GUID=%s>" % ou3_child, |
| 654 |
scope=SCOPE_BASE, attrs=["name"]) |
| 655 |
print(res1[0].dn) |
| 656 |
print(res2[0].dn) |
| 657 |
print(res3[0].dn) |
| 658 |
self.assertEqual('Test Child 2', str(res1[0]["name"][0])) |
| 659 |
self.assertEqual('Test Child', str(res2[0]["name"][0])) |
| 660 |
self.assertEqual('Test CASE Child', str(res3[0]["name"][0])) |
| 661 |
self.assertEqual(str(res1[0].dn), "OU=Test Child 2,OU=Original parent 3,%s" % self.top_ou) |
| 662 |
self.assertEqual(str(res2[0].dn), "OU=Test Child,OU=Original parent 3,%s" % self.top_ou) |
| 663 |
self.assertEqual(str(res3[0].dn), "OU=Test CASE Child,OU=Original parent 2,%s" % self.top_ou) |
| 664 |
|
| 665 |
# Delete all objects by GUID on DC1 |
| 666 |
|
| 667 |
self.ldb_dc1.delete('<GUID=%s>' % ou1_child) |
| 668 |
self.ldb_dc1.delete('<GUID=%s>' % ou2_child) |
| 669 |
self.ldb_dc1.delete('<GUID=%s>' % ou3_child) |
| 670 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 671 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 672 |
|
| 673 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 674 |
|
| 675 |
# Check all deleted on DC1 |
| 676 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 677 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 678 |
self._check_deleted(self.ldb_dc1, ou1_child) |
| 679 |
self._check_deleted(self.ldb_dc1, ou2_child) |
| 680 |
self._check_deleted(self.ldb_dc1, ou3_child) |
| 681 |
# Check all deleted on DC2 |
| 682 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 683 |
self._check_deleted(self.ldb_dc2, self.ou2) |
| 684 |
self._check_deleted(self.ldb_dc2, ou1_child) |
| 685 |
self._check_deleted(self.ldb_dc2, ou2_child) |
| 686 |
self._check_deleted(self.ldb_dc2, ou3_child) |
| 687 |
|
| 688 |
def reanimate_object(self, samdb, guid, new_dn): |
| 689 |
"""Re-animates a deleted object""" |
| 690 |
res = samdb.search(base="<GUID=%s>" % guid, attrs=["isDeleted"], |
| 691 |
controls=['show_deleted:1'], scope=SCOPE_BASE) |
| 692 |
if len(res) != 1: |
| 693 |
return |
| 694 |
|
| 695 |
msg = ldb.Message() |
| 696 |
msg.dn = res[0].dn |
| 697 |
msg["isDeleted"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "isDeleted") |
| 698 |
msg["distinguishedName"] = ldb.MessageElement([new_dn], ldb.FLAG_MOD_REPLACE, "distinguishedName") |
| 699 |
samdb.modify(msg, ["show_deleted:1"]) |
| 700 |
|
| 701 |
def test_ReplReanimationConflict(self): |
| 702 |
""" |
| 703 |
Checks that if a reanimated object conflicts with a new object, then |
| 704 |
the conflict is resolved correctly. |
| 705 |
""" |
| 706 |
|
| 707 |
self._disable_inbound_repl(self.dnsname_dc1) |
| 708 |
self._disable_inbound_repl(self.dnsname_dc2) |
| 709 |
|
| 710 |
# create an object, "accidentally" delete it, and replicate the changes to both DCs |
| 711 |
self.ou1 = self._create_ou(self.ldb_dc2, "OU=Conflict object") |
| 712 |
self.ldb_dc2.delete('<GUID=%s>' % self.ou1) |
| 713 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 714 |
|
| 715 |
# Now pretend that the admin for one DC resolves the problem by |
| 716 |
# re-animating the object... |
| 717 |
self.reanimate_object(self.ldb_dc1, self.ou1, "OU=Conflict object,%s" % self.top_ou) |
| 718 |
|
| 719 |
# ...whereas another admin just creates a user with the same name |
| 720 |
# again on a different DC |
| 721 |
time.sleep(1) |
| 722 |
self.ou2 = self._create_ou(self.ldb_dc2, "OU=Conflict object") |
| 723 |
|
| 724 |
# Now sync the DCs to resolve the conflict |
| 725 |
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True, full_sync=False) |
| 726 |
|
| 727 |
# Check the latest change won and SELF.OU1 was made into a conflict |
| 728 |
res1 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou1, |
| 729 |
scope=SCOPE_BASE, attrs=["name"]) |
| 730 |
res2 = self.ldb_dc1.search(base="<GUID=%s>" % self.ou2, |
| 731 |
scope=SCOPE_BASE, attrs=["name"]) |
| 732 |
print(res1[0]["name"][0]) |
| 733 |
print(res2[0]["name"][0]) |
| 734 |
self.assertTrue('CNF:%s' % self.ou1 in str(res1[0]["name"][0])) |
| 735 |
self.assertFalse('CNF:%s' % self.ou2 in str(res2[0]["name"][0])) |
| 736 |
|
| 737 |
# Delete both objects by GUID on DC1 |
| 738 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou1) |
| 739 |
self.ldb_dc1.delete('<GUID=%s>' % self.ou2) |
| 740 |
|
| 741 |
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True, full_sync=False) |
| 742 |
|
| 743 |
self._check_deleted(self.ldb_dc1, self.ou1) |
| 744 |
self._check_deleted(self.ldb_dc1, self.ou2) |
| 745 |
# Check deleted on DC2 |
| 746 |
self._check_deleted(self.ldb_dc2, self.ou1) |
| 747 |
self._check_deleted(self.ldb_dc2, self.ou2) |