summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tests
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mdw@samba.org>2010-06-06 23:09:28 +0200
committerMatthias Dieter Wallnöfer <mdw@samba.org>2010-06-07 14:47:24 +0200
commit17f465a4ac5562bec1b40dc97ac414fb3920175b (patch)
tree095c56198032317152576f0a72351e9e022b8828 /source4/lib/ldb/tests
parentee278bf0c48dbc8b7afc37762ad4f305014a2e2c (diff)
downloadsamba-17f465a4ac5562bec1b40dc97ac414fb3920175b.tar.gz
samba-17f465a4ac5562bec1b40dc97ac414fb3920175b.tar.bz2
samba-17f465a4ac5562bec1b40dc97ac414fb3920175b.zip
s4:ldap.py - enhance the attributes testcase to demonstrate how the attributes are checked against the schema and the specified objectclasses
This demonstrates the bew "objectclass_attrs" LDB module behaviour.
Diffstat (limited to 'source4/lib/ldb/tests')
-rwxr-xr-xsource4/lib/ldb/tests/python/ldap.py77
1 files changed, 75 insertions, 2 deletions
diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py
index 64889f1e32..86980c96f1 100755
--- a/source4/lib/ldb/tests/python/ldap.py
+++ b/source4/lib/ldb/tests/python/ldap.py
@@ -154,8 +154,12 @@ class BasicTests(unittest.TestCase):
self.delete_force(self.ldb, "ou=testou,cn=users," + self.base_dn)
def test_invalid_attribute(self):
- """Test adding invalid attributes (not in schema)"""
- print "Test adding invalid attributes (not in schema)"""
+ """Test invalid attributes on schema/objectclasses"""
+ print "Test invalid attributes on schema/objectclasses"""
+
+ # attributes not in schema test
+
+ # add operation
try:
self.ldb.add({
@@ -170,6 +174,8 @@ class BasicTests(unittest.TestCase):
"dn": "cn=ldaptestgroup,cn=users," + self.base_dn,
"objectclass": "group"})
+ # modify operation
+
m = Message()
m.dn = Dn(ldb, "cn=ldaptestgroup,cn=users," + self.base_dn)
m["thisdoesnotexist"] = MessageElement("x", FLAG_MOD_REPLACE,
@@ -182,6 +188,73 @@ class BasicTests(unittest.TestCase):
self.delete_force(self.ldb, "cn=ldaptestgroup,cn=users," + self.base_dn)
+ # attributes not in objectclasses and mandatory attributes missing test
+ # Use here a non-SAM entry since it doesn't have special triggers
+ # associated which have an impact on the error results.
+
+ # add operations
+
+ # mandatory attribute missing
+ try:
+ self.ldb.add({
+ "dn": "cn=ldaptestobject," + self.base_dn,
+ "objectclass": "ipProtocol"})
+ self.fail()
+ except LdbError, (num, _):
+ self.assertEquals(num, ERR_OBJECT_CLASS_VIOLATION)
+
+ # inadequate but schema-valid attribute specified
+ try:
+ self.ldb.add({
+ "dn": "cn=ldaptestobject," + self.base_dn,
+ "objectclass": "ipProtocol",
+ "ipProtocolNumber": "1",
+ "uid" : "0"})
+ self.fail()
+ except LdbError, (num, _):
+ self.assertEquals(num, ERR_OBJECT_CLASS_VIOLATION)
+
+ self.ldb.add({
+ "dn": "cn=ldaptestobject," + self.base_dn,
+ "objectclass": "ipProtocol",
+ "ipProtocolNumber": "1"})
+
+ # modify operations
+
+ # inadequate but schema-valid attribute add trial
+ m = Message()
+ m.dn = Dn(ldb, "cn=ldaptestobject," + self.base_dn)
+ m["uid"] = MessageElement("0", FLAG_MOD_ADD, "uid")
+ try:
+ ldb.modify(m)
+ self.fail()
+ except LdbError, (num, _):
+ self.assertEquals(num, ERR_OBJECT_CLASS_VIOLATION)
+
+ # mandatory attribute delete trial
+ m = Message()
+ m.dn = Dn(ldb, "cn=ldaptestobject," + self.base_dn)
+ m["ipProtocolNumber"] = MessageElement([], FLAG_MOD_DELETE,
+ "ipProtocolNumber")
+ try:
+ ldb.modify(m)
+ self.fail()
+ except LdbError, (num, _):
+ self.assertEquals(num, ERR_OBJECT_CLASS_VIOLATION)
+
+ # mandatory attribute delete trial
+ m = Message()
+ m.dn = Dn(ldb, "cn=ldaptestobject," + self.base_dn)
+ m["ipProtocolNumber"] = MessageElement([], FLAG_MOD_REPLACE,
+ "ipProtocolNumber")
+ try:
+ ldb.modify(m)
+ self.fail()
+ except LdbError, (num, _):
+ self.assertEquals(num, ERR_OBJECT_CLASS_VIOLATION)
+
+ self.delete_force(self.ldb, "cn=ldaptestobject," + self.base_dn)
+
def test_single_valued_attributes(self):
"""Test single-valued attributes"""
print "Test single-valued attributes"""