s4:ldap.py - other important RDN check testcases
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 4 Mar 2011 08:27:51 +0000 (09:27 +0100)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 4 Mar 2011 21:07:24 +0000 (22:07 +0100)
Reviewed by: Tridge

source4/dsdb/tests/python/ldap.py

index 489c0176504f2b425b174c0c66a9db593efbeedb..d546717da92c0a816e2a38c5c5e6899397ead3e4 100755 (executable)
@@ -889,6 +889,30 @@ class BasicTests(unittest.TestCase):
         """Tests the RDN"""
         print "Tests the RDN"""
 
         """Tests the RDN"""
         print "Tests the RDN"""
 
+        # Search
+
+        # empty RDN
+        try:
+            self.ldb.search("=,cn=users," + self.base_dn, scope=SCOPE_BASE)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        # empty RDN name
+        try:
+            self.ldb.search("cn=,cn=users," + self.base_dn, scope=SCOPE_BASE)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        try:
+            self.ldb.search("=ldaptestgroup,cn=users," + self.base_dn, scope=SCOPE_BASE)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        # Add
+
         # empty RDN
         try:
             self.ldb.add({
         # empty RDN
         try:
             self.ldb.add({
@@ -940,6 +964,29 @@ class BasicTests(unittest.TestCase):
         self.assertTrue("name" in res[0])
         self.assertTrue(res[0]["name"][0] == "ldaptestgroup")
 
         self.assertTrue("name" in res[0])
         self.assertTrue(res[0]["name"][0] == "ldaptestgroup")
 
+        # Modify
+
+        # empty RDN value
+        m = Message()
+        m.dn = Dn(ldb, "cn=,cn=users," + self.base_dn)
+        m["description"] = "test"
+        try:
+            self.ldb.modify(m)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        # Delete
+
+        # empty RDN value
+        try:
+            self.ldb.delete("cn=,cn=users," + self.base_dn)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        # Rename
+
         # new empty RDN
         try:
             self.ldb.rename("cn=ldaptestgroup,cn=users," + self.base_dn,
         # new empty RDN
         try:
             self.ldb.rename("cn=ldaptestgroup,cn=users," + self.base_dn,
@@ -964,6 +1011,26 @@ class BasicTests(unittest.TestCase):
         except LdbError, (num, _):
             self.assertEquals(num, ERR_NAMING_VIOLATION)
 
         except LdbError, (num, _):
             self.assertEquals(num, ERR_NAMING_VIOLATION)
 
+        # new wrong RDN candidate
+        try:
+            self.ldb.rename("cn=ldaptestgroup,cn=users," + self.base_dn,
+                            "description=xyz,cn=users," + self.base_dn)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_UNWILLING_TO_PERFORM)
+
+        delete_force(self.ldb, "description=xyz,cn=users," + self.base_dn)
+
+        # old empty RDN value
+        try:
+            self.ldb.rename("cn=,cn=users," + self.base_dn,
+                            "cn=ldaptestgroup,cn=users," + self.base_dn)
+            self.fail()
+        except LdbError, (num, _):
+            self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
+
+        # names
+
         m = Message()
         m.dn = Dn(ldb, "cn=ldaptestgroup,cn=users," + self.base_dn)
         m["name"] = MessageElement("cn=ldaptestuser", FLAG_MOD_REPLACE,
         m = Message()
         m.dn = Dn(ldb, "cn=ldaptestgroup,cn=users," + self.base_dn)
         m["name"] = MessageElement("cn=ldaptestuser", FLAG_MOD_REPLACE,