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
31 class DsdbTests(TestCase
):
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"]))
58 # Search for Description
60 old_version
= o
.version
61 o
.version
= o
.version
+ 1
62 replBlob
= ndr_pack(repl
)
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
)
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
)
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"]))
100 # Search for Description
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
)
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"]))
120 # Search for Description
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
)
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
,
142 self
.assertEquals(len(res
), 1)
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
,
150 self
.assertEquals(len(res
), 1)
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)