s4:ldap.py - fix up the dSHeuristics test to check for the right behaviour
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Thu, 13 Oct 2011 07:51:18 +0000 (09:51 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Thu, 27 Oct 2011 16:52:29 +0000 (18:52 +0200)
Reviewed-by: abartlet
source4/dsdb/tests/python/ldap.py

index 20e05faaf5666491eeb807d47131ace6b049b5b0..9009c74e52cf06148b005495c225155fc558f710 100755 (executable)
@@ -2716,21 +2716,33 @@ nTSecurityDescriptor:: """ + desc_base64
 
         # Get the current value to restore it later
         dsheuristics = self.ldb.get_dsheuristics()
-        # Should not be longer than 18 chars?
-        try:
-            self.ldb.set_dsheuristics("123ABC-+!1asdfg@#^12")
-        except LdbError, (num, _):
-            self.assertEquals(num, ERR_CONSTRAINT_VIOLATION)
-        # If it is >= 10 chars, tenthChar should be 1
-        try:
-            self.ldb.set_dsheuristics("00020000000002")
-        except LdbError, (num, _):
-            self.assertEquals(num, ERR_CONSTRAINT_VIOLATION)
-        # apart from the above, all char values are accepted
-        self.ldb.set_dsheuristics("123ABC-+!1asdfg@#^")
-        self.assertEquals(self.ldb.get_dsheuristics(), "123ABC-+!1asdfg@#^")
-        # restore old value
-        self.ldb.set_dsheuristics(dsheuristics)
+        # Perform the length checks: for each decade (except the 0th) we need
+        # the first index to be the number. This goes till the 9th one, beyond
+        # there does not seem to be another limitation.
+        try:
+            dshstr = ""
+            for i in range(1,11):
+                # This is in the range
+                self.ldb.set_dsheuristics(dshstr + "x")
+                self.ldb.set_dsheuristics(dshstr + "xxxxx")
+                dshstr = dshstr + "xxxxxxxxx"
+                if i < 10:
+                    # Not anymore in the range, new decade specifier needed
+                    try:
+                        self.ldb.set_dsheuristics(dshstr + "x")
+                        self.fail()
+                    except LdbError, (num, _):
+                        self.assertEquals(num, ERR_CONSTRAINT_VIOLATION)
+                    dshstr = dshstr + str(i)
+                else:
+                    # There does not seem to be an upper limit
+                    self.ldb.set_dsheuristics(dshstr + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
+            # apart from the above, all char values are accepted
+            self.ldb.set_dsheuristics("123ABC-+!1asdfg@#^")
+            self.assertEquals(self.ldb.get_dsheuristics(), "123ABC-+!1asdfg@#^")
+        finally:
+            # restore old value
+            self.ldb.set_dsheuristics(dsheuristics)
 
     def test_ldapControlReturn(self):
         """Testing that if we request a control that return a control it