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"
39 class DrsDeleteObjectTestCase(drs_base
.DrsBaseTestCase
):
42 super(DrsDeleteObjectTestCase
, self
).setUp()
43 # make sure DCs are synchronized before the test
44 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
, forced
=True)
45 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc1
, fromDC
=self
.dnsname_dc2
, forced
=True)
46 # disable automatic replication temporary
47 self
._disable
_inbound
_repl
(self
.dnsname_dc1
)
48 self
._disable
_inbound
_repl
(self
.dnsname_dc2
)
51 self
._enable
_inbound
_repl
(self
.dnsname_dc1
)
52 self
._enable
_inbound
_repl
(self
.dnsname_dc2
)
53 super(DrsDeleteObjectTestCase
, self
).tearDown()
55 def _make_username(self
):
56 return "DrsDelObjUser_" + time
.strftime("%s", time
.gmtime())
58 def _check_user(self
, sam_ldb
, user_orig
, is_deleted
):
59 # search the user by guid as it may be deleted
60 guid_str
= self
._GUID
_string
(user_orig
["objectGUID"][0])
61 expression
= "(objectGUID=%s)" % guid_str
62 res
= sam_ldb
.search(base
=self
.domain_dn
,
63 expression
=expression
,
64 controls
=["show_deleted:1"])
65 self
.assertEquals(len(res
), 1)
67 # Deleted Object base DN
68 dodn
= self
._deleted
_objects
_dn
(sam_ldb
)
69 # now check properties of the user
70 name_orig
= user_orig
["cn"][0]
71 name_cur
= user_cur
["cn"][0]
73 self
.assertEquals(user_cur
["isDeleted"][0],"TRUE")
74 self
.assertTrue(not("objectCategory" in user_cur
))
75 self
.assertTrue(not("sAMAccountType" in user_cur
))
76 self
.assertTrue(dodn
in str(user_cur
["dn"]),
77 "User %s is deleted but it is not located under %s!" % (name_orig
, dodn
))
78 self
.assertEquals(name_cur
, name_orig
+ "\nDEL:" + guid_str
)
80 self
.assertTrue(not("isDeleted" in user_cur
))
81 self
.assertEquals(name_cur
, name_orig
)
82 self
.assertEquals(user_orig
["dn"], user_cur
["dn"])
83 self
.assertTrue(dodn
not in str(user_cur
["dn"]))
85 def test_ReplicateDeteleteObject(self
):
86 """Verifies how a deleted-object is replicated between two DCs.
87 This test should verify that:
88 - deleted-object is replicated properly
89 TODO: We should verify that after replication,
90 object's state to conform to a deleted-object state
91 or tombstone -object, depending on DC's features
92 It will also be great if check replPropertyMetaData."""
93 # work-out unique username to test with
94 username
= self
._make
_username
()
97 self
.ldb_dc1
.newuser(username
=username
, password
="P@sswOrd!")
98 ldb_res
= self
.ldb_dc1
.search(base
=self
.domain_dn
,
100 expression
="(samAccountName=%s)" % username
)
101 self
.assertEquals(len(ldb_res
), 1)
102 user_orig
= ldb_res
[0]
103 user_dn
= ldb_res
[0]["dn"]
105 # check user info on DC1
106 print "Testing for %s with GUID %s" % (username
, self
._GUID
_string
(user_orig
["objectGUID"][0]))
107 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=False)
109 # trigger replication from DC1 to DC2
110 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
, forced
=True)
113 self
.ldb_dc1
.delete(user_dn
)
114 # check user info on DC1 - should be deleted
115 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
116 # check user info on DC2 - should be valid user
117 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=False)
119 # trigger replication from DC2 to DC1
120 # to check if deleted object gets restored
121 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc1
, fromDC
=self
.dnsname_dc2
, forced
=True)
122 # check user info on DC1 - should be deleted
123 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
124 # check user info on DC2 - should be valid user
125 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=False)
127 # trigger replication from DC1 to DC2
128 # to check if deleted object is replicated
129 self
._net
_drs
_replicate
(DC
=self
.dnsname_dc2
, fromDC
=self
.dnsname_dc1
, forced
=True)
130 # check user info on DC1 - should be deleted
131 self
._check
_user
(sam_ldb
=self
.ldb_dc1
, user_orig
=user_orig
, is_deleted
=True)
132 # check user info on DC2 - should be deleted
133 self
._check
_user
(sam_ldb
=self
.ldb_dc2
, user_orig
=user_orig
, is_deleted
=True)