dbcheck: Add explict tests for unknown and unsorted attributeID values
[Samba.git] / python / samba / tests / dsdb.py
bloba3b94fbe20675d093f51f4e3290a3cdd2c558041
1 # Unix SMB/CIFS implementation. Tests for dsdb
2 # Copyright (C) Matthieu Patou <mat@matws.net> 2010
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.dsdb."""
20 from samba.credentials import Credentials
21 from samba.samdb import SamDB
22 from samba.auth import system_session
23 from samba.tests import TestCase
24 from samba.ndr import ndr_unpack, ndr_pack
25 from samba.dcerpc import drsblobs
26 import ldb
27 import os
28 import samba
31 class DsdbTests(TestCase):
33 def setUp(self):
34 super(DsdbTests, self).setUp()
35 self.lp = samba.param.LoadParm()
36 self.lp.load(os.path.join(os.path.join(self.baseprovpath(), "etc"), "smb.conf"))
37 self.creds = Credentials()
38 self.creds.guess(self.lp)
39 self.session = system_session()
40 self.samdb = SamDB(os.path.join(self.baseprovpath(), "private", "sam.ldb"),
41 session_info=self.session, credentials=self.creds,lp=self.lp)
43 def baseprovpath(self):
44 return os.path.join(os.environ['SELFTEST_PREFIX'], "ad_dc_ntvfs")
46 def test_get_oid_from_attrid(self):
47 oid = self.samdb.get_oid_from_attid(591614)
48 self.assertEquals(oid, "1.2.840.113556.1.4.1790")
50 def test_error_replpropertymetadata(self):
51 res = self.samdb.search(expression="cn=Administrator",
52 scope=ldb.SCOPE_SUBTREE,
53 attrs=["replPropertyMetaData"])
54 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
55 str(res[0]["replPropertyMetaData"]))
56 ctr = repl.ctr
57 for o in ctr.array:
58 # Search for Description
59 if o.attid == 13:
60 old_version = o.version
61 o.version = o.version + 1
62 replBlob = ndr_pack(repl)
63 msg = ldb.Message()
64 msg.dn = res[0].dn
65 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
66 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
68 def test_error_replpropertymetadata_nochange(self):
69 res = self.samdb.search(expression="cn=Administrator",
70 scope=ldb.SCOPE_SUBTREE,
71 attrs=["replPropertyMetaData"])
72 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
73 str(res[0]["replPropertyMetaData"]))
74 replBlob = ndr_pack(repl)
75 msg = ldb.Message()
76 msg.dn = res[0].dn
77 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
78 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
80 def test_error_replpropertymetadata_allow_sort(self):
81 res = self.samdb.search(expression="cn=Administrator",
82 scope=ldb.SCOPE_SUBTREE,
83 attrs=["replPropertyMetaData"])
84 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
85 str(res[0]["replPropertyMetaData"]))
86 replBlob = ndr_pack(repl)
87 msg = ldb.Message()
88 msg.dn = res[0].dn
89 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
90 self.samdb.modify(msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0", "local_oid:1.3.6.1.4.1.7165.4.3.25:0"])
92 def test_twoatt_replpropertymetadata(self):
93 res = self.samdb.search(expression="cn=Administrator",
94 scope=ldb.SCOPE_SUBTREE,
95 attrs=["replPropertyMetaData", "uSNChanged"])
96 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
97 str(res[0]["replPropertyMetaData"]))
98 ctr = repl.ctr
99 for o in ctr.array:
100 # Search for Description
101 if o.attid == 13:
102 old_version = o.version
103 o.version = o.version + 1
104 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
105 replBlob = ndr_pack(repl)
106 msg = ldb.Message()
107 msg.dn = res[0].dn
108 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
109 msg["description"] = ldb.MessageElement("new val", ldb.FLAG_MOD_REPLACE, "description")
110 self.assertRaises(ldb.LdbError, self.samdb.modify, msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
112 def test_set_replpropertymetadata(self):
113 res = self.samdb.search(expression="cn=Administrator",
114 scope=ldb.SCOPE_SUBTREE,
115 attrs=["replPropertyMetaData", "uSNChanged"])
116 repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
117 str(res[0]["replPropertyMetaData"]))
118 ctr = repl.ctr
119 for o in ctr.array:
120 # Search for Description
121 if o.attid == 13:
122 old_version = o.version
123 o.version = o.version + 1
124 o.local_usn = long(str(res[0]["uSNChanged"])) + 1
125 o.originating_usn = long(str(res[0]["uSNChanged"])) + 1
126 replBlob = ndr_pack(repl)
127 msg = ldb.Message()
128 msg.dn = res[0].dn
129 msg["replPropertyMetaData"] = ldb.MessageElement(replBlob, ldb.FLAG_MOD_REPLACE, "replPropertyMetaData")
130 self.samdb.modify(msg, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
132 def test_ok_get_attribute_from_attid(self):
133 self.assertEquals(self.samdb.get_attribute_from_attid(13), "description")
135 def test_ko_get_attribute_from_attid(self):
136 self.assertEquals(self.samdb.get_attribute_from_attid(11979), None)
138 def test_get_attribute_replmetadata_version(self):
139 res = self.samdb.search(expression="cn=Administrator",
140 scope=ldb.SCOPE_SUBTREE,
141 attrs=["dn"])
142 self.assertEquals(len(res), 1)
143 dn = str(res[0].dn)
144 self.assertEqual(self.samdb.get_attribute_replmetadata_version(dn, "unicodePwd"), 1)
146 def test_set_attribute_replmetadata_version(self):
147 res = self.samdb.search(expression="cn=Administrator",
148 scope=ldb.SCOPE_SUBTREE,
149 attrs=["dn"])
150 self.assertEquals(len(res), 1)
151 dn = str(res[0].dn)
152 version = self.samdb.get_attribute_replmetadata_version(dn, "description")
153 self.samdb.set_attribute_replmetadata_version(dn, "description", version + 2)
154 self.assertEqual(self.samdb.get_attribute_replmetadata_version(dn, "description"), version + 2)