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'], "dc")
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_twoatt_replpropertymetadata(self
):
69 res
= self
.samdb
.search(expression
="cn=Administrator",
70 scope
=ldb
.SCOPE_SUBTREE
,
71 attrs
=["replPropertyMetaData", "uSNChanged"])
72 repl
= ndr_unpack(drsblobs
.replPropertyMetaDataBlob
,
73 str(res
[0]["replPropertyMetaData"]))
76 # Search for Description
78 old_version
= o
.version
79 o
.version
= o
.version
+ 1
80 o
.local_usn
= long(str(res
[0]["uSNChanged"])) + 1
81 replBlob
= ndr_pack(repl
)
84 msg
["replPropertyMetaData"] = ldb
.MessageElement(replBlob
, ldb
.FLAG_MOD_REPLACE
, "replPropertyMetaData")
85 msg
["description"] = ldb
.MessageElement("new val", ldb
.FLAG_MOD_REPLACE
, "description")
86 self
.assertRaises(ldb
.LdbError
, self
.samdb
.modify
, msg
, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
88 def test_set_replpropertymetadata(self
):
89 res
= self
.samdb
.search(expression
="cn=Administrator",
90 scope
=ldb
.SCOPE_SUBTREE
,
91 attrs
=["replPropertyMetaData", "uSNChanged"])
92 repl
= ndr_unpack(drsblobs
.replPropertyMetaDataBlob
,
93 str(res
[0]["replPropertyMetaData"]))
96 # Search for Description
98 old_version
= o
.version
99 o
.version
= o
.version
+ 1
100 o
.local_usn
= long(str(res
[0]["uSNChanged"])) + 1
101 o
.originating_usn
= long(str(res
[0]["uSNChanged"])) + 1
102 replBlob
= ndr_pack(repl
)
105 msg
["replPropertyMetaData"] = ldb
.MessageElement(replBlob
, ldb
.FLAG_MOD_REPLACE
, "replPropertyMetaData")
106 self
.samdb
.modify(msg
, ["local_oid:1.3.6.1.4.1.7165.4.3.14:0"])
108 def test_ok_get_attribute_from_attid(self
):
109 self
.assertEquals(self
.samdb
.get_attribute_from_attid(13), "description")
111 def test_ko_get_attribute_from_attid(self
):
112 self
.assertEquals(self
.samdb
.get_attribute_from_attid(11979), None)
114 def test_get_attribute_replmetadata_version(self
):
115 res
= self
.samdb
.search(expression
="cn=Administrator",
116 scope
=ldb
.SCOPE_SUBTREE
,
118 self
.assertEquals(len(res
), 1)
120 self
.assertEqual(self
.samdb
.get_attribute_replmetadata_version(dn
, "unicodePwd"), 1)
122 def test_set_attribute_replmetadata_version(self
):
123 res
= self
.samdb
.search(expression
="cn=Administrator",
124 scope
=ldb
.SCOPE_SUBTREE
,
126 self
.assertEquals(len(res
), 1)
128 version
= self
.samdb
.get_attribute_replmetadata_version(dn
, "description")
129 self
.samdb
.set_attribute_replmetadata_version(dn
, "description", version
+ 2)
130 self
.assertEqual(self
.samdb
.get_attribute_replmetadata_version(dn
, "description"), version
+ 2)