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 """Tests for samba.dsdb."""
22 from samba.credentials import Credentials
23 from samba.samdb import SamDB
24 from samba.auth import system_session
25 from samba.tests import TestCase
26 from samba.ndr import ndr_unpack, ndr_pack
27 from samba.dcerpc import drsblobs
33 class DsdbTests(TestCase):
36 super(DsdbTests, self).setUp()
37 self.lp = samba.param.LoadParm()
38 self.lp.load(os.path.join(os.path.join(self.baseprovpath(), "etc"), "smb.conf"))
39 self.creds = Credentials()
40 self.creds.guess(self.lp)
41 self.session = system_session()
42 self.samdb = SamDB(os.path.join(self.baseprovpath(), "private", "sam.ldb"),
43 session_info=self.session, credentials=self.creds,lp=self.lp)
45 def baseprovpath(self):
46 return os.path.join(os.environ['SELFTEST_PREFIX'], "dc")
48 def test_get_oid_from_attrid(self):
49 oid = self.samdb.get_oid_from_attid(591614)
50 self.assertEquals(oid, "1.2.840.113556.1.4.1790")
52 def test_error_replpropertymetadata(self):
53 res = self.samdb.search(expression="cn=Administrator",
54 scope=ldb.SCOPE_SUBTREE,
55 attrs=["replPropertyMetaData"])
56 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
57 str(res[0]["replPropertyMetaData"]))
60 # Search for Description
62 old_version = o.version
63 o.version = o.version + 1
64 replBlob = ndr_pack(repl)
67 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
68 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
70 def test_twoatt_replpropertymetadata(self):
71 res = self.samdb.search(expression="cn=Administrator",
72 scope=ldb.SCOPE_SUBTREE,
73 attrs=["replPropertyMetaData", "uSNChanged"])
74 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
75 str(res[0]["replPropertyMetaData"]))
78 # Search for Description
80 old_version = o.version
81 o.version = o.version + 1
82 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
83 replBlob = ndr_pack(repl)
86 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
87 msg["description"] = ldb.MessageElement("new val", ldb.FLAG_MOD_REPLACE, "description")
88 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
90 def test_set_replpropertymetadata(self):
91 res = self.samdb.search(expression="cn=Administrator",
92 scope=ldb.SCOPE_SUBTREE,
93 attrs=["replPropertyMetaData", "uSNChanged"])
94 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
95 str(res[0]["replPropertyMetaData"]))
98 # Search for Description
100 old_version = o.version
101 o.version = o.version + 1
102 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
103 o.originating_usn = long(str(res[0]["uSNChanged"])) + 1
104 replBlob = ndr_pack(repl)
107 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
108 self.samdb.modify(msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
110 def test_ok_get_attribute_from_attid(self):
111 self.assertEquals(self.samdb.get_attribute_from_attid(13), "description")
113 def test_ko_get_attribute_from_attid(self):
114 self.assertEquals(self.samdb.get_attribute_from_attid(11979), None)
116 def test_get_attribute_replmetadata_version(self):
117 res = self.samdb.search(expression="cn=Administrator",
118 scope=ldb.SCOPE_SUBTREE,
120 self.assertEquals(len(res), 1)
122 self.assertEqual(self.samdb.get_attribute_replmetadata_version(dn, "unicodePwd"), 1)
124 def test_set_attribute_replmetadata_version(self):
125 res = self.samdb.search(expression="cn=Administrator",
126 scope=ldb.SCOPE_SUBTREE,
128 self.assertEquals(len(res), 1)
130 version = self.samdb.get_attribute_replmetadata_version(dn, "description")
131 self.samdb.set_attribute_replmetadata_version(dn, "description", version + 2)
132 self.assertEqual(self.samdb.get_attribute_replmetadata_version(dn, "description"), version + 2)