3 # Unix SMB/CIFS implementation. Tests for dsdb
4 # Copyright (C) Matthieu Patou <mat@matws.net> 2010
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from samba.credentials import Credentials
21 from samba.samdb import SamDB
22 from samba.auth import system_session
23 from testtools.testcase import TestCase
24 from samba.ndr import ndr_unpack, ndr_pack
25 from samba.dcerpc import drsblobs
31 class DsdbTests(TestCase):
35 super(DsdbTests, self).setUp()
36 self.lp = samba.param.LoadParm()
37 self.lp.load(os.path.join(os.path.join(self.baseprovpath(), "etc"), "smb.conf"))
38 self.creds = Credentials()
39 self.creds.guess(self.lp)
40 self.session = system_session()
41 self.samdb = SamDB(os.path.join(self.baseprovpath(), "private", "sam.ldb"),
42 session_info=self.session, credentials=self.creds,lp=self.lp)
45 def baseprovpath(self):
46 return os.path.join(os.environ['SELFTEST_PREFIX'], "dc")
49 def test_get_oid_from_attrid(self):
50 oid = self.samdb.get_oid_from_attid(591614)
51 self.assertEquals(oid, "1.2.840.113556.1.4.1790")
53 def test_error_replpropertymetadata(self):
54 res = self.samdb.search(expression="cn=Administrator",
55 scope=ldb.SCOPE_SUBTREE,
56 attrs=["replPropertyMetaData"])
57 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
58 str(res[0]["replPropertyMetaData"]))
61 # Search for Description
63 old_version = o.version
64 o.version = o.version + 1
65 replBlob = ndr_pack(repl)
68 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
69 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
71 def test_twoatt_replpropertymetadata(self):
72 res = self.samdb.search(expression="cn=Administrator",
73 scope=ldb.SCOPE_SUBTREE,
74 attrs=["replPropertyMetaData", "uSNChanged"])
75 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
76 str(res[0]["replPropertyMetaData"]))
79 # Search for Description
81 old_version = o.version
82 o.version = o.version + 1
83 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
84 replBlob = ndr_pack(repl)
87 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
88 msg["description"] = ldb.MessageElement("new val", ldb.FLAG_MOD_REPLACE, "description")
89 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
91 def test_set_replpropertymetadata(self):
92 res = self.samdb.search(expression="cn=Administrator",
93 scope=ldb.SCOPE_SUBTREE,
94 attrs=["replPropertyMetaData", "uSNChanged"])
95 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
96 str(res[0]["replPropertyMetaData"]))
99 # Search for Description
101 old_version = o.version
102 o.version = o.version + 1
103 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
104 o.originating_usn = long(str(res[0]["uSNChanged"])) + 1
105 replBlob = ndr_pack(repl)
108 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
109 self.samdb.modify(msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])