2 # -*- coding: utf-8 -*-
3 # This is a port of the original in testprogs/ejs/ldap.js
5 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008-2011
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 sys
.path
.insert(0, "bin/python")
28 from samba
.tests
.subunitrun
import SubunitOptions
, TestProgram
29 import samba
.getopt
as options
31 from samba
.auth
import system_session
32 from ldb
import SCOPE_SUBTREE
, SCOPE_ONELEVEL
, SCOPE_BASE
, LdbError
33 from ldb
import ERR_NO_SUCH_OBJECT
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
34 from ldb
import ERR_ENTRY_ALREADY_EXISTS
, ERR_UNWILLING_TO_PERFORM
35 from ldb
import ERR_NOT_ALLOWED_ON_NON_LEAF
, ERR_OTHER
, ERR_INVALID_DN_SYNTAX
36 from ldb
import ERR_NO_SUCH_ATTRIBUTE
, ERR_INVALID_ATTRIBUTE_SYNTAX
37 from ldb
import ERR_OBJECT_CLASS_VIOLATION
, ERR_NOT_ALLOWED_ON_RDN
38 from ldb
import ERR_NAMING_VIOLATION
, ERR_CONSTRAINT_VIOLATION
39 from ldb
import Message
, MessageElement
, Dn
40 from ldb
import FLAG_MOD_ADD
, FLAG_MOD_REPLACE
, FLAG_MOD_DELETE
41 from ldb
import timestring
43 from samba
.samdb
import SamDB
44 from samba
.dsdb
import (UF_NORMAL_ACCOUNT
,
45 UF_WORKSTATION_TRUST_ACCOUNT
,
46 UF_PASSWD_NOTREQD
, UF_ACCOUNTDISABLE
, ATYPE_NORMAL_ACCOUNT
,
47 ATYPE_WORKSTATION_TRUST
, SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE
,
48 SYSTEM_FLAG_CONFIG_ALLOW_RENAME
, SYSTEM_FLAG_CONFIG_ALLOW_MOVE
,
49 SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE
)
51 from samba
.ndr
import ndr_pack
, ndr_unpack
52 from samba
.dcerpc
import security
, lsa
53 from samba
.tests
import delete_force
55 parser
= optparse
.OptionParser("ldap.py [options] <host>")
56 sambaopts
= options
.SambaOptions(parser
)
57 parser
.add_option_group(sambaopts
)
58 parser
.add_option_group(options
.VersionOptions(parser
))
59 # use command line creds if available
60 credopts
= options
.CredentialsOptions(parser
)
61 parser
.add_option_group(credopts
)
62 subunitopts
= SubunitOptions(parser
)
63 parser
.add_option_group(subunitopts
)
64 opts
, args
= parser
.parse_args()
72 lp
= sambaopts
.get_loadparm()
73 creds
= credopts
.get_credentials(lp
)
75 class BasicTests(samba
.tests
.TestCase
):
78 super(BasicTests
, self
).setUp()
81 self
.base_dn
= ldb
.domain_dn()
82 self
.configuration_dn
= ldb
.get_config_basedn().get_linearized()
83 self
.schema_dn
= ldb
.get_schema_basedn().get_linearized()
84 self
.domain_sid
= security
.dom_sid(ldb
.get_domain_sid())
86 delete_force(self
.ldb
, "cn=posixuser,cn=users," + self
.base_dn
)
87 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
88 delete_force(self
.ldb
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
89 delete_force(self
.ldb
, "cn=ldaptestuser3,cn=users," + self
.base_dn
)
90 delete_force(self
.ldb
, "cn=ldaptestuser4,cn=ldaptestcontainer," + self
.base_dn
)
91 delete_force(self
.ldb
, "cn=ldaptestuser4,cn=ldaptestcontainer2," + self
.base_dn
)
92 delete_force(self
.ldb
, "cn=ldaptestuser5,cn=users," + self
.base_dn
)
93 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
94 delete_force(self
.ldb
, "cn=ldaptestgroup2,cn=users," + self
.base_dn
)
95 delete_force(self
.ldb
, "cn=ldaptestcomputer,cn=computers," + self
.base_dn
)
96 delete_force(self
.ldb
, "cn=ldaptest2computer,cn=computers," + self
.base_dn
)
97 delete_force(self
.ldb
, "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
)
98 delete_force(self
.ldb
, "cn=ldaptestutf8user èùéìòà,cn=users," + self
.base_dn
)
99 delete_force(self
.ldb
, "cn=ldaptestutf8user2 èùéìòà,cn=users," + self
.base_dn
)
100 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
101 delete_force(self
.ldb
, "cn=ldaptestcontainer2," + self
.base_dn
)
102 delete_force(self
.ldb
, "cn=parentguidtest,cn=users," + self
.base_dn
)
103 delete_force(self
.ldb
, "cn=parentguidtest,cn=testotherusers," + self
.base_dn
)
104 delete_force(self
.ldb
, "cn=testotherusers," + self
.base_dn
)
105 delete_force(self
.ldb
, "cn=ldaptestobject," + self
.base_dn
)
106 delete_force(self
.ldb
, "description=xyz,cn=users," + self
.base_dn
)
107 delete_force(self
.ldb
, "ou=testou,cn=users," + self
.base_dn
)
108 delete_force(self
.ldb
, "cn=Test Secret,cn=system," + self
.base_dn
)
109 delete_force(self
.ldb
, "cn=testtimevaluesuser1,cn=users," + self
.base_dn
)
111 def test_objectclasses(self
):
112 """Test objectClass behaviour"""
113 # Invalid objectclass specified
116 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
119 except LdbError
, (num
, _
):
120 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
122 # Invalid objectclass specified
125 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
126 "objectClass": "X" })
128 except LdbError
, (num
, _
):
129 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
131 # Invalid objectCategory specified
134 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
135 "objectClass": "person",
136 "objectCategory": self
.base_dn
})
138 except LdbError
, (num
, _
):
139 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
141 # Multi-valued "systemFlags"
144 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
145 "objectClass": "person",
146 "systemFlags": ["0", str(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE
)] })
148 except LdbError
, (num
, _
):
149 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
151 # We cannot instanciate from an abstract object class ("connectionPoint"
152 # or "leaf"). In the first case we use "connectionPoint" (subclass of
153 # "leaf") to prevent a naming violation - this returns us a
154 # "ERR_UNWILLING_TO_PERFORM" since it is not structural. In the second
155 # case however we get "ERR_OBJECT_CLASS_VIOLATION" since an abstract
156 # class is also not allowed to be auxiliary.
159 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
160 "objectClass": "connectionPoint" })
162 except LdbError
, (num
, _
):
163 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
166 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
167 "objectClass": ["person", "leaf"] })
169 except LdbError
, (num
, _
):
170 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
172 # Objects instanciated using "satisfied" abstract classes (concrete
173 # subclasses) are allowed
175 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
176 "objectClass": ["top", "leaf", "connectionPoint", "serviceConnectionPoint"] })
178 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
180 # Two disjoint top-most structural object classes aren't allowed
183 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
184 "objectClass": ["person", "container"] })
186 except LdbError
, (num
, _
):
187 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
189 # Test allowed system flags
191 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
192 "objectClass": "person",
193 "systemFlags": str(~
(SYSTEM_FLAG_CONFIG_ALLOW_RENAME | SYSTEM_FLAG_CONFIG_ALLOW_MOVE | SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE
)) })
195 res
= ldb
.search("cn=ldaptestuser,cn=users," + self
.base_dn
,
196 scope
=SCOPE_BASE
, attrs
=["systemFlags"])
197 self
.assertTrue(len(res
) == 1)
198 self
.assertEquals(res
[0]["systemFlags"][0], "0")
200 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
203 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
204 "objectClass": "person" })
206 # We can remove derivation classes of the structural objectclass
207 # but they're going to be readded afterwards
209 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
210 m
["objectClass"] = MessageElement("top", FLAG_MOD_DELETE
,
214 res
= ldb
.search("cn=ldaptestuser,cn=users," + self
.base_dn
,
215 scope
=SCOPE_BASE
, attrs
=["objectClass"])
216 self
.assertTrue(len(res
) == 1)
217 self
.assertTrue("top" in res
[0]["objectClass"])
219 # The top-most structural class cannot be deleted since there are
220 # attributes of it in use
222 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
223 m
["objectClass"] = MessageElement("person", FLAG_MOD_DELETE
,
228 except LdbError
, (num
, _
):
229 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
231 # We cannot delete classes which weren't specified
233 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
234 m
["objectClass"] = MessageElement("computer", FLAG_MOD_DELETE
,
239 except LdbError
, (num
, _
):
240 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
242 # An invalid class cannot be added
244 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
245 m
["objectClass"] = MessageElement("X", FLAG_MOD_ADD
,
250 except LdbError
, (num
, _
):
251 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
253 # We cannot add a the new top-most structural class "user" here since
254 # we are missing at least one new mandatory attribute (in this case
257 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
258 m
["objectClass"] = MessageElement("user", FLAG_MOD_ADD
,
263 except LdbError
, (num
, _
):
264 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
266 # An already specified objectclass cannot be added another time
268 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
269 m
["objectClass"] = MessageElement("person", FLAG_MOD_ADD
,
274 except LdbError
, (num
, _
):
275 self
.assertEquals(num
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
)
277 # Auxiliary classes can always be added
279 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
280 m
["objectClass"] = MessageElement("bootableDevice", FLAG_MOD_ADD
,
284 # This does not work since object class "leaf" is not auxiliary nor it
285 # stands in direct relation to "person" (and it is abstract too!)
287 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
288 m
["objectClass"] = MessageElement("leaf", FLAG_MOD_ADD
,
293 except LdbError
, (num
, _
):
294 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
296 # Objectclass replace operations can be performed as well
298 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
299 m
["objectClass"] = MessageElement(["top", "person", "bootableDevice"],
300 FLAG_MOD_REPLACE
, "objectClass")
304 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
305 m
["objectClass"] = MessageElement(["person", "bootableDevice"],
306 FLAG_MOD_REPLACE
, "objectClass")
309 # This does not work since object class "leaf" is not auxiliary nor it
310 # stands in direct relation to "person" (and it is abstract too!)
312 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
313 m
["objectClass"] = MessageElement(["top", "person", "bootableDevice",
314 "leaf"], FLAG_MOD_REPLACE
, "objectClass")
318 except LdbError
, (num
, _
):
319 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
321 # More than one change operation is allowed
323 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
324 m
.add(MessageElement("bootableDevice", FLAG_MOD_DELETE
, "objectClass"))
325 m
.add(MessageElement("bootableDevice", FLAG_MOD_ADD
, "objectClass"))
328 # We cannot remove all object classes by an empty replace
330 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
331 m
["objectClass"] = MessageElement([], FLAG_MOD_REPLACE
, "objectClass")
335 except LdbError
, (num
, _
):
336 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
339 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
340 m
["objectClass"] = MessageElement(["top", "computer"], FLAG_MOD_REPLACE
,
345 except LdbError
, (num
, _
):
346 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
348 # Classes can be removed unless attributes of them are used.
350 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
351 m
["objectClass"] = MessageElement("bootableDevice", FLAG_MOD_DELETE
,
355 res
= ldb
.search("cn=ldaptestuser,cn=users," + self
.base_dn
,
356 scope
=SCOPE_BASE
, attrs
=["objectClass"])
357 self
.assertTrue(len(res
) == 1)
358 self
.assertFalse("bootableDevice" in res
[0]["objectClass"])
361 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
362 m
["objectClass"] = MessageElement("bootableDevice", FLAG_MOD_ADD
,
366 # Add an attribute specific to the "bootableDevice" class
368 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
369 m
["bootParameter"] = MessageElement("test", FLAG_MOD_ADD
,
373 # Classes can be removed unless attributes of them are used. Now there
374 # exist such attributes on the entry.
376 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
377 m
["objectClass"] = MessageElement("bootableDevice", FLAG_MOD_DELETE
,
382 except LdbError
, (num
, _
):
383 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
385 # Remove the previously specified attribute
387 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
388 m
["bootParameter"] = MessageElement("test", FLAG_MOD_DELETE
,
392 # Classes can be removed unless attributes of them are used.
394 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
395 m
["objectClass"] = MessageElement("bootableDevice", FLAG_MOD_DELETE
,
399 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
402 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
403 "objectClass": "user" })
405 # Add a new top-most structural class "container". This does not work
406 # since it stands in no direct relation to the current one.
408 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
409 m
["objectClass"] = MessageElement("container", FLAG_MOD_ADD
,
414 except LdbError
, (num
, _
):
415 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
417 # Add a new top-most structural class "inetOrgPerson" and remove it
420 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
421 m
["objectClass"] = MessageElement("inetOrgPerson", FLAG_MOD_ADD
,
426 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
427 m
["objectClass"] = MessageElement("inetOrgPerson", FLAG_MOD_DELETE
,
431 # Replace top-most structural class to "inetOrgPerson" and reset it
434 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
435 m
["objectClass"] = MessageElement("inetOrgPerson", FLAG_MOD_REPLACE
,
440 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
441 m
["objectClass"] = MessageElement("user", FLAG_MOD_REPLACE
,
445 # Add a new auxiliary object class "posixAccount" to "ldaptestuser"
447 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
448 m
["objectClass"] = MessageElement("posixAccount", FLAG_MOD_ADD
,
452 # Be sure that "top" is the first and the (most) structural object class
453 # the last value of the "objectClass" attribute - MS-ADTS 3.1.1.1.4
454 res
= ldb
.search("cn=ldaptestuser,cn=users," + self
.base_dn
,
455 scope
=SCOPE_BASE
, attrs
=["objectClass"])
456 self
.assertTrue(len(res
) == 1)
457 self
.assertEquals(res
[0]["objectClass"][0], "top")
458 self
.assertEquals(res
[0]["objectClass"][len(res
[0]["objectClass"])-1], "user")
460 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
462 def test_system_only(self
):
463 """Test systemOnly objects"""
466 "dn": "cn=ldaptestobject," + self
.base_dn
,
467 "objectclass": "configuration"})
469 except LdbError
, (num
, _
):
470 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
474 "dn": "cn=Test Secret,cn=system," + self
.base_dn
,
475 "objectclass": "secret"})
477 except LdbError
, (num
, _
):
478 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
480 delete_force(self
.ldb
, "cn=ldaptestobject," + self
.base_dn
)
481 delete_force(self
.ldb
, "cn=Test Secret,cn=system," + self
.base_dn
)
483 # Create secret over LSA and try to change it
485 lsa_conn
= lsa
.lsarpc("ncacn_np:%s" % args
[0], lp
, creds
)
486 lsa_handle
= lsa_conn
.OpenPolicy2(system_name
="\\",
487 attr
=lsa
.ObjectAttribute(),
488 access_mask
=security
.SEC_FLAG_MAXIMUM_ALLOWED
)
489 secret_name
= lsa
.String()
490 secret_name
.string
= "G$Test"
491 sec_handle
= lsa_conn
.CreateSecret(handle
=lsa_handle
,
493 access_mask
=security
.SEC_FLAG_MAXIMUM_ALLOWED
)
494 lsa_conn
.Close(lsa_handle
)
497 m
.dn
= Dn(ldb
, "cn=Test Secret,cn=system," + self
.base_dn
)
498 m
["description"] = MessageElement("desc", FLAG_MOD_REPLACE
,
503 except LdbError
, (num
, _
):
504 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
506 delete_force(self
.ldb
, "cn=Test Secret,cn=system," + self
.base_dn
)
510 "dn": "cn=ldaptestcontainer," + self
.base_dn
,
511 "objectclass": "container",
512 "isCriticalSystemObject": "TRUE"})
514 except LdbError
, (num
, _
):
515 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
518 "dn": "cn=ldaptestcontainer," + self
.base_dn
,
519 "objectclass": "container"})
522 m
.dn
= Dn(ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
523 m
["isCriticalSystemObject"] = MessageElement("TRUE", FLAG_MOD_REPLACE
,
524 "isCriticalSystemObject")
528 except LdbError
, (num
, _
):
529 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
531 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
533 # Proof if DC SAM object has "isCriticalSystemObject" set
534 res
= self
.ldb
.search("", scope
=SCOPE_BASE
, attrs
=["serverName"])
535 self
.assertTrue(len(res
) == 1)
536 self
.assertTrue("serverName" in res
[0])
537 res
= self
.ldb
.search(res
[0]["serverName"][0], scope
=SCOPE_BASE
,
538 attrs
=["serverReference"])
539 self
.assertTrue(len(res
) == 1)
540 self
.assertTrue("serverReference" in res
[0])
541 res
= self
.ldb
.search(res
[0]["serverReference"][0], scope
=SCOPE_BASE
,
542 attrs
=["isCriticalSystemObject"])
543 self
.assertTrue(len(res
) == 1)
544 self
.assertTrue("isCriticalSystemObject" in res
[0])
545 self
.assertEquals(res
[0]["isCriticalSystemObject"][0], "TRUE")
547 def test_invalid_parent(self
):
548 """Test adding an object with invalid parent"""
551 "dn": "cn=ldaptestgroup,cn=thisdoesnotexist123,"
553 "objectclass": "group"})
555 except LdbError
, (num
, _
):
556 self
.assertEquals(num
, ERR_NO_SUCH_OBJECT
)
558 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=thisdoesnotexist123,"
563 "dn": "ou=testou,cn=users," + self
.base_dn
,
564 "objectclass": "organizationalUnit"})
566 except LdbError
, (num
, _
):
567 self
.assertEquals(num
, ERR_NAMING_VIOLATION
)
569 delete_force(self
.ldb
, "ou=testou,cn=users," + self
.base_dn
)
571 def test_invalid_attribute(self
):
572 """Test invalid attributes on schema/objectclasses"""
573 # attributes not in schema test
579 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
580 "objectclass": "group",
581 "thisdoesnotexist": "x"})
583 except LdbError
, (num
, _
):
584 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
587 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
588 "objectclass": "group"})
593 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
594 m
["thisdoesnotexist"] = MessageElement("x", FLAG_MOD_REPLACE
,
599 except LdbError
, (num
, _
):
600 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
602 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
604 # attributes not in objectclasses and mandatory attributes missing test
605 # Use here a non-SAM entry since it doesn't have special triggers
606 # associated which have an impact on the error results.
610 # mandatory attribute missing
613 "dn": "cn=ldaptestobject," + self
.base_dn
,
614 "objectclass": "ipProtocol"})
616 except LdbError
, (num
, _
):
617 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
619 # inadequate but schema-valid attribute specified
622 "dn": "cn=ldaptestobject," + self
.base_dn
,
623 "objectclass": "ipProtocol",
624 "ipProtocolNumber": "1",
627 except LdbError
, (num
, _
):
628 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
631 "dn": "cn=ldaptestobject," + self
.base_dn
,
632 "objectclass": "ipProtocol",
633 "ipProtocolNumber": "1"})
637 # inadequate but schema-valid attribute add trial
639 m
.dn
= Dn(ldb
, "cn=ldaptestobject," + self
.base_dn
)
640 m
["uid"] = MessageElement("0", FLAG_MOD_ADD
, "uid")
644 except LdbError
, (num
, _
):
645 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
647 # mandatory attribute delete trial
649 m
.dn
= Dn(ldb
, "cn=ldaptestobject," + self
.base_dn
)
650 m
["ipProtocolNumber"] = MessageElement([], FLAG_MOD_DELETE
,
655 except LdbError
, (num
, _
):
656 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
658 # mandatory attribute delete trial
660 m
.dn
= Dn(ldb
, "cn=ldaptestobject," + self
.base_dn
)
661 m
["ipProtocolNumber"] = MessageElement([], FLAG_MOD_REPLACE
,
666 except LdbError
, (num
, _
):
667 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
669 delete_force(self
.ldb
, "cn=ldaptestobject," + self
.base_dn
)
671 def test_single_valued_attributes(self
):
672 """Test single-valued attributes"""
675 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
676 "objectclass": "group",
677 "sAMAccountName": ["nam1", "nam2"]})
679 except LdbError
, (num
, _
):
680 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
683 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
684 "objectclass": "group"})
687 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
688 m
["sAMAccountName"] = MessageElement(["nam1","nam2"], FLAG_MOD_REPLACE
,
693 except LdbError
, (num
, _
):
694 self
.assertEquals(num
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
)
697 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
698 m
["sAMAccountName"] = MessageElement("testgroupXX", FLAG_MOD_REPLACE
,
703 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
704 m
["sAMAccountName"] = MessageElement("testgroupXX2", FLAG_MOD_ADD
,
709 except LdbError
, (num
, _
):
710 self
.assertEquals(num
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
)
712 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
714 def test_attribute_ranges(self
):
715 """Test attribute ranges"""
719 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
720 "objectClass": "person",
723 except LdbError
, (num
, _
):
724 self
.assertEquals(num
, ERR_INVALID_ATTRIBUTE_SYNTAX
)
729 # "dn": "cn=ldaptestuser,cn=users," + self.base_dn,
730 # "objectClass": "person",
731 # "sn": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" })
733 # except LdbError, (num, _):
734 # self.assertEquals(num, ERR_CONSTRAINT_VIOLATION)
737 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
738 "objectClass": "person" })
742 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
743 m
["sn"] = MessageElement("", FLAG_MOD_REPLACE
, "sn")
747 except LdbError
, (num
, _
):
748 self
.assertEquals(num
, ERR_INVALID_ATTRIBUTE_SYNTAX
)
752 # m.dn = Dn(ldb, "cn=ldaptestuser,cn=users," + self.base_dn)
753 # m["sn"] = MessageElement("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FLAG_MOD_REPLACE, "sn")
757 # except LdbError, (num, _):
758 # self.assertEquals(num, ERR_CONSTRAINT_VIOLATION)
761 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
762 m
["sn"] = MessageElement("x", FLAG_MOD_REPLACE
, "sn")
765 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
767 def test_empty_messages(self
):
768 """Test empty messages"""
770 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
775 except LdbError
, (num
, _
):
776 self
.assertEquals(num
, ERR_OBJECT_CLASS_VIOLATION
)
781 except LdbError
, (num
, _
):
782 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
784 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
786 def test_empty_attributes(self
):
787 """Test empty attributes"""
789 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
790 m
["objectClass"] = MessageElement("group", FLAG_MOD_ADD
, "objectClass")
791 m
["description"] = MessageElement([], FLAG_MOD_ADD
, "description")
796 except LdbError
, (num
, _
):
797 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
800 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
801 "objectclass": "group"})
804 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
805 m
["description"] = MessageElement([], FLAG_MOD_ADD
, "description")
810 except LdbError
, (num
, _
):
811 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
814 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
815 m
["description"] = MessageElement([], FLAG_MOD_REPLACE
, "description")
819 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
820 m
["description"] = MessageElement([], FLAG_MOD_DELETE
, "description")
824 except LdbError
, (num
, _
):
825 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
827 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
829 def test_instanceType(self
):
830 """Tests the 'instanceType' attribute"""
831 # The instance type is single-valued
834 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
835 "objectclass": "group",
836 "instanceType": ["0", "1"]})
838 except LdbError
, (num
, _
):
839 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
841 # The head NC flag cannot be set without the write flag
844 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
845 "objectclass": "group",
846 "instanceType": "1" })
848 except LdbError
, (num
, _
):
849 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
851 # We cannot manipulate NCs without the head NC flag
854 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
855 "objectclass": "group",
856 "instanceType": "32" })
858 except LdbError
, (num
, _
):
859 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
862 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
863 "objectclass": "group"})
866 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
867 m
["instanceType"] = MessageElement("0", FLAG_MOD_REPLACE
,
872 except LdbError
, (num
, _
):
873 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
876 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
877 m
["instanceType"] = MessageElement([], FLAG_MOD_REPLACE
,
882 except LdbError
, (num
, _
):
883 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
886 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
887 m
["instanceType"] = MessageElement([], FLAG_MOD_DELETE
, "instanceType")
891 except LdbError
, (num
, _
):
892 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
894 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
896 #only write is allowed with NC_HEAD for originating updates
899 "dn": "cn=ldaptestuser2,cn=users," + self
.base_dn
,
900 "objectclass": "user",
901 "instanceType": "3" })
903 except LdbError
, (num
, _
):
904 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
905 delete_force(self
.ldb
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
907 def test_distinguished_name(self
):
908 """Tests the 'distinguishedName' attribute"""
909 # The "dn" shortcut isn't supported
911 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
912 m
["objectClass"] = MessageElement("group", 0, "objectClass")
913 m
["dn"] = MessageElement("cn=ldaptestgroup,cn=users," + self
.base_dn
, 0,
918 except LdbError
, (num
, _
):
919 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
921 # a wrong "distinguishedName" attribute is obviously tolerated
923 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
924 "objectclass": "group",
925 "distinguishedName": "cn=ldaptest,cn=users," + self
.base_dn
})
927 # proof if the DN has been set correctly
928 res
= ldb
.search("cn=ldaptestgroup,cn=users," + self
.base_dn
,
929 scope
=SCOPE_BASE
, attrs
=["distinguishedName"])
930 self
.assertTrue(len(res
) == 1)
931 self
.assertTrue("distinguishedName" in res
[0])
932 self
.assertTrue(Dn(ldb
, res
[0]["distinguishedName"][0])
933 == Dn(ldb
, "cn=ldaptestgroup, cn=users," + self
.base_dn
))
935 # The "dn" shortcut isn't supported
937 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
938 m
["dn"] = MessageElement(
939 "cn=ldaptestgroup,cn=users," + self
.base_dn
, FLAG_MOD_REPLACE
,
944 except LdbError
, (num
, _
):
945 self
.assertEquals(num
, ERR_NO_SUCH_ATTRIBUTE
)
948 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
949 m
["distinguishedName"] = MessageElement(
950 "cn=ldaptestuser,cn=users," + self
.base_dn
, FLAG_MOD_ADD
,
956 except LdbError
, (num
, _
):
957 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
960 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
961 m
["distinguishedName"] = MessageElement(
962 "cn=ldaptestuser,cn=users," + self
.base_dn
, FLAG_MOD_REPLACE
,
968 except LdbError
, (num
, _
):
969 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
972 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
973 m
["distinguishedName"] = MessageElement(
974 "cn=ldaptestuser,cn=users," + self
.base_dn
, FLAG_MOD_DELETE
,
980 except LdbError
, (num
, _
):
981 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
983 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
985 def test_rdn_name(self
):
991 self
.ldb
.search("=,cn=users," + self
.base_dn
, scope
=SCOPE_BASE
)
993 except LdbError
, (num
, _
):
994 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
998 self
.ldb
.search("cn=,cn=users," + self
.base_dn
, scope
=SCOPE_BASE
)
1000 except LdbError
, (num
, _
):
1001 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1004 self
.ldb
.search("=ldaptestgroup,cn=users," + self
.base_dn
, scope
=SCOPE_BASE
)
1006 except LdbError
, (num
, _
):
1007 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1014 "dn": "=,cn=users," + self
.base_dn
,
1015 "objectclass": "group"})
1017 except LdbError
, (num
, _
):
1018 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1023 "dn": "=ldaptestgroup,cn=users," + self
.base_dn
,
1024 "objectclass": "group"})
1026 except LdbError
, (num
, _
):
1027 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1032 "dn": "cn=,cn=users," + self
.base_dn
,
1033 "objectclass": "group"})
1035 except LdbError
, (num
, _
):
1036 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1038 # a wrong RDN candidate
1041 "dn": "description=xyz,cn=users," + self
.base_dn
,
1042 "objectclass": "group"})
1044 except LdbError
, (num
, _
):
1045 self
.assertEquals(num
, ERR_NAMING_VIOLATION
)
1047 delete_force(self
.ldb
, "description=xyz,cn=users," + self
.base_dn
)
1049 # a wrong "name" attribute is obviously tolerated
1051 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
1052 "objectclass": "group",
1053 "name": "ldaptestgroupx"})
1055 # proof if the name has been set correctly
1056 res
= ldb
.search("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1057 scope
=SCOPE_BASE
, attrs
=["name"])
1058 self
.assertTrue(len(res
) == 1)
1059 self
.assertTrue("name" in res
[0])
1060 self
.assertTrue(res
[0]["name"][0] == "ldaptestgroup")
1066 m
.dn
= Dn(ldb
, "cn=,cn=users," + self
.base_dn
)
1067 m
["description"] = "test"
1071 except LdbError
, (num
, _
):
1072 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1078 self
.ldb
.delete("cn=,cn=users," + self
.base_dn
)
1080 except LdbError
, (num
, _
):
1081 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1087 self
.ldb
.rename("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1088 "=,cn=users," + self
.base_dn
)
1090 except LdbError
, (num
, _
):
1091 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1093 # new empty RDN name
1095 self
.ldb
.rename("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1096 "=ldaptestgroup,cn=users," + self
.base_dn
)
1098 except LdbError
, (num
, _
):
1099 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1101 # new empty RDN value
1103 self
.ldb
.rename("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1104 "cn=,cn=users," + self
.base_dn
)
1106 except LdbError
, (num
, _
):
1107 self
.assertEquals(num
, ERR_NAMING_VIOLATION
)
1109 # new wrong RDN candidate
1111 self
.ldb
.rename("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1112 "description=xyz,cn=users," + self
.base_dn
)
1114 except LdbError
, (num
, _
):
1115 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1117 delete_force(self
.ldb
, "description=xyz,cn=users," + self
.base_dn
)
1119 # old empty RDN value
1121 self
.ldb
.rename("cn=,cn=users," + self
.base_dn
,
1122 "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1124 except LdbError
, (num
, _
):
1125 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1130 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1131 m
["name"] = MessageElement("cn=ldaptestuser", FLAG_MOD_REPLACE
,
1136 except LdbError
, (num
, _
):
1137 self
.assertEquals(num
, ERR_NOT_ALLOWED_ON_RDN
)
1140 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1141 m
["cn"] = MessageElement("ldaptestuser",
1142 FLAG_MOD_REPLACE
, "cn")
1146 except LdbError
, (num
, _
):
1147 self
.assertEquals(num
, ERR_NOT_ALLOWED_ON_RDN
)
1149 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1152 # this test needs to be disabled until we really understand
1153 # what the rDN length constraints are
1154 def DISABLED_test_largeRDN(self
):
1155 """Testing large rDN (limit 64 characters)"""
1156 rdn
= "CN=a012345678901234567890123456789012345678901234567890123456789012"
1157 delete_force(self
.ldb
, "%s,%s" % (rdn
, self
.base_dn
))
1159 dn: %s,%s""" % (rdn
,self
.base_dn
) + """
1160 objectClass: container
1162 self
.ldb
.add_ldif(ldif
)
1163 delete_force(self
.ldb
, "%s,%s" % (rdn
, self
.base_dn
))
1165 rdn
= "CN=a0123456789012345678901234567890123456789012345678901234567890120"
1166 delete_force(self
.ldb
, "%s,%s" % (rdn
, self
.base_dn
))
1169 dn: %s,%s""" % (rdn
,self
.base_dn
) + """
1170 objectClass: container
1172 self
.ldb
.add_ldif(ldif
)
1174 except LdbError
, (num
, _
):
1175 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
1176 delete_force(self
.ldb
, "%s,%s" % (rdn
, self
.base_dn
))
1178 def test_rename(self
):
1179 """Tests the rename operation"""
1181 # cannot rename to be a child of itself
1182 ldb
.rename(self
.base_dn
, "dc=test," + self
.base_dn
)
1184 except LdbError
, (num
, _
):
1185 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1189 ldb
.rename("cn=ldaptestuser2,cn=users," + self
.base_dn
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
1191 except LdbError
, (num
, _
):
1192 self
.assertEquals(num
, ERR_NO_SUCH_OBJECT
)
1195 "dn": "cn=ldaptestuser2,cn=users," + self
.base_dn
,
1196 "objectclass": "user" })
1198 ldb
.rename("cn=ldaptestuser2,cn=users," + self
.base_dn
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
1199 ldb
.rename("cn=ldaptestuser2,cn=users," + self
.base_dn
, "cn=ldaptestuser3,cn=users," + self
.base_dn
)
1200 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "cn=ldaptestUSER3,cn=users," + self
.base_dn
)
1203 # containment problem: a user entry cannot contain user entries
1204 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "cn=ldaptestuser4,cn=ldaptestuser3,cn=users," + self
.base_dn
)
1206 except LdbError
, (num
, _
):
1207 self
.assertEquals(num
, ERR_NAMING_VIOLATION
)
1211 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "cn=ldaptestuser3,cn=people,cn=users," + self
.base_dn
)
1213 except LdbError
, (num
, _
):
1214 self
.assertEquals(num
, ERR_OTHER
)
1217 # invalid target DN syntax
1218 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, ",cn=users," + self
.base_dn
)
1220 except LdbError
, (num
, _
):
1221 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1225 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "ou=ldaptestuser3,cn=users," + self
.base_dn
)
1227 except LdbError
, (num
, _
):
1228 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1230 delete_force(self
.ldb
, "cn=ldaptestuser3,cn=users," + self
.base_dn
)
1232 # Performs some "systemFlags" testing
1234 # Move failing since no "SYSTEM_FLAG_CONFIG_ALLOW_MOVE"
1236 ldb
.rename("CN=DisplaySpecifiers," + self
.configuration_dn
, "CN=DisplaySpecifiers,CN=Services," + self
.configuration_dn
)
1238 except LdbError
, (num
, _
):
1239 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1241 # Limited move failing since no "SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE"
1243 ldb
.rename("CN=Directory Service,CN=Windows NT,CN=Services," + self
.configuration_dn
, "CN=Directory Service,CN=RRAS,CN=Services," + self
.configuration_dn
)
1245 except LdbError
, (num
, _
):
1246 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1248 # Rename failing since no "SYSTEM_FLAG_CONFIG_ALLOW_RENAME"
1250 ldb
.rename("CN=DisplaySpecifiers," + self
.configuration_dn
, "CN=DisplaySpecifiers2," + self
.configuration_dn
)
1252 except LdbError
, (num
, _
):
1253 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1255 # It's not really possible to test moves on the schema partition since
1256 # there don't exist subcontainers on it.
1258 # Rename failing since "SYSTEM_FLAG_SCHEMA_BASE_OBJECT"
1260 ldb
.rename("CN=Top," + self
.schema_dn
, "CN=Top2," + self
.schema_dn
)
1262 except LdbError
, (num
, _
):
1263 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1265 # Move failing since "SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE"
1267 ldb
.rename("CN=Users," + self
.base_dn
, "CN=Users,CN=Computers," + self
.base_dn
)
1269 except LdbError
, (num
, _
):
1270 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1272 # Rename failing since "SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME"
1274 ldb
.rename("CN=Users," + self
.base_dn
, "CN=Users2," + self
.base_dn
)
1276 except LdbError
, (num
, _
):
1277 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1279 # Performs some other constraints testing
1282 ldb
.rename("CN=Policies,CN=System," + self
.base_dn
, "CN=Users2," + self
.base_dn
)
1284 except LdbError
, (num
, _
):
1285 self
.assertEquals(num
, ERR_OTHER
)
1287 def test_rename_twice(self
):
1288 """Tests the rename operation twice - this corresponds to a past bug"""
1290 "dn": "cn=ldaptestuser5,cn=users," + self
.base_dn
,
1291 "objectclass": "user" })
1293 ldb
.rename("cn=ldaptestuser5,cn=users," + self
.base_dn
, "cn=ldaptestUSER5,cn=users," + self
.base_dn
)
1294 delete_force(self
.ldb
, "cn=ldaptestuser5,cn=users," + self
.base_dn
)
1296 "dn": "cn=ldaptestuser5,cn=users," + self
.base_dn
,
1297 "objectclass": "user" })
1298 ldb
.rename("cn=ldaptestuser5,cn=Users," + self
.base_dn
, "cn=ldaptestUSER5,cn=users," + self
.base_dn
)
1299 res
= ldb
.search(expression
="cn=ldaptestuser5")
1300 self
.assertEquals(len(res
), 1, "Wrong number of hits for cn=ldaptestuser5")
1301 res
= ldb
.search(expression
="(&(cn=ldaptestuser5)(objectclass=user))")
1302 self
.assertEquals(len(res
), 1, "Wrong number of hits for (&(cn=ldaptestuser5)(objectclass=user))")
1303 delete_force(self
.ldb
, "cn=ldaptestuser5,cn=users," + self
.base_dn
)
1305 def test_objectGUID(self
):
1306 """Test objectGUID behaviour"""
1307 # The objectGUID cannot directly be set
1309 self
.ldb
.add_ldif("""
1310 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1311 objectClass: container
1312 objectGUID: bd3480c9-58af-4cd8-92df-bc4a18b6e44d
1315 except LdbError
, (num
, _
):
1316 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1319 "dn": "cn=ldaptestcontainer," + self
.base_dn
,
1320 "objectClass": "container" })
1322 # The objectGUID cannot directly be changed
1324 self
.ldb
.modify_ldif("""
1325 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1328 objectGUID: bd3480c9-58af-4cd8-92df-bc4a18b6e44d
1331 except LdbError
, (num
, _
):
1332 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
1334 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
1336 def test_parentGUID(self
):
1337 """Test parentGUID behaviour"""
1339 "dn": "cn=parentguidtest,cn=users," + self
.base_dn
,
1340 "objectclass":"user",
1341 "samaccountname":"parentguidtest"})
1342 res1
= ldb
.search(base
="cn=parentguidtest,cn=users," + self
.base_dn
, scope
=SCOPE_BASE
,
1343 attrs
=["parentGUID", "samaccountname"])
1344 res2
= ldb
.search(base
="cn=users," + self
.base_dn
,scope
=SCOPE_BASE
,
1345 attrs
=["objectGUID"])
1346 res3
= ldb
.search(base
=self
.base_dn
, scope
=SCOPE_BASE
,
1347 attrs
=["parentGUID"])
1348 res4
= ldb
.search(base
=self
.configuration_dn
, scope
=SCOPE_BASE
,
1349 attrs
=["parentGUID"])
1350 res5
= ldb
.search(base
=self
.schema_dn
, scope
=SCOPE_BASE
,
1351 attrs
=["parentGUID"])
1353 """Check if the parentGUID is valid """
1354 self
.assertEquals(res1
[0]["parentGUID"], res2
[0]["objectGUID"])
1356 """Check if it returns nothing when there is no parent object - default NC"""
1357 has_parentGUID
= False
1358 for key
in res3
[0].keys():
1359 if key
== "parentGUID":
1360 has_parentGUID
= True
1362 self
.assertFalse(has_parentGUID
)
1364 """Check if it returns nothing when there is no parent object - configuration NC"""
1365 has_parentGUID
= False
1366 for key
in res4
[0].keys():
1367 if key
== "parentGUID":
1368 has_parentGUID
= True
1370 self
.assertFalse(has_parentGUID
)
1372 """Check if it returns nothing when there is no parent object - schema NC"""
1373 has_parentGUID
= False
1374 for key
in res5
[0].keys():
1375 if key
== "parentGUID":
1376 has_parentGUID
= True
1378 self
.assertFalse(has_parentGUID
)
1380 """Ensures that if you look for another object attribute after the constructed
1381 parentGUID, it will return correctly"""
1382 has_another_attribute
= False
1383 for key
in res1
[0].keys():
1384 if key
== "sAMAccountName":
1385 has_another_attribute
= True
1387 self
.assertTrue(has_another_attribute
)
1388 self
.assertTrue(len(res1
[0]["samaccountname"]) == 1)
1389 self
.assertEquals(res1
[0]["samaccountname"][0], "parentguidtest")
1391 # Testing parentGUID behaviour on rename\
1394 "dn": "cn=testotherusers," + self
.base_dn
,
1395 "objectclass":"container"})
1396 res1
= ldb
.search(base
="cn=testotherusers," + self
.base_dn
,scope
=SCOPE_BASE
,
1397 attrs
=["objectGUID"])
1398 ldb
.rename("cn=parentguidtest,cn=users," + self
.base_dn
,
1399 "cn=parentguidtest,cn=testotherusers," + self
.base_dn
)
1400 res2
= ldb
.search(base
="cn=parentguidtest,cn=testotherusers," + self
.base_dn
,
1402 attrs
=["parentGUID"])
1403 self
.assertEquals(res1
[0]["objectGUID"], res2
[0]["parentGUID"])
1405 delete_force(self
.ldb
, "cn=parentguidtest,cn=testotherusers," + self
.base_dn
)
1406 delete_force(self
.ldb
, "cn=testotherusers," + self
.base_dn
)
1408 def test_usnChanged(self
):
1409 """Test usnChanged behaviour"""
1412 "dn": "cn=ldaptestcontainer," + self
.base_dn
,
1413 "objectClass": "container" })
1415 res
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1417 attrs
=["objectGUID", "uSNCreated", "uSNChanged", "whenCreated", "whenChanged", "description"])
1418 self
.assertTrue(len(res
) == 1)
1419 self
.assertFalse("description" in res
[0])
1420 self
.assertTrue("objectGUID" in res
[0])
1421 self
.assertTrue("uSNCreated" in res
[0])
1422 self
.assertTrue("uSNChanged" in res
[0])
1423 self
.assertTrue("whenCreated" in res
[0])
1424 self
.assertTrue("whenChanged" in res
[0])
1426 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
1428 # All this attributes are specificable on add operations
1430 "dn": "cn=ldaptestcontainer," + self
.base_dn
,
1431 "objectclass": "container",
1434 "whenCreated": timestring(long(time
.time())),
1435 "whenChanged": timestring(long(time
.time())) })
1437 res
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1439 attrs
=["objectGUID", "uSNCreated", "uSNChanged", "whenCreated", "whenChanged", "description"])
1440 self
.assertTrue(len(res
) == 1)
1441 self
.assertFalse("description" in res
[0])
1442 self
.assertTrue("objectGUID" in res
[0])
1443 self
.assertTrue("uSNCreated" in res
[0])
1444 self
.assertFalse(res
[0]["uSNCreated"][0] == "1") # these are corrected
1445 self
.assertTrue("uSNChanged" in res
[0])
1446 self
.assertFalse(res
[0]["uSNChanged"][0] == "1") # these are corrected
1447 self
.assertTrue("whenCreated" in res
[0])
1448 self
.assertTrue("whenChanged" in res
[0])
1451 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1453 replace: description
1456 res2
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1458 attrs
=["uSNCreated", "uSNChanged", "description"])
1459 self
.assertTrue(len(res
) == 1)
1460 self
.assertFalse("description" in res2
[0])
1461 self
.assertEqual(res
[0]["usnCreated"], res2
[0]["usnCreated"])
1462 self
.assertEqual(res
[0]["usnCreated"], res2
[0]["usnChanged"])
1463 self
.assertEqual(res
[0]["usnChanged"], res2
[0]["usnChanged"])
1466 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1468 replace: description
1472 res3
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1474 attrs
=["uSNCreated", "uSNChanged", "description"])
1475 self
.assertTrue(len(res
) == 1)
1476 self
.assertTrue("description" in res3
[0])
1477 self
.assertEqual("test", str(res3
[0]["description"][0]))
1478 self
.assertEqual(res
[0]["usnCreated"], res3
[0]["usnCreated"])
1479 self
.assertNotEqual(res
[0]["usnCreated"], res3
[0]["usnChanged"])
1480 self
.assertNotEqual(res
[0]["usnChanged"], res3
[0]["usnChanged"])
1483 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1485 replace: description
1489 res4
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1491 attrs
=["uSNCreated", "uSNChanged", "description"])
1492 self
.assertTrue(len(res
) == 1)
1493 self
.assertTrue("description" in res4
[0])
1494 self
.assertEqual("test", str(res4
[0]["description"][0]))
1495 self
.assertEqual(res
[0]["usnCreated"], res4
[0]["usnCreated"])
1496 self
.assertNotEqual(res3
[0]["usnCreated"], res4
[0]["usnChanged"])
1497 self
.assertEqual(res3
[0]["usnChanged"], res4
[0]["usnChanged"])
1500 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1502 replace: description
1506 res5
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1508 attrs
=["uSNCreated", "uSNChanged", "description"])
1509 self
.assertTrue(len(res
) == 1)
1510 self
.assertTrue("description" in res5
[0])
1511 self
.assertEqual("test2", str(res5
[0]["description"][0]))
1512 self
.assertEqual(res
[0]["usnCreated"], res5
[0]["usnCreated"])
1513 self
.assertNotEqual(res3
[0]["usnChanged"], res5
[0]["usnChanged"])
1516 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1522 res6
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1524 attrs
=["uSNCreated", "uSNChanged", "description"])
1525 self
.assertTrue(len(res
) == 1)
1526 self
.assertFalse("description" in res6
[0])
1527 self
.assertEqual(res
[0]["usnCreated"], res6
[0]["usnCreated"])
1528 self
.assertNotEqual(res5
[0]["usnChanged"], res6
[0]["usnChanged"])
1531 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1537 res7
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1539 attrs
=["uSNCreated", "uSNChanged", "description"])
1540 self
.assertTrue(len(res
) == 1)
1541 self
.assertTrue("description" in res7
[0])
1542 self
.assertEqual("test3", str(res7
[0]["description"][0]))
1543 self
.assertEqual(res
[0]["usnCreated"], res7
[0]["usnCreated"])
1544 self
.assertNotEqual(res6
[0]["usnChanged"], res7
[0]["usnChanged"])
1547 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
1552 res8
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
1554 attrs
=["uSNCreated", "uSNChanged", "description"])
1555 self
.assertTrue(len(res
) == 1)
1556 self
.assertFalse("description" in res8
[0])
1557 self
.assertEqual(res
[0]["usnCreated"], res8
[0]["usnCreated"])
1558 self
.assertNotEqual(res7
[0]["usnChanged"], res8
[0]["usnChanged"])
1560 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
1562 def test_groupType_int32(self
):
1563 """Test groupType (int32) behaviour (should appear to be casted to a 32 bit signed integer before comparsion)"""
1565 res1
= ldb
.search(base
=self
.base_dn
, scope
=SCOPE_SUBTREE
,
1566 attrs
=["groupType"], expression
="groupType=2147483653")
1568 res2
= ldb
.search(base
=self
.base_dn
, scope
=SCOPE_SUBTREE
,
1569 attrs
=["groupType"], expression
="groupType=-2147483643")
1571 self
.assertEquals(len(res1
), len(res2
))
1573 self
.assertTrue(res1
.count
> 0)
1575 self
.assertEquals(res1
[0]["groupType"][0], "-2147483643")
1577 def test_linked_attributes(self
):
1578 """This tests the linked attribute behaviour"""
1581 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
1582 "objectclass": "group"})
1584 # This should not work since "memberOf" is linked to "member"
1587 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
1588 "objectclass": "user",
1589 "memberOf": "cn=ldaptestgroup,cn=users," + self
.base_dn
})
1590 except LdbError
, (num
, _
):
1591 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1594 "dn": "cn=ldaptestuser,cn=users," + self
.base_dn
,
1595 "objectclass": "user"})
1598 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
1599 m
["memberOf"] = MessageElement("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1600 FLAG_MOD_ADD
, "memberOf")
1604 except LdbError
, (num
, _
):
1605 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1608 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1609 m
["member"] = MessageElement("cn=ldaptestuser,cn=users," + self
.base_dn
,
1610 FLAG_MOD_ADD
, "member")
1614 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
1615 m
["memberOf"] = MessageElement("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1616 FLAG_MOD_REPLACE
, "memberOf")
1620 except LdbError
, (num
, _
):
1621 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1624 m
.dn
= Dn(ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
1625 m
["memberOf"] = MessageElement("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1626 FLAG_MOD_DELETE
, "memberOf")
1630 except LdbError
, (num
, _
):
1631 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1634 m
.dn
= Dn(ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1635 m
["member"] = MessageElement("cn=ldaptestuser,cn=users," + self
.base_dn
,
1636 FLAG_MOD_DELETE
, "member")
1639 # This should yield no results since the member attribute for
1640 # "ldaptestuser" should have been deleted
1641 res1
= ldb
.search("cn=ldaptestgroup, cn=users," + self
.base_dn
,
1643 expression
="(member=cn=ldaptestuser,cn=users," + self
.base_dn
+ ")",
1645 self
.assertTrue(len(res1
) == 0)
1647 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1650 "dn": "cn=ldaptestgroup,cn=users," + self
.base_dn
,
1651 "objectclass": "group",
1652 "member": "cn=ldaptestuser,cn=users," + self
.base_dn
})
1654 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
1656 # Make sure that the "member" attribute for "ldaptestuser" has been
1658 res
= ldb
.search("cn=ldaptestgroup,cn=users," + self
.base_dn
,
1659 scope
=SCOPE_BASE
, attrs
=["member"])
1660 self
.assertTrue(len(res
) == 1)
1661 self
.assertFalse("member" in res
[0])
1663 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
1665 def test_wkguid(self
):
1666 """Test Well known GUID behaviours (including DN+Binary)"""
1668 res
= self
.ldb
.search(base
=("<WKGUID=ab1d30f3768811d1aded00c04fd8d5cd,%s>" % self
.base_dn
), scope
=SCOPE_BASE
, attrs
=[])
1669 self
.assertEquals(len(res
), 1)
1671 res2
= self
.ldb
.search(scope
=SCOPE_BASE
, attrs
=["wellKnownObjects"], expression
=("wellKnownObjects=B:32:ab1d30f3768811d1aded00c04fd8d5cd:%s" % res
[0].dn
))
1672 self
.assertEquals(len(res2
), 1)
1674 # Prove that the matching rule is over the whole DN+Binary
1675 res2
= self
.ldb
.search(scope
=SCOPE_BASE
, attrs
=["wellKnownObjects"], expression
=("wellKnownObjects=B:32:ab1d30f3768811d1aded00c04fd8d5cd"))
1676 self
.assertEquals(len(res2
), 0)
1677 # Prove that the matching rule is over the whole DN+Binary
1678 res2
= self
.ldb
.search(scope
=SCOPE_BASE
, attrs
=["wellKnownObjects"], expression
=("wellKnownObjects=%s") % res
[0].dn
)
1679 self
.assertEquals(len(res2
), 0)
1681 def test_subschemasubentry(self
):
1682 """Test subSchemaSubEntry appears when requested, but not when not requested"""
1684 res
= self
.ldb
.search(base
=self
.base_dn
, scope
=SCOPE_BASE
, attrs
=["subSchemaSubEntry"])
1685 self
.assertEquals(len(res
), 1)
1686 self
.assertEquals(res
[0]["subSchemaSubEntry"][0], "CN=Aggregate,"+self
.schema_dn
)
1688 res
= self
.ldb
.search(base
=self
.base_dn
, scope
=SCOPE_BASE
, attrs
=["*"])
1689 self
.assertEquals(len(res
), 1)
1690 self
.assertTrue("subScheamSubEntry" not in res
[0])
1698 "dn": "cn=ldaptestuser,cn=uSers," + self
.base_dn
,
1699 "objectclass": "user",
1700 "cN": "LDAPtestUSER",
1701 "givenname": "ldap",
1705 "dn": "cn=ldaptestgroup,cn=uSers," + self
.base_dn
,
1706 "objectclass": "group",
1707 "member": "cn=ldaptestuser,cn=useRs," + self
.base_dn
})
1710 "dn": "cn=ldaptestcomputer,cn=computers," + self
.base_dn
,
1711 "objectclass": "computer",
1712 "cN": "LDAPtestCOMPUTER"})
1714 ldb
.add({"dn": "cn=ldaptest2computer,cn=computers," + self
.base_dn
,
1715 "objectClass": "computer",
1716 "cn": "LDAPtest2COMPUTER",
1717 "userAccountControl": str(UF_WORKSTATION_TRUST_ACCOUNT
),
1718 "displayname": "ldap testy"})
1721 ldb
.add({"dn": "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
,
1722 "objectClass": "computer",
1723 "cn": "LDAPtest2COMPUTER"
1726 except LdbError
, (num
, _
):
1727 self
.assertEquals(num
, ERR_INVALID_DN_SYNTAX
)
1730 ldb
.add({"dn": "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
,
1731 "objectClass": "computer",
1732 "cn": "ldaptestcomputer3",
1733 "sAMAccountType": str(ATYPE_NORMAL_ACCOUNT
)
1736 except LdbError
, (num
, _
):
1737 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
1739 ldb
.add({"dn": "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
,
1740 "objectClass": "computer",
1741 "cn": "LDAPtestCOMPUTER3"
1744 # Testing ldb.search for (&(cn=ldaptestcomputer3)(objectClass=user))
1745 res
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestcomputer3)(objectClass=user))")
1746 self
.assertEquals(len(res
), 1, "Found only %d for (&(cn=ldaptestcomputer3)(objectClass=user))" % len(res
))
1748 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestcomputer3,CN=Computers," + self
.base_dn
))
1749 self
.assertEquals(res
[0]["cn"][0], "ldaptestcomputer3")
1750 self
.assertEquals(res
[0]["name"][0], "ldaptestcomputer3")
1751 self
.assertEquals(res
[0]["objectClass"][0], "top")
1752 self
.assertEquals(res
[0]["objectClass"][1], "person")
1753 self
.assertEquals(res
[0]["objectClass"][2], "organizationalPerson")
1754 self
.assertEquals(res
[0]["objectClass"][3], "user")
1755 self
.assertEquals(res
[0]["objectClass"][4], "computer")
1756 self
.assertTrue("objectGUID" in res
[0])
1757 self
.assertTrue("whenCreated" in res
[0])
1758 self
.assertEquals(res
[0]["objectCategory"][0], ("CN=Computer,%s" % ldb
.get_schema_basedn()))
1759 self
.assertEquals(int(res
[0]["primaryGroupID"][0]), 513)
1760 self
.assertEquals(int(res
[0]["sAMAccountType"][0]), ATYPE_NORMAL_ACCOUNT
)
1761 self
.assertEquals(int(res
[0]["userAccountControl"][0]), UF_NORMAL_ACCOUNT | UF_PASSWD_NOTREQD | UF_ACCOUNTDISABLE
)
1763 delete_force(self
.ldb
, "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
)
1765 # Testing attribute or value exists behaviour
1768 dn: cn=ldaptest2computer,cn=computers,""" + self
.base_dn
+ """
1770 replace: servicePrincipalName
1771 servicePrincipalName: host/ldaptest2computer
1772 servicePrincipalName: host/ldaptest2computer
1773 servicePrincipalName: cifs/ldaptest2computer
1776 except LdbError
, (num
, msg
):
1777 self
.assertEquals(num
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
)
1780 dn: cn=ldaptest2computer,cn=computers,""" + self
.base_dn
+ """
1782 replace: servicePrincipalName
1783 servicePrincipalName: host/ldaptest2computer
1784 servicePrincipalName: cifs/ldaptest2computer
1788 dn: cn=ldaptest2computer,cn=computers,""" + self
.base_dn
+ """
1790 add: servicePrincipalName
1791 servicePrincipalName: host/ldaptest2computer
1794 except LdbError
, (num
, msg
):
1795 self
.assertEquals(num
, ERR_ATTRIBUTE_OR_VALUE_EXISTS
)
1797 # Testing ranged results
1799 dn: cn=ldaptest2computer,cn=computers,""" + self
.base_dn
+ """
1801 replace: servicePrincipalName
1805 dn: cn=ldaptest2computer,cn=computers,""" + self
.base_dn
+ """
1807 add: servicePrincipalName
1808 servicePrincipalName: host/ldaptest2computer0
1809 servicePrincipalName: host/ldaptest2computer1
1810 servicePrincipalName: host/ldaptest2computer2
1811 servicePrincipalName: host/ldaptest2computer3
1812 servicePrincipalName: host/ldaptest2computer4
1813 servicePrincipalName: host/ldaptest2computer5
1814 servicePrincipalName: host/ldaptest2computer6
1815 servicePrincipalName: host/ldaptest2computer7
1816 servicePrincipalName: host/ldaptest2computer8
1817 servicePrincipalName: host/ldaptest2computer9
1818 servicePrincipalName: host/ldaptest2computer10
1819 servicePrincipalName: host/ldaptest2computer11
1820 servicePrincipalName: host/ldaptest2computer12
1821 servicePrincipalName: host/ldaptest2computer13
1822 servicePrincipalName: host/ldaptest2computer14
1823 servicePrincipalName: host/ldaptest2computer15
1824 servicePrincipalName: host/ldaptest2computer16
1825 servicePrincipalName: host/ldaptest2computer17
1826 servicePrincipalName: host/ldaptest2computer18
1827 servicePrincipalName: host/ldaptest2computer19
1828 servicePrincipalName: host/ldaptest2computer20
1829 servicePrincipalName: host/ldaptest2computer21
1830 servicePrincipalName: host/ldaptest2computer22
1831 servicePrincipalName: host/ldaptest2computer23
1832 servicePrincipalName: host/ldaptest2computer24
1833 servicePrincipalName: host/ldaptest2computer25
1834 servicePrincipalName: host/ldaptest2computer26
1835 servicePrincipalName: host/ldaptest2computer27
1836 servicePrincipalName: host/ldaptest2computer28
1837 servicePrincipalName: host/ldaptest2computer29
1840 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
,
1841 attrs
=["servicePrincipalName;range=0-*"])
1842 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1843 self
.assertEquals(len(res
[0]["servicePrincipalName;range=0-*"]), 30)
1845 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=0-19"])
1846 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1847 self
.assertEquals(len(res
[0]["servicePrincipalName;range=0-19"]), 20)
1850 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=0-30"])
1851 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1852 self
.assertEquals(len(res
[0]["servicePrincipalName;range=0-*"]), 30)
1854 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=0-40"])
1855 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1856 self
.assertEquals(len(res
[0]["servicePrincipalName;range=0-*"]), 30)
1858 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=30-40"])
1859 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1860 self
.assertEquals(len(res
[0]["servicePrincipalName;range=30-*"]), 0)
1863 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=10-40"])
1864 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1865 self
.assertEquals(len(res
[0]["servicePrincipalName;range=10-*"]), 20)
1866 # pos_11 = res[0]["servicePrincipalName;range=10-*"][18]
1868 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=11-40"])
1869 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1870 self
.assertEquals(len(res
[0]["servicePrincipalName;range=11-*"]), 19)
1871 # self.assertEquals((res[0]["servicePrincipalName;range=11-*"][18]), pos_11)
1873 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName;range=11-15"])
1874 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1875 self
.assertEquals(len(res
[0]["servicePrincipalName;range=11-15"]), 5)
1876 # self.assertEquals(res[0]["servicePrincipalName;range=11-15"][4], pos_11)
1878 res
= ldb
.search(self
.base_dn
, expression
="(cn=ldaptest2computer))", scope
=SCOPE_SUBTREE
, attrs
=["servicePrincipalName"])
1879 self
.assertEquals(len(res
), 1, "Could not find (cn=ldaptest2computer)")
1880 self
.assertEquals(len(res
[0]["servicePrincipalName"]), 30)
1881 # self.assertEquals(res[0]["servicePrincipalName"][18], pos_11)
1883 delete_force(self
.ldb
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
1885 "dn": "cn=ldaptestuser2,cn=useRs," + self
.base_dn
,
1886 "objectClass": "user",
1887 "cn": "LDAPtestUSER2",
1888 "givenname": "testy",
1889 "sn": "ldap user2"})
1891 # Testing Ambigious Name Resolution
1892 # Testing ldb.search for (&(anr=ldap testy)(objectClass=user))
1893 res
= ldb
.search(expression
="(&(anr=ldap testy)(objectClass=user))")
1894 self
.assertEquals(len(res
), 3, "Found only %d of 3 for (&(anr=ldap testy)(objectClass=user))" % len(res
))
1896 # Testing ldb.search for (&(anr=testy ldap)(objectClass=user))
1897 res
= ldb
.search(expression
="(&(anr=testy ldap)(objectClass=user))")
1898 self
.assertEquals(len(res
), 2, "Found only %d of 2 for (&(anr=testy ldap)(objectClass=user))" % len(res
))
1900 # Testing ldb.search for (&(anr=ldap)(objectClass=user))
1901 res
= ldb
.search(expression
="(&(anr=ldap)(objectClass=user))")
1902 self
.assertEquals(len(res
), 4, "Found only %d of 4 for (&(anr=ldap)(objectClass=user))" % len(res
))
1904 # Testing ldb.search for (&(anr==ldap)(objectClass=user))
1905 res
= ldb
.search(expression
="(&(anr==ldap)(objectClass=user))")
1906 self
.assertEquals(len(res
), 1, "Could not find (&(anr==ldap)(objectClass=user)). Found only %d for (&(anr=ldap)(objectClass=user))" % len(res
))
1908 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser,CN=Users," + self
.base_dn
))
1909 self
.assertEquals(res
[0]["cn"][0], "ldaptestuser")
1910 self
.assertEquals(str(res
[0]["name"]), "ldaptestuser")
1912 # Testing ldb.search for (&(anr=testy)(objectClass=user))
1913 res
= ldb
.search(expression
="(&(anr=testy)(objectClass=user))")
1914 self
.assertEquals(len(res
), 2, "Found only %d for (&(anr=testy)(objectClass=user))" % len(res
))
1916 # Testing ldb.search for (&(anr=testy ldap)(objectClass=user))
1917 res
= ldb
.search(expression
="(&(anr=testy ldap)(objectClass=user))")
1918 self
.assertEquals(len(res
), 2, "Found only %d for (&(anr=testy ldap)(objectClass=user))" % len(res
))
1920 # Testing ldb.search for (&(anr==testy ldap)(objectClass=user))
1921 # this test disabled for the moment, as anr with == tests are not understood
1922 # res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))")
1923 # self.assertEquals(len(res), 1, "Found only %d for (&(anr==testy ldap)(objectClass=user))" % len(res))
1925 # self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn))
1926 # self.assertEquals(res[0]["cn"][0], "ldaptestuser")
1927 # self.assertEquals(res[0]["name"][0], "ldaptestuser")
1929 # Testing ldb.search for (&(anr==testy ldap)(objectClass=user))
1930 # res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))")
1931 # self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap)(objectClass=user))")
1933 # self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn))
1934 # self.assertEquals(res[0]["cn"][0], "ldaptestuser")
1935 # self.assertEquals(res[0]["name"][0], "ldaptestuser")
1937 # Testing ldb.search for (&(anr=testy ldap user)(objectClass=user))
1938 res
= ldb
.search(expression
="(&(anr=testy ldap user)(objectClass=user))")
1939 self
.assertEquals(len(res
), 1, "Could not find (&(anr=testy ldap user)(objectClass=user))")
1941 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
1942 self
.assertEquals(str(res
[0]["cn"]), "ldaptestuser2")
1943 self
.assertEquals(str(res
[0]["name"]), "ldaptestuser2")
1945 # Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user))
1946 # res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))")
1947 # self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))")
1949 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
1950 self
.assertEquals(str(res
[0]["cn"]), "ldaptestuser2")
1951 self
.assertEquals(str(res
[0]["name"]), "ldaptestuser2")
1953 # Testing ldb.search for (&(anr==ldap user2)(objectClass=user))
1954 # res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))")
1955 # self.assertEquals(len(res), 1, "Could not find (&(anr==ldap user2)(objectClass=user))")
1957 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
1958 self
.assertEquals(str(res
[0]["cn"]), "ldaptestuser2")
1959 self
.assertEquals(str(res
[0]["name"]), "ldaptestuser2")
1961 # Testing ldb.search for (&(anr==not ldap user2)(objectClass=user))
1962 # res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))")
1963 # self.assertEquals(len(res), 0, "Must not find (&(anr==not ldap user2)(objectClass=user))")
1965 # Testing ldb.search for (&(anr=not ldap user2)(objectClass=user))
1966 res
= ldb
.search(expression
="(&(anr=not ldap user2)(objectClass=user))")
1967 self
.assertEquals(len(res
), 0, "Must not find (&(anr=not ldap user2)(objectClass=user))")
1969 # Testing ldb.search for (&(anr="testy ldap")(objectClass=user)) (ie, with quotes)
1970 # res = ldb.search(expression="(&(anr==\"testy ldap\")(objectClass=user))")
1971 # self.assertEquals(len(res), 0, "Found (&(anr==\"testy ldap\")(objectClass=user))")
1975 attrs
= ["objectGUID", "objectSid"]
1976 # Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))
1977 res_user
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestUSer2)(objectClass=user))", scope
=SCOPE_SUBTREE
, attrs
=attrs
)
1978 self
.assertEquals(len(res_user
), 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))")
1980 # Check rename works with extended/alternate DN forms
1981 ldb
.rename("<SID=" + ldb
.schema_format_value("objectSID", res_user
[0]["objectSID"][0]) + ">" , "cn=ldaptestUSER3,cn=users," + self
.base_dn
)
1983 # Testing ldb.search for (&(cn=ldaptestuser3)(objectClass=user))
1984 res
= ldb
.search(expression
="(&(cn=ldaptestuser3)(objectClass=user))")
1985 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))")
1987 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestUSER3,CN=Users," + self
.base_dn
))
1988 self
.assertEquals(str(res
[0]["cn"]), "ldaptestUSER3")
1989 self
.assertEquals(str(res
[0]["name"]), "ldaptestUSER3")
1991 #"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))"
1992 res
= ldb
.search(expression
="(&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))")
1993 self
.assertEquals(len(res
), 1, "(&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))")
1995 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestUSER3,CN=Users," + self
.base_dn
))
1996 self
.assertEquals(str(res
[0]["cn"]), "ldaptestUSER3")
1997 self
.assertEquals(str(res
[0]["name"]), "ldaptestUSER3")
1999 #"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))"
2000 res
= ldb
.search(expression
="(&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))")
2001 self
.assertEquals(len(res
), 1, "(&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))")
2003 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestUSER3,CN=Users," + self
.base_dn
))
2004 self
.assertEquals(str(res
[0]["cn"]), "ldaptestUSER3")
2005 self
.assertEquals(str(res
[0]["name"]), "ldaptestUSER3")
2007 #"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=547))(objectClass=user))"
2008 res
= ldb
.search(expression
="(&(&(cn=ldaptestuser3)(userAccountControl=547))(objectClass=user))")
2009 self
.assertEquals(len(res
), 0, "(&(&(cn=ldaptestuser3)(userAccountControl=547))(objectClass=user))")
2011 # Testing ldb.search for (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ") - should not work
2012 res
= ldb
.search(expression
="(dn=CN=ldaptestUSER3,CN=Users," + self
.base_dn
+ ")")
2013 self
.assertEquals(len(res
), 0, "Could find (dn=CN=ldaptestUSER3,CN=Users," + self
.base_dn
+ ")")
2015 # Testing ldb.search for (distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")
2016 res
= ldb
.search(expression
="(distinguishedName=CN=ldaptestUSER3,CN=Users," + self
.base_dn
+ ")")
2017 self
.assertEquals(len(res
), 1, "Could not find (distinguishedName=CN=ldaptestUSER3,CN=Users," + self
.base_dn
+ ")")
2018 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestUSER3,CN=Users," + self
.base_dn
))
2019 self
.assertEquals(str(res
[0]["cn"]), "ldaptestUSER3")
2020 self
.assertEquals(str(res
[0]["name"]), "ldaptestUSER3")
2022 # ensure we cannot add it again
2024 ldb
.add({"dn": "cn=ldaptestuser3,cn=userS," + self
.base_dn
,
2025 "objectClass": "user",
2026 "cn": "LDAPtestUSER3"})
2028 except LdbError
, (num
, _
):
2029 self
.assertEquals(num
, ERR_ENTRY_ALREADY_EXISTS
)
2032 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
2034 # ensure we cannot rename it twice
2036 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
,
2037 "cn=ldaptestuser2,cn=users," + self
.base_dn
)
2039 except LdbError
, (num
, _
):
2040 self
.assertEquals(num
, ERR_NO_SUCH_OBJECT
)
2042 # ensure can now use that name
2043 ldb
.add({"dn": "cn=ldaptestuser3,cn=users," + self
.base_dn
,
2044 "objectClass": "user",
2045 "cn": "LDAPtestUSER3"})
2047 # ensure we now cannot rename
2049 ldb
.rename("cn=ldaptestuser2,cn=users," + self
.base_dn
, "cn=ldaptestuser3,cn=users," + self
.base_dn
)
2051 except LdbError
, (num
, _
):
2052 self
.assertEquals(num
, ERR_ENTRY_ALREADY_EXISTS
)
2054 ldb
.rename("cn=ldaptestuser3,cn=users,%s" % self
.base_dn
, "cn=ldaptestuser3,%s" % ldb
.get_config_basedn())
2056 except LdbError
, (num
, _
):
2057 self
.assertTrue(num
in (71, 64))
2059 ldb
.rename("cn=ldaptestuser3,cn=users," + self
.base_dn
, "cn=ldaptestuser5,cn=users," + self
.base_dn
)
2061 ldb
.delete("cn=ldaptestuser5,cn=users," + self
.base_dn
)
2063 delete_force(ldb
, "cn=ldaptestgroup2,cn=users," + self
.base_dn
)
2065 ldb
.rename("cn=ldaptestgroup,cn=users," + self
.base_dn
, "cn=ldaptestgroup2,cn=users," + self
.base_dn
)
2067 # Testing subtree renames
2069 ldb
.add({"dn": "cn=ldaptestcontainer," + self
.base_dn
,
2070 "objectClass": "container"})
2072 ldb
.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + self
.base_dn
,
2073 "objectClass": "user",
2074 "cn": "LDAPtestUSER4"})
2076 # Here we don't enforce these hard "description" constraints
2078 dn: cn=ldaptestcontainer,""" + self
.base_dn
+ """
2080 replace: description
2086 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2089 member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self
.base_dn
+ """
2090 member: cn=ldaptestcomputer,cn=computers,""" + self
.base_dn
+ """
2091 member: cn=ldaptestuser2,cn=users,""" + self
.base_dn
+ """
2094 # Testing ldb.rename of cn=ldaptestcontainer," + self.base_dn + " to cn=ldaptestcontainer2," + self.base_dn
2095 ldb
.rename("CN=ldaptestcontainer," + self
.base_dn
, "CN=ldaptestcontainer2," + self
.base_dn
)
2097 # Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user))
2098 res
= ldb
.search(expression
="(&(cn=ldaptestuser4)(objectClass=user))")
2099 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user))")
2101 # Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn
2103 res
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
2104 expression
="(&(cn=ldaptestuser4)(objectClass=user))",
2105 scope
=SCOPE_SUBTREE
)
2107 except LdbError
, (num
, _
):
2108 self
.assertEquals(num
, ERR_NO_SUCH_OBJECT
)
2110 # Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn
2112 res
= ldb
.search("cn=ldaptestcontainer," + self
.base_dn
,
2113 expression
="(&(cn=ldaptestuser4)(objectClass=user))", scope
=SCOPE_ONELEVEL
)
2115 except LdbError
, (num
, _
):
2116 self
.assertEquals(num
, ERR_NO_SUCH_OBJECT
)
2118 # Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container"
2119 res
= ldb
.search("cn=ldaptestcontainer2," + self
.base_dn
, expression
="(&(cn=ldaptestuser4)(objectClass=user))", scope
=SCOPE_SUBTREE
)
2120 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user)) under cn=ldaptestcontainer2," + self
.base_dn
)
2122 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
))
2123 self
.assertEquals(res
[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
).upper())
2127 # Testing ldb.search for (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group)) to check subtree renames and linked attributes"
2128 res
= ldb
.search(self
.base_dn
, expression
="(&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
+ ")(objectclass=group))", scope
=SCOPE_SUBTREE
)
2129 self
.assertEquals(len(res
), 1, "Could not find (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
+ ")(objectclass=group)), perhaps linked attributes are not consistant with subtree renames?")
2131 # Testing ldb.rename (into itself) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn
2133 ldb
.rename("cn=ldaptestcontainer2," + self
.base_dn
, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + self
.base_dn
)
2135 except LdbError
, (num
, _
):
2136 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
2138 # Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn
2140 ldb
.rename("cn=ldaptestcontainer2," + self
.base_dn
, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + self
.base_dn
)
2142 except LdbError
, (num
, _
):
2143 self
.assertTrue(num
in (ERR_UNWILLING_TO_PERFORM
, ERR_OTHER
))
2145 # Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + self.base_dn
2147 ldb
.delete("cn=ldaptestcontainer2," + self
.base_dn
)
2149 except LdbError
, (num
, _
):
2150 self
.assertEquals(num
, ERR_NOT_ALLOWED_ON_NON_LEAF
)
2152 # Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn
2153 res
= ldb
.search(expression
="(objectclass=*)", base
=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
), scope
=SCOPE_BASE
)
2154 self
.assertEquals(len(res
), 1)
2155 res
= ldb
.search(expression
="(cn=ldaptestuser40)", base
=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
), scope
=SCOPE_BASE
)
2156 self
.assertEquals(len(res
), 0)
2158 # Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn
2159 res
= ldb
.search(expression
="(&(cn=ldaptestuser4)(objectClass=user))", base
=("cn=ldaptestcontainer2," + self
.base_dn
), scope
=SCOPE_ONELEVEL
)
2160 self
.assertEquals(len(res
), 1)
2162 # Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn
2163 res
= ldb
.search(expression
="(&(cn=ldaptestuser4)(objectClass=user))", base
=("cn=ldaptestcontainer2," + self
.base_dn
), scope
=SCOPE_SUBTREE
)
2164 self
.assertEquals(len(res
), 1)
2166 # Testing delete of subtree renamed "+("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn)
2167 ldb
.delete(("CN=ldaptestuser4,CN=ldaptestcontainer2," + self
.base_dn
))
2168 # Testing delete of renamed cn=ldaptestcontainer2," + self.base_dn
2169 ldb
.delete("cn=ldaptestcontainer2," + self
.base_dn
)
2171 ldb
.add({"dn": "cn=ldaptestutf8user èùéìòà,cn=users," + self
.base_dn
, "objectClass": "user"})
2173 ldb
.add({"dn": "cn=ldaptestutf8user2 èùéìòà,cn=users," + self
.base_dn
, "objectClass": "user"})
2175 # Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))"
2176 res
= ldb
.search(expression
="(&(cn=ldaptestuser)(objectClass=user))")
2177 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))")
2179 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestuser,CN=Users," + self
.base_dn
))
2180 self
.assertEquals(str(res
[0]["cn"]), "ldaptestuser")
2181 self
.assertEquals(str(res
[0]["name"]), "ldaptestuser")
2182 self
.assertEquals(set(res
[0]["objectClass"]), set(["top", "person", "organizationalPerson", "user"]))
2183 self
.assertTrue("objectGUID" in res
[0])
2184 self
.assertTrue("whenCreated" in res
[0])
2185 self
.assertEquals(str(res
[0]["objectCategory"]), ("CN=Person,%s" % ldb
.get_schema_basedn()))
2186 self
.assertEquals(int(res
[0]["sAMAccountType"][0]), ATYPE_NORMAL_ACCOUNT
)
2187 self
.assertEquals(int(res
[0]["userAccountControl"][0]), UF_NORMAL_ACCOUNT | UF_PASSWD_NOTREQD | UF_ACCOUNTDISABLE
)
2188 self
.assertEquals(res
[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
).upper())
2189 self
.assertEquals(len(res
[0]["memberOf"]), 1)
2191 # Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,%s))" % ldb.get_schema_basedn()
2192 res2
= ldb
.search(expression
="(&(cn=ldaptestuser)(objectCategory=cn=person,%s))" % ldb
.get_schema_basedn())
2193 self
.assertEquals(len(res2
), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,%s))" % ldb
.get_schema_basedn())
2195 self
.assertEquals(res
[0].dn
, res2
[0].dn
)
2197 # Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))"
2198 res3
= ldb
.search(expression
="(&(cn=ldaptestuser)(objectCategory=PerSon))")
2199 self
.assertEquals(len(res3
), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)): matched %d" % len(res3
))
2201 self
.assertEquals(res
[0].dn
, res3
[0].dn
)
2203 if gc_ldb
is not None:
2204 # Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog"
2205 res3gc
= gc_ldb
.search(expression
="(&(cn=ldaptestuser)(objectCategory=PerSon))")
2206 self
.assertEquals(len(res3gc
), 1)
2208 self
.assertEquals(res
[0].dn
, res3gc
[0].dn
)
2210 # Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in with 'phantom root' control"
2212 if gc_ldb
is not None:
2213 res3control
= gc_ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestuser)(objectCategory=PerSon))", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["search_options:1:2"])
2214 self
.assertEquals(len(res3control
), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog")
2216 self
.assertEquals(res
[0].dn
, res3control
[0].dn
)
2218 ldb
.delete(res
[0].dn
)
2220 # Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))"
2221 res
= ldb
.search(expression
="(&(cn=ldaptestcomputer)(objectClass=user))")
2222 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))")
2224 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestcomputer,CN=Computers," + self
.base_dn
))
2225 self
.assertEquals(str(res
[0]["cn"]), "ldaptestcomputer")
2226 self
.assertEquals(str(res
[0]["name"]), "ldaptestcomputer")
2227 self
.assertEquals(set(res
[0]["objectClass"]), set(["top", "person", "organizationalPerson", "user", "computer"]))
2228 self
.assertTrue("objectGUID" in res
[0])
2229 self
.assertTrue("whenCreated" in res
[0])
2230 self
.assertEquals(str(res
[0]["objectCategory"]), ("CN=Computer,%s" % ldb
.get_schema_basedn()))
2231 self
.assertEquals(int(res
[0]["primaryGroupID"][0]), 513)
2232 self
.assertEquals(int(res
[0]["sAMAccountType"][0]), ATYPE_NORMAL_ACCOUNT
)
2233 self
.assertEquals(int(res
[0]["userAccountControl"][0]), UF_NORMAL_ACCOUNT | UF_PASSWD_NOTREQD | UF_ACCOUNTDISABLE
)
2234 self
.assertEquals(res
[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
).upper())
2235 self
.assertEquals(len(res
[0]["memberOf"]), 1)
2237 # Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s))" % ldb.get_schema_basedn()
2238 res2
= ldb
.search(expression
="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s))" % ldb
.get_schema_basedn())
2239 self
.assertEquals(len(res2
), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s))" % ldb
.get_schema_basedn())
2241 self
.assertEquals(res
[0].dn
, res2
[0].dn
)
2243 if gc_ldb
is not None:
2244 # Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s)) in Global Catalog" % gc_ldb.get_schema_basedn()
2245 res2gc
= gc_ldb
.search(expression
="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s))" % gc_ldb
.get_schema_basedn())
2246 self
.assertEquals(len(res2gc
), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,%s)) In Global Catalog" % gc_ldb
.get_schema_basedn())
2248 self
.assertEquals(res
[0].dn
, res2gc
[0].dn
)
2250 # Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))"
2251 res3
= ldb
.search(expression
="(&(cn=ldaptestcomputer)(objectCategory=compuTER))")
2252 self
.assertEquals(len(res3
), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))")
2254 self
.assertEquals(res
[0].dn
, res3
[0].dn
)
2256 if gc_ldb
is not None:
2257 # Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog"
2258 res3gc
= gc_ldb
.search(expression
="(&(cn=ldaptestcomputer)(objectCategory=compuTER))")
2259 self
.assertEquals(len(res3gc
), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog")
2261 self
.assertEquals(res
[0].dn
, res3gc
[0].dn
)
2263 # Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))"
2264 res4
= ldb
.search(expression
="(&(cn=ldaptestcomp*r)(objectCategory=compuTER))")
2265 self
.assertEquals(len(res4
), 1, "Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))")
2267 self
.assertEquals(res
[0].dn
, res4
[0].dn
)
2269 # Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))"
2270 res5
= ldb
.search(expression
="(&(cn=ldaptestcomput*)(objectCategory=compuTER))")
2271 self
.assertEquals(len(res5
), 1, "Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))")
2273 self
.assertEquals(res
[0].dn
, res5
[0].dn
)
2275 # Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))"
2276 res6
= ldb
.search(expression
="(&(cn=*daptestcomputer)(objectCategory=compuTER))")
2277 self
.assertEquals(len(res6
), 1, "Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))")
2279 self
.assertEquals(res
[0].dn
, res6
[0].dn
)
2281 ldb
.delete("<GUID=" + ldb
.schema_format_value("objectGUID", res
[0]["objectGUID"][0]) + ">")
2283 # Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))"
2284 res
= ldb
.search(expression
="(&(cn=ldaptest2computer)(objectClass=user))")
2285 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))")
2287 self
.assertEquals(str(res
[0].dn
), "CN=ldaptest2computer,CN=Computers," + self
.base_dn
)
2288 self
.assertEquals(str(res
[0]["cn"]), "ldaptest2computer")
2289 self
.assertEquals(str(res
[0]["name"]), "ldaptest2computer")
2290 self
.assertEquals(list(res
[0]["objectClass"]), ["top", "person", "organizationalPerson", "user", "computer"])
2291 self
.assertTrue("objectGUID" in res
[0])
2292 self
.assertTrue("whenCreated" in res
[0])
2293 self
.assertEquals(res
[0]["objectCategory"][0], "CN=Computer,%s" % ldb
.get_schema_basedn())
2294 self
.assertEquals(int(res
[0]["sAMAccountType"][0]), ATYPE_WORKSTATION_TRUST
)
2295 self
.assertEquals(int(res
[0]["userAccountControl"][0]), UF_WORKSTATION_TRUST_ACCOUNT
)
2297 ldb
.delete("<SID=" + ldb
.schema_format_value("objectSID", res
[0]["objectSID"][0]) + ">")
2299 attrs
= ["cn", "name", "objectClass", "objectGUID", "objectSID", "whenCreated", "nTSecurityDescriptor", "memberOf", "allowedAttributes", "allowedAttributesEffective"]
2300 # Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))"
2301 res_user
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestUSer2)(objectClass=user))", scope
=SCOPE_SUBTREE
, attrs
=attrs
)
2302 self
.assertEquals(len(res_user
), 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))")
2304 self
.assertEquals(str(res_user
[0].dn
), ("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
2305 self
.assertEquals(str(res_user
[0]["cn"]), "ldaptestuser2")
2306 self
.assertEquals(str(res_user
[0]["name"]), "ldaptestuser2")
2307 self
.assertEquals(list(res_user
[0]["objectClass"]), ["top", "person", "organizationalPerson", "user"])
2308 self
.assertTrue("objectSid" in res_user
[0])
2309 self
.assertTrue("objectGUID" in res_user
[0])
2310 self
.assertTrue("whenCreated" in res_user
[0])
2311 self
.assertTrue("nTSecurityDescriptor" in res_user
[0])
2312 self
.assertTrue("allowedAttributes" in res_user
[0])
2313 self
.assertTrue("allowedAttributesEffective" in res_user
[0])
2314 self
.assertEquals(res_user
[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
).upper())
2316 ldaptestuser2_sid
= res_user
[0]["objectSid"][0]
2317 ldaptestuser2_guid
= res_user
[0]["objectGUID"][0]
2319 attrs
= ["cn", "name", "objectClass", "objectGUID", "objectSID", "whenCreated", "nTSecurityDescriptor", "member", "allowedAttributes", "allowedAttributesEffective"]
2320 # Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group))"
2321 res
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestgroup2)(objectClass=group))", scope
=SCOPE_SUBTREE
, attrs
=attrs
)
2322 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))")
2324 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
))
2325 self
.assertEquals(str(res
[0]["cn"]), "ldaptestgroup2")
2326 self
.assertEquals(str(res
[0]["name"]), "ldaptestgroup2")
2327 self
.assertEquals(list(res
[0]["objectClass"]), ["top", "group"])
2328 self
.assertTrue("objectGUID" in res
[0])
2329 self
.assertTrue("objectSid" in res
[0])
2330 self
.assertTrue("whenCreated" in res
[0])
2331 self
.assertTrue("nTSecurityDescriptor" in res
[0])
2332 self
.assertTrue("allowedAttributes" in res
[0])
2333 self
.assertTrue("allowedAttributesEffective" in res
[0])
2335 for m
in res
[0]["member"]:
2336 memberUP
.append(m
.upper())
2337 self
.assertTrue(("CN=ldaptestuser2,CN=Users," + self
.base_dn
).upper() in memberUP
)
2339 res
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestgroup2)(objectClass=group))", scope
=SCOPE_SUBTREE
, attrs
=attrs
, controls
=["extended_dn:1:1"])
2340 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))")
2342 print res
[0]["member"]
2344 for m
in res
[0]["member"]:
2345 memberUP
.append(m
.upper())
2346 print ("<GUID=" + ldb
.schema_format_value("objectGUID", ldaptestuser2_guid
) + ">;<SID=" + ldb
.schema_format_value("objectSid", ldaptestuser2_sid
) + ">;CN=ldaptestuser2,CN=Users," + self
.base_dn
).upper()
2348 self
.assertTrue(("<GUID=" + ldb
.schema_format_value("objectGUID", ldaptestuser2_guid
) + ">;<SID=" + ldb
.schema_format_value("objectSid", ldaptestuser2_sid
) + ">;CN=ldaptestuser2,CN=Users," + self
.base_dn
).upper() in memberUP
)
2350 # Quicktest for linked attributes"
2352 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2355 member: CN=ldaptestuser2,CN=Users,""" + self
.base_dn
+ """
2356 member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self
.base_dn
+ """
2360 dn: <GUID=""" + ldb
.schema_format_value("objectGUID", res
[0]["objectGUID"][0]) + """>
2363 member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self
.base_dn
+ """
2367 dn: <SID=""" + ldb
.schema_format_value("objectSid", res
[0]["objectSid"][0]) + """>
2373 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2376 member: <GUID=""" + ldb
.schema_format_value("objectGUID", res
[0]["objectGUID"][0]) + """>
2377 member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self
.base_dn
+ """
2381 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2387 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2390 member: <SID=""" + ldb
.schema_format_value("objectSid", res_user
[0]["objectSid"][0]) + """>
2391 member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self
.base_dn
+ """
2395 dn: cn=ldaptestgroup2,cn=users,""" + self
.base_dn
+ """
2398 member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self
.base_dn
+ """
2401 res
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestgroup2)(objectClass=group))", scope
=SCOPE_SUBTREE
, attrs
=attrs
)
2402 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))")
2404 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
))
2405 self
.assertEquals(res
[0]["member"][0], ("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
2406 self
.assertEquals(len(res
[0]["member"]), 1)
2408 ldb
.delete(("CN=ldaptestuser2,CN=Users," + self
.base_dn
))
2412 attrs
= ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"]
2413 # Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete"
2414 res
= ldb
.search(self
.base_dn
, expression
="(&(cn=ldaptestgroup2)(objectClass=group))", scope
=SCOPE_SUBTREE
, attrs
=attrs
)
2415 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete")
2417 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestgroup2,CN=Users," + self
.base_dn
))
2418 self
.assertTrue("member" not in res
[0])
2420 # Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))"
2421 res
= ldb
.search(expression
="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))")
2422 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))")
2423 res
= ldb
.search(expression
="(&(cn=ldaptestutf8user èùéìòà)(objectclass=user))")
2424 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))")
2426 self
.assertEquals(str(res
[0].dn
), ("CN=ldaptestutf8user èùéìòà,CN=Users," + self
.base_dn
))
2427 self
.assertEquals(str(res
[0]["cn"]), "ldaptestutf8user èùéìòà")
2428 self
.assertEquals(str(res
[0]["name"]), "ldaptestutf8user èùéìòà")
2429 self
.assertEquals(list(res
[0]["objectClass"]), ["top", "person", "organizationalPerson", "user"])
2430 self
.assertTrue("objectGUID" in res
[0])
2431 self
.assertTrue("whenCreated" in res
[0])
2433 # delete "ldaptestutf8user"
2434 ldb
.delete(res
[0].dn
)
2436 # Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))"
2437 res
= ldb
.search(expression
="(&(cn=ldaptestutf8user2*)(objectClass=user))")
2438 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))")
2440 # Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))"
2441 res
= ldb
.search(expression
="(&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))")
2442 self
.assertEquals(len(res
), 1, "Could not find (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))")
2444 # delete "ldaptestutf8user2 "
2445 ldb
.delete(res
[0].dn
)
2447 ldb
.delete(("CN=ldaptestgroup2,CN=Users," + self
.base_dn
))
2449 # Testing that we can't get at the configuration DN from the main search base"
2450 res
= ldb
.search(self
.base_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2451 self
.assertEquals(len(res
), 0)
2453 # Testing that we can get at the configuration DN from the main search base on the LDAP port with the 'phantom root' search_options control"
2454 res
= ldb
.search(self
.base_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["search_options:1:2"])
2455 self
.assertTrue(len(res
) > 0)
2457 if gc_ldb
is not None:
2458 # Testing that we can get at the configuration DN from the main search base on the GC port with the search_options control == 0"
2460 res
= gc_ldb
.search(self
.base_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["search_options:1:0"])
2461 self
.assertTrue(len(res
) > 0)
2463 # Testing that we do find configuration elements in the global catlog"
2464 res
= gc_ldb
.search(self
.base_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2465 self
.assertTrue(len(res
) > 0)
2467 # Testing that we do find configuration elements and user elements at the same time"
2468 res
= gc_ldb
.search(self
.base_dn
, expression
="(|(objectClass=crossRef)(objectClass=person))", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2469 self
.assertTrue(len(res
) > 0)
2471 # Testing that we do find configuration elements in the global catlog, with the configuration basedn"
2472 res
= gc_ldb
.search(self
.configuration_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2473 self
.assertTrue(len(res
) > 0)
2475 # Testing that we can get at the configuration DN on the main LDAP port"
2476 res
= ldb
.search(self
.configuration_dn
, expression
="objectClass=crossRef", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2477 self
.assertTrue(len(res
) > 0)
2479 # Testing objectCategory canonacolisation"
2480 res
= ldb
.search(self
.configuration_dn
, expression
="objectCategory=ntDsDSA", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2481 self
.assertTrue(len(res
) > 0, "Didn't find any records with objectCategory=ntDsDSA")
2482 self
.assertTrue(len(res
) != 0)
2484 res
= ldb
.search(self
.configuration_dn
, expression
="objectCategory=CN=ntDs-DSA," + self
.schema_dn
, scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2485 self
.assertTrue(len(res
) > 0, "Didn't find any records with objectCategory=CN=ntDs-DSA," + self
.schema_dn
)
2486 self
.assertTrue(len(res
) != 0)
2488 # Testing objectClass attribute order on "+ self.base_dn
2489 res
= ldb
.search(expression
="objectClass=domain", base
=self
.base_dn
,
2490 scope
=SCOPE_BASE
, attrs
=["objectClass"])
2491 self
.assertEquals(len(res
), 1)
2493 self
.assertEquals(list(res
[0]["objectClass"]), ["top", "domain", "domainDNS"])
2497 # Testing ldb.search for objectCategory=person"
2498 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=person", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2499 self
.assertTrue(len(res
) > 0)
2501 # Testing ldb.search for objectCategory=person with domain scope control"
2502 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=person", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["domain_scope:1"])
2503 self
.assertTrue(len(res
) > 0)
2505 # Testing ldb.search for objectCategory=user"
2506 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=user", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2507 self
.assertTrue(len(res
) > 0)
2509 # Testing ldb.search for objectCategory=user with domain scope control"
2510 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=user", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["domain_scope:1"])
2511 self
.assertTrue(len(res
) > 0)
2513 # Testing ldb.search for objectCategory=group"
2514 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=group", scope
=SCOPE_SUBTREE
, attrs
=["cn"])
2515 self
.assertTrue(len(res
) > 0)
2517 # Testing ldb.search for objectCategory=group with domain scope control"
2518 res
= ldb
.search(self
.base_dn
, expression
="objectCategory=group", scope
=SCOPE_SUBTREE
, attrs
=["cn"], controls
=["domain_scope:1"])
2519 self
.assertTrue(len(res
) > 0)
2521 # Testing creating a user with the posixAccount objectClass"
2522 self
.ldb
.add_ldif("""dn: cn=posixuser,CN=Users,%s
2525 objectClass: posixAccount
2527 objectClass: organizationalPerson
2533 homeDirectory: /home/posixuser
2534 loginShell: /bin/bash
2535 gecos: Posix User;;;
2536 description: A POSIX user"""% (self
.base_dn
))
2538 # Testing removing the posixAccount objectClass from an existing user"
2539 self
.ldb
.modify_ldif("""dn: cn=posixuser,CN=Users,%s
2542 objectClass: posixAccount"""% (self
.base_dn
))
2544 # Testing adding the posixAccount objectClass to an existing user"
2545 self
.ldb
.modify_ldif("""dn: cn=posixuser,CN=Users,%s
2548 objectClass: posixAccount"""% (self
.base_dn
))
2550 delete_force(self
.ldb
, "cn=posixuser,cn=users," + self
.base_dn
)
2551 delete_force(self
.ldb
, "cn=ldaptestuser,cn=users," + self
.base_dn
)
2552 delete_force(self
.ldb
, "cn=ldaptestuser2,cn=users," + self
.base_dn
)
2553 delete_force(self
.ldb
, "cn=ldaptestuser3,cn=users," + self
.base_dn
)
2554 delete_force(self
.ldb
, "cn=ldaptestuser4,cn=ldaptestcontainer," + self
.base_dn
)
2555 delete_force(self
.ldb
, "cn=ldaptestuser4,cn=ldaptestcontainer2," + self
.base_dn
)
2556 delete_force(self
.ldb
, "cn=ldaptestuser5,cn=users," + self
.base_dn
)
2557 delete_force(self
.ldb
, "cn=ldaptestgroup,cn=users," + self
.base_dn
)
2558 delete_force(self
.ldb
, "cn=ldaptestgroup2,cn=users," + self
.base_dn
)
2559 delete_force(self
.ldb
, "cn=ldaptestcomputer,cn=computers," + self
.base_dn
)
2560 delete_force(self
.ldb
, "cn=ldaptest2computer,cn=computers," + self
.base_dn
)
2561 delete_force(self
.ldb
, "cn=ldaptestcomputer3,cn=computers," + self
.base_dn
)
2562 delete_force(self
.ldb
, "cn=ldaptestutf8user èùéìòà,cn=users," + self
.base_dn
)
2563 delete_force(self
.ldb
, "cn=ldaptestutf8user2 èùéìòà,cn=users," + self
.base_dn
)
2564 delete_force(self
.ldb
, "cn=ldaptestcontainer," + self
.base_dn
)
2565 delete_force(self
.ldb
, "cn=ldaptestcontainer2," + self
.base_dn
)
2567 def test_security_descriptor_add(self
):
2568 """ Testing ldb.add_ldif() for nTSecurityDescriptor """
2569 user_name
= "testdescriptoruser1"
2570 user_dn
= "CN=%s,CN=Users,%s" % (user_name
, self
.base_dn
)
2572 # Test an empty security descriptor (naturally this shouldn't work)
2574 delete_force(self
.ldb
, user_dn
)
2576 self
.ldb
.add({ "dn": user_dn
,
2577 "objectClass": "user",
2578 "sAMAccountName": user_name
,
2579 "nTSecurityDescriptor": [] })
2581 except LdbError
, (num
, _
):
2582 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
2584 delete_force(self
.ldb
, user_dn
)
2586 # Test add_ldif() with SDDL security descriptor input
2589 sddl
= "O:DUG:DUD:PAI(A;;RPWP;;;AU)S:PAI"
2590 self
.ldb
.add_ldif("""
2591 dn: """ + user_dn
+ """
2593 sAMAccountName: """ + user_name
+ """
2594 nTSecurityDescriptor: """ + sddl
)
2595 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2596 desc
= res
[0]["nTSecurityDescriptor"][0]
2597 desc
= ndr_unpack( security
.descriptor
, desc
)
2598 desc_sddl
= desc
.as_sddl( self
.domain_sid
)
2599 self
.assertEqual(desc_sddl
, sddl
)
2601 delete_force(self
.ldb
, user_dn
)
2603 # Test add_ldif() with BASE64 security descriptor
2606 sddl
= "O:DUG:DUD:PAI(A;;RPWP;;;AU)S:PAI"
2607 desc
= security
.descriptor
.from_sddl(sddl
, self
.domain_sid
)
2608 desc_binary
= ndr_pack(desc
)
2609 desc_base64
= base64
.b64encode(desc_binary
)
2610 self
.ldb
.add_ldif("""
2611 dn: """ + user_dn
+ """
2613 sAMAccountName: """ + user_name
+ """
2614 nTSecurityDescriptor:: """ + desc_base64
)
2615 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2616 desc
= res
[0]["nTSecurityDescriptor"][0]
2617 desc
= ndr_unpack(security
.descriptor
, desc
)
2618 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2619 self
.assertEqual(desc_sddl
, sddl
)
2621 delete_force(self
.ldb
, user_dn
)
2623 def test_security_descriptor_add_neg(self
):
2624 """Test add_ldif() with BASE64 security descriptor input using WRONG domain SID
2627 user_name
= "testdescriptoruser1"
2628 user_dn
= "CN=%s,CN=Users,%s" % (user_name
, self
.base_dn
)
2629 delete_force(self
.ldb
, user_dn
)
2631 sddl
= "O:DUG:DUD:AI(A;;RPWP;;;AU)S:PAI"
2632 desc
= security
.descriptor
.from_sddl(sddl
, security
.dom_sid('S-1-5-21'))
2633 desc_base64
= base64
.b64encode( ndr_pack(desc
) )
2634 self
.ldb
.add_ldif("""
2635 dn: """ + user_dn
+ """
2637 sAMAccountName: """ + user_name
+ """
2638 nTSecurityDescriptor:: """ + desc_base64
)
2639 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2640 self
.assertTrue("nTSecurityDescriptor" in res
[0])
2641 desc
= res
[0]["nTSecurityDescriptor"][0]
2642 desc
= ndr_unpack(security
.descriptor
, desc
)
2643 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2644 self
.assertTrue("O:S-1-5-21-513G:S-1-5-21-513D:AI(A;;RPWP;;;AU)" in desc_sddl
)
2646 delete_force(self
.ldb
, user_dn
)
2648 def test_security_descriptor_modify(self
):
2649 """ Testing ldb.modify_ldif() for nTSecurityDescriptor """
2650 user_name
= "testdescriptoruser2"
2651 user_dn
= "CN=%s,CN=Users,%s" % (user_name
, self
.base_dn
)
2653 # Test an empty security descriptor (naturally this shouldn't work)
2655 delete_force(self
.ldb
, user_dn
)
2656 self
.ldb
.add({ "dn": user_dn
,
2657 "objectClass": "user",
2658 "sAMAccountName": user_name
})
2661 m
.dn
= Dn(ldb
, user_dn
)
2662 m
["nTSecurityDescriptor"] = MessageElement([], FLAG_MOD_ADD
,
2663 "nTSecurityDescriptor")
2667 except LdbError
, (num
, _
):
2668 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
2671 m
.dn
= Dn(ldb
, user_dn
)
2672 m
["nTSecurityDescriptor"] = MessageElement([], FLAG_MOD_REPLACE
,
2673 "nTSecurityDescriptor")
2677 except LdbError
, (num
, _
):
2678 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
2681 m
.dn
= Dn(ldb
, user_dn
)
2682 m
["nTSecurityDescriptor"] = MessageElement([], FLAG_MOD_DELETE
,
2683 "nTSecurityDescriptor")
2687 except LdbError
, (num
, _
):
2688 self
.assertEquals(num
, ERR_UNWILLING_TO_PERFORM
)
2690 delete_force(self
.ldb
, user_dn
)
2692 # Test modify_ldif() with SDDL security descriptor input
2693 # Add ACE to the original descriptor test
2696 self
.ldb
.add_ldif("""
2697 dn: """ + user_dn
+ """
2699 sAMAccountName: """ + user_name
)
2701 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2702 desc
= res
[0]["nTSecurityDescriptor"][0]
2703 desc
= ndr_unpack(security
.descriptor
, desc
)
2704 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2705 sddl
= desc_sddl
[:desc_sddl
.find("(")] + "(A;;RPWP;;;AU)" + desc_sddl
[desc_sddl
.find("("):]
2707 dn: """ + user_dn
+ """
2709 replace: nTSecurityDescriptor
2710 nTSecurityDescriptor: """ + sddl
2711 self
.ldb
.modify_ldif(mod
)
2712 # Read modified descriptor
2713 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2714 desc
= res
[0]["nTSecurityDescriptor"][0]
2715 desc
= ndr_unpack(security
.descriptor
, desc
)
2716 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2717 self
.assertEqual(desc_sddl
, sddl
)
2719 delete_force(self
.ldb
, user_dn
)
2721 # Test modify_ldif() with SDDL security descriptor input
2722 # New desctiptor test
2725 self
.ldb
.add_ldif("""
2726 dn: """ + user_dn
+ """
2728 sAMAccountName: """ + user_name
)
2730 sddl
= "O:DUG:DUD:PAI(A;;RPWP;;;AU)S:PAI"
2732 dn: """ + user_dn
+ """
2734 replace: nTSecurityDescriptor
2735 nTSecurityDescriptor: """ + sddl
2736 self
.ldb
.modify_ldif(mod
)
2737 # Read modified descriptor
2738 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2739 desc
= res
[0]["nTSecurityDescriptor"][0]
2740 desc
= ndr_unpack(security
.descriptor
, desc
)
2741 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2742 self
.assertEqual(desc_sddl
, sddl
)
2744 delete_force(self
.ldb
, user_dn
)
2746 # Test modify_ldif() with BASE64 security descriptor input
2747 # Add ACE to the original descriptor test
2750 self
.ldb
.add_ldif("""
2751 dn: """ + user_dn
+ """
2753 sAMAccountName: """ + user_name
)
2755 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2756 desc
= res
[0]["nTSecurityDescriptor"][0]
2757 desc
= ndr_unpack(security
.descriptor
, desc
)
2758 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2759 sddl
= desc_sddl
[:desc_sddl
.find("(")] + "(A;;RPWP;;;AU)" + desc_sddl
[desc_sddl
.find("("):]
2760 desc
= security
.descriptor
.from_sddl(sddl
, self
.domain_sid
)
2761 desc_base64
= base64
.b64encode(ndr_pack(desc
))
2763 dn: """ + user_dn
+ """
2765 replace: nTSecurityDescriptor
2766 nTSecurityDescriptor:: """ + desc_base64
2767 self
.ldb
.modify_ldif(mod
)
2768 # Read modified descriptor
2769 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2770 desc
= res
[0]["nTSecurityDescriptor"][0]
2771 desc
= ndr_unpack(security
.descriptor
, desc
)
2772 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2773 self
.assertEqual(desc_sddl
, sddl
)
2775 delete_force(self
.ldb
, user_dn
)
2777 # Test modify_ldif() with BASE64 security descriptor input
2778 # New descriptor test
2781 delete_force(self
.ldb
, user_dn
)
2782 self
.ldb
.add_ldif("""
2783 dn: """ + user_dn
+ """
2785 sAMAccountName: """ + user_name
)
2787 sddl
= "O:DUG:DUD:PAI(A;;RPWP;;;AU)S:PAI"
2788 desc
= security
.descriptor
.from_sddl(sddl
, self
.domain_sid
)
2789 desc_base64
= base64
.b64encode(ndr_pack(desc
))
2791 dn: """ + user_dn
+ """
2793 replace: nTSecurityDescriptor
2794 nTSecurityDescriptor:: """ + desc_base64
2795 self
.ldb
.modify_ldif(mod
)
2796 # Read modified descriptor
2797 res
= self
.ldb
.search(base
=user_dn
, attrs
=["nTSecurityDescriptor"])
2798 desc
= res
[0]["nTSecurityDescriptor"][0]
2799 desc
= ndr_unpack(security
.descriptor
, desc
)
2800 desc_sddl
= desc
.as_sddl(self
.domain_sid
)
2801 self
.assertEqual(desc_sddl
, sddl
)
2803 delete_force(self
.ldb
, user_dn
)
2805 def test_dsheuristics(self
):
2806 """Tests the 'dSHeuristics' attribute"""
2807 # Tests the 'dSHeuristics' attribute"
2809 # Get the current value to restore it later
2810 dsheuristics
= self
.ldb
.get_dsheuristics()
2811 # Perform the length checks: for each decade (except the 0th) we need
2812 # the first index to be the number. This goes till the 9th one, beyond
2813 # there does not seem to be another limitation.
2816 for i
in range(1,11):
2817 # This is in the range
2818 self
.ldb
.set_dsheuristics(dshstr
+ "x")
2819 self
.ldb
.set_dsheuristics(dshstr
+ "xxxxx")
2820 dshstr
= dshstr
+ "xxxxxxxxx"
2822 # Not anymore in the range, new decade specifier needed
2824 self
.ldb
.set_dsheuristics(dshstr
+ "x")
2826 except LdbError
, (num
, _
):
2827 self
.assertEquals(num
, ERR_CONSTRAINT_VIOLATION
)
2828 dshstr
= dshstr
+ str(i
)
2830 # There does not seem to be an upper limit
2831 self
.ldb
.set_dsheuristics(dshstr
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
2832 # apart from the above, all char values are accepted
2833 self
.ldb
.set_dsheuristics("123ABC-+!1asdfg@#^")
2834 self
.assertEquals(self
.ldb
.get_dsheuristics(), "123ABC-+!1asdfg@#^")
2837 self
.ldb
.set_dsheuristics(dsheuristics
)
2839 def test_ldapControlReturn(self
):
2840 """Testing that if we request a control that return a control it
2841 really return something"""
2842 res
= self
.ldb
.search(attrs
=["cn"],
2843 controls
=["paged_results:1:10"])
2844 self
.assertEquals(len(res
.controls
), 1)
2845 self
.assertEquals(res
.controls
[0].oid
, "1.2.840.113556.1.4.319")
2846 s
= str(res
.controls
[0])
2848 def test_operational(self
):
2849 """Tests operational attributes"""
2850 # Tests operational attributes"
2852 res
= self
.ldb
.search(self
.base_dn
, scope
=SCOPE_BASE
,
2853 attrs
=["createTimeStamp", "modifyTimeStamp",
2854 "structuralObjectClass", "whenCreated",
2856 self
.assertEquals(len(res
), 1)
2857 self
.assertTrue("createTimeStamp" in res
[0])
2858 self
.assertTrue("modifyTimeStamp" in res
[0])
2859 self
.assertTrue("structuralObjectClass" in res
[0])
2860 self
.assertTrue("whenCreated" in res
[0])
2861 self
.assertTrue("whenChanged" in res
[0])
2863 def test_timevalues1(self
):
2864 """Tests possible syntax of time attributes"""
2866 user_name
= "testtimevaluesuser1"
2867 user_dn
= "CN=%s,CN=Users,%s" % (user_name
, self
.base_dn
)
2869 delete_force(self
.ldb
, user_dn
)
2870 self
.ldb
.add({ "dn": user_dn
,
2871 "objectClass": "user",
2872 "sAMAccountName": user_name
})
2875 # We check the following values:
2877 # 370101000000Z => 20370101000000.0Z
2878 # 20370102000000.*Z => 20370102000000.0Z
2880 ext
= [ "Z", ".0Z", ".Z", ".000Z", ".RandomIgnoredCharacters...987654321Z" ]
2881 for i
in range(0, len(ext
)):
2882 v_raw
= "203701%02d000000" % (i
+ 1)
2884 v_set
= v_raw
[2:] + ext
[i
]
2886 v_set
= v_raw
+ ext
[i
]
2887 v_get
= v_raw
+ ".0Z"
2890 m
.dn
= Dn(ldb
, user_dn
)
2891 m
["msTSExpireDate"] = MessageElement([v_set
],
2896 res
= self
.ldb
.search(base
=user_dn
, scope
=SCOPE_BASE
, attrs
=["msTSExpireDate"])
2897 self
.assertTrue(len(res
) == 1)
2898 self
.assertTrue("msTSExpireDate" in res
[0])
2899 self
.assertTrue(len(res
[0]["msTSExpireDate"]) == 1)
2900 self
.assertEquals(res
[0]["msTSExpireDate"][0], v_get
)
2902 class BaseDnTests(samba
.tests
.TestCase
):
2905 super(BaseDnTests
, self
).setUp()
2908 def test_rootdse_attrs(self
):
2909 """Testing for all rootDSE attributes"""
2910 res
= self
.ldb
.search("", scope
=SCOPE_BASE
, attrs
=[])
2911 self
.assertEquals(len(res
), 1)
2913 def test_highestcommittedusn(self
):
2914 """Testing for highestCommittedUSN"""
2915 res
= self
.ldb
.search("", scope
=SCOPE_BASE
, attrs
=["highestCommittedUSN"])
2916 self
.assertEquals(len(res
), 1)
2917 self
.assertTrue(int(res
[0]["highestCommittedUSN"][0]) != 0)
2919 def test_netlogon(self
):
2920 """Testing for netlogon via LDAP"""
2921 res
= self
.ldb
.search("", scope
=SCOPE_BASE
, attrs
=["netlogon"])
2922 self
.assertEquals(len(res
), 0)
2924 def test_netlogon_highestcommitted_usn(self
):
2925 """Testing for netlogon and highestCommittedUSN via LDAP"""
2926 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2927 attrs
=["netlogon", "highestCommittedUSN"])
2928 self
.assertEquals(len(res
), 0)
2930 def test_namingContexts(self
):
2931 """Testing for namingContexts in rootDSE"""
2932 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2933 attrs
=["namingContexts", "defaultNamingContext", "schemaNamingContext", "configurationNamingContext"])
2934 self
.assertEquals(len(res
), 1)
2937 for nc
in res
[0]["namingContexts"]:
2938 self
.assertTrue(nc
not in ncs
)
2941 self
.assertTrue(res
[0]["defaultNamingContext"][0] in ncs
)
2942 self
.assertTrue(res
[0]["configurationNamingContext"][0] in ncs
)
2943 self
.assertTrue(res
[0]["schemaNamingContext"][0] in ncs
)
2945 def test_serverPath(self
):
2946 """Testing the server paths in rootDSE"""
2947 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2948 attrs
=["dsServiceName", "serverName"])
2949 self
.assertEquals(len(res
), 1)
2951 self
.assertTrue("CN=Servers" in res
[0]["dsServiceName"][0])
2952 self
.assertTrue("CN=Sites" in res
[0]["dsServiceName"][0])
2953 self
.assertTrue("CN=NTDS Settings" in res
[0]["dsServiceName"][0])
2954 self
.assertTrue("CN=Servers" in res
[0]["serverName"][0])
2955 self
.assertTrue("CN=Sites" in res
[0]["serverName"][0])
2956 self
.assertFalse("CN=NTDS Settings" in res
[0]["serverName"][0])
2958 def test_functionality(self
):
2959 """Testing the server paths in rootDSE"""
2960 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2961 attrs
=["forestFunctionality", "domainFunctionality", "domainControllerFunctionality"])
2962 self
.assertEquals(len(res
), 1)
2963 self
.assertEquals(len(res
[0]["forestFunctionality"]), 1)
2964 self
.assertEquals(len(res
[0]["domainFunctionality"]), 1)
2965 self
.assertEquals(len(res
[0]["domainControllerFunctionality"]), 1)
2967 self
.assertTrue(int(res
[0]["forestFunctionality"][0]) <= int(res
[0]["domainFunctionality"][0]))
2968 self
.assertTrue(int(res
[0]["domainControllerFunctionality"][0]) >= int(res
[0]["domainFunctionality"][0]))
2970 res2
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2971 attrs
=["dsServiceName", "serverName"])
2972 self
.assertEquals(len(res2
), 1)
2973 self
.assertEquals(len(res2
[0]["dsServiceName"]), 1)
2975 res3
= self
.ldb
.search(res2
[0]["dsServiceName"][0], scope
=SCOPE_BASE
, attrs
=["msDS-Behavior-Version"])
2976 self
.assertEquals(len(res3
), 1)
2977 self
.assertEquals(len(res3
[0]["msDS-Behavior-Version"]), 1)
2978 self
.assertEquals(int(res
[0]["domainControllerFunctionality"][0]), int(res3
[0]["msDS-Behavior-Version"][0]))
2980 res4
= self
.ldb
.search(ldb
.domain_dn(), scope
=SCOPE_BASE
, attrs
=["msDS-Behavior-Version"])
2981 self
.assertEquals(len(res4
), 1)
2982 self
.assertEquals(len(res4
[0]["msDS-Behavior-Version"]), 1)
2983 self
.assertEquals(int(res
[0]["domainFunctionality"][0]), int(res4
[0]["msDS-Behavior-Version"][0]))
2985 res5
= self
.ldb
.search("cn=partitions,%s" % ldb
.get_config_basedn(), scope
=SCOPE_BASE
, attrs
=["msDS-Behavior-Version"])
2986 self
.assertEquals(len(res5
), 1)
2987 self
.assertEquals(len(res5
[0]["msDS-Behavior-Version"]), 1)
2988 self
.assertEquals(int(res
[0]["forestFunctionality"][0]), int(res5
[0]["msDS-Behavior-Version"][0]))
2990 def test_dnsHostname(self
):
2991 """Testing the DNS hostname in rootDSE"""
2992 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
2993 attrs
=["dnsHostName", "serverName"])
2994 self
.assertEquals(len(res
), 1)
2996 res2
= self
.ldb
.search(res
[0]["serverName"][0], scope
=SCOPE_BASE
,
2997 attrs
=["dNSHostName"])
2998 self
.assertEquals(len(res2
), 1)
3000 self
.assertEquals(res
[0]["dnsHostName"][0], res2
[0]["dNSHostName"][0])
3002 def test_ldapServiceName(self
):
3003 """Testing the ldap service name in rootDSE"""
3004 res
= self
.ldb
.search("", scope
=SCOPE_BASE
,
3005 attrs
=["ldapServiceName", "dnsHostName"])
3006 self
.assertEquals(len(res
), 1)
3007 self
.assertTrue("ldapServiceName" in res
[0])
3008 self
.assertTrue("dnsHostName" in res
[0])
3010 (hostname
, _
, dns_domainname
) = res
[0]["dnsHostName"][0].partition(".")
3012 given
= res
[0]["ldapServiceName"][0]
3013 expected
= "%s:%s$@%s" % (dns_domainname
.lower(), hostname
.lower(), dns_domainname
.upper())
3014 self
.assertEquals(given
, expected
)
3016 if not "://" in host
:
3017 if os
.path
.isfile(host
):
3018 host
= "tdb://%s" % host
3020 host
= "ldap://%s" % host
3022 ldb
= SamDB(host
, credentials
=creds
, session_info
=system_session(lp
), lp
=lp
)
3023 if not "tdb://" in host
:
3024 gc_ldb
= Ldb("%s:3268" % host
, credentials
=creds
,
3025 session_info
=system_session(lp
), lp
=lp
)
3029 TestProgram(module
=__name__
, opts
=subunitopts
)