2 # -*- coding: utf-8 -*-
4 # Unix SMB/CIFS implementation.
5 # Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2010
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # export DC1=dc1_dns_name
24 # export DC2=dc2_dns_name
25 # export SUBUNITRUN=$samba4srcdir/scripting/bin/subunitrun
26 # PYTHONPATH="$PYTHONPATH:$samba4srcdir/torture/drs/python" $SUBUNITRUN delete_object -U"$DOMAIN/$DC_USERNAME"%"$DC_PASSWORD"
33 sys
.path
.insert(0, "bin/python")
43 class DrsDeleteObjectTestCase(drs_base
.DrsBaseTestCase
):
46 super(DrsDeleteObjectTestCase
, self
).setUp()
47 # disable automatic replication temporary
48 self
._disable
_inbound
_repl
(self
.dnsname_dc1
)
49 self
._disable
_inbound
_repl
(self
.dnsname_dc2
)
52 self
._enable
_inbound
_repl
(self
.dnsname_dc1
)
53 self
._enable
_inbound
_repl
(self
.dnsname_dc2
)
54 super(DrsDeleteObjectTestCase
, self
).tearDown()
56 def _make_username(self
):
57 return "DrsDelObjUser_" + time
.strftime("%s", time
.gmtime())
59 def _check_user(self
, sam_ldb
, user_orig
, is_deleted
):
60 # search the user by guid as it may be deleted
61 guid_str
= self
._GUID
_string
(user_orig
["objectGUID"][0])
62 expression
= "(objectGUID=%s)" % guid_str
63 res
= sam_ldb
.search(base
=self
.domain_dn
,
64 expression
=expression
,
65 controls
=["show_deleted:1"])
66 self
.assertEquals(len(res
), 1)
68 # Deleted Object base DN
69 dodn
= self
._deleted
_objects
_dn
(sam_ldb
)
70 # now check properties of the user
71 name_orig
= user_orig
["cn"][0]
72 name_cur
= user_cur
["cn"][0]
74 self
.assertEquals(user_cur
["isDeleted"][0],"TRUE")
75 self
.assertTrue(not("objectCategory" in user_cur
))
76 self
.assertTrue(not("sAMAccountType" in user_cur
))
77 self
.assertTrue(dodn
in str(user_cur
["dn"]),
78 "User %s is deleted but it is not located under %s!" % (name_orig
, dodn
))
79 self
.assertEquals(name_cur
, name_orig
+ "\nDEL:" + guid_str
)
81 self
.assertTrue(not("isDeleted" in user_cur
))
82 self
.assertEquals(name_cur
, name_orig
)
83 self
.assertEquals(user_orig
["dn"], user_cur
["dn"])
84 self
.assertTrue(dodn
not in str(user_cur
["dn"]))
86 def test_NetReplicateCmd(self
):
87 """Triggers replication from DC1 to DC2
88 and vice versa so both DCs are synchronized
89 before test_ReplicateDeteleteObject test"""
90 # replicate Domain NC on DC2 from DC1
91 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
)
92 # replicate Domain NC on DC1 from DC2
93 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc1
, fromDC
=self
.dnsname_dc2
)
95 def test_ReplicateDeteleteObject(self
):
96 """Verifies how a deleted-object is replicated between two DCs.
97 This test should verify that:
98 - deleted-object is replicated properly
99 TODO: We should verify that after replication,
100 object's state to conform to a deleted-object state
101 or tombstone -object, depending on DC's features
102 It will also be great if check replPropertyMetaData."""
103 # work-out unique username to test with
104 username
= self
._make
_username
()
107 self
.ldb_dc1
.newuser(username
=username
, password
="P@sswOrd!")
108 ldb_res
= self
.ldb_dc1
.search(base
=self
.domain_dn
,
110 expression
="(samAccountName=%s)" % username
)
111 self
.assertEquals(len(ldb_res
), 1)
112 user_orig
= ldb_res
[0]
113 user_dn
= ldb_res
[0]["dn"]
115 # check user info on DC1
116 print "Testing for %s with GUID %s" % (username
, self
._GUID
_string
(user_orig
["objectGUID"][0]))
117 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=False)
119 # trigger replication from DC1 to DC2
120 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
, forced
=True)
123 self
.ldb_dc1
.delete(user_dn
)
124 # check user info on DC1 - should be deleted
125 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
126 # check user info on DC2 - should be valid user
127 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=False)
129 # trigger replication from DC2 to DC1
130 # to check if deleted object gets restored
131 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc1
, fromDC
=self
.dnsname_dc2
, fored
=True)
132 # check user info on DC1 - should be deleted
133 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
134 # check user info on DC2 - should be valid user
135 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=False)
137 # trigger replication from DC1 to DC2
138 # to check if deleted object is replicated
139 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
, forced
=True)
140 # check user info on DC1 - should be deleted
141 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
142 # check user info on DC2 - should be deleted
143 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=True)