s4:dsdb/tests/passwords.py - set and reset the "minPwdAge" properly
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Sat, 3 Jul 2010 09:07:10 +0000 (11:07 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Sat, 3 Jul 2010 09:28:21 +0000 (11:28 +0200)
After a patch proposal of Nadya and some reflection I think that it's really
worth to change all tests which need a "0" "minPwdAge" to set it manually and
reset the default afterwards.

So we can finally introduce the default "minPwdAge" on provision.

Patch proposal by: Nadya Ivanova

source4/dsdb/tests/python/passwords.py

index bf9e90976a170257fc68fe3dd60892787b8e090f..c288ed524e8c6a651749a77c6b0929bbbfe48e7c 100755 (executable)
@@ -7,8 +7,6 @@
 # Notice: This tests will also work against Windows Server if the connection is
 # secured enough (SASL with a minimum of 128 Bit encryption) - consider
 # MS-ADTS 3.1.1.3.1.5
-#
-# Important: Make sure that the minimum password age is set to "0"!
 
 import optparse
 import sys
@@ -584,6 +582,11 @@ res = ldb.search(base="", expression="", scope=SCOPE_BASE,
                  attrs=["configurationNamingContext"])
 configuration_dn = res[0]["configurationNamingContext"][0]
 
+# Gets back the basedn
+res = ldb.search(base="", expression="", scope=SCOPE_BASE,
+                 attrs=["defaultNamingContext"])
+base_dn = res[0]["defaultNamingContext"][0]
+
 # Get the old "dSHeuristics" if it was set
 res = ldb.search("CN=Directory Service, CN=Windows NT, CN=Services, "
                  + configuration_dn, scope=SCOPE_BASE, attrs=["dSHeuristics"])
@@ -600,6 +603,16 @@ m["dSHeuristics"] = MessageElement("000000001", FLAG_MOD_REPLACE,
   "dSHeuristics")
 ldb.modify(m)
 
+# Get the old "minPwdAge"
+res = ldb.search(base_dn, scope=SCOPE_BASE, attrs=["minPwdAge"])
+minPwdAge = res[0]["minPwdAge"][0]
+
+# Set it temporarely to "0"
+m = Message()
+m.dn = Dn(ldb, base_dn)
+m["minPwdAge"] = MessageElement("0", FLAG_MOD_REPLACE, "minPwdAge")
+ldb.modify(m)
+
 runner = SubunitTestRunner()
 rc = 0
 if not runner.run(unittest.makeSuite(PasswordTests)).wasSuccessful():
@@ -616,4 +629,10 @@ else:
     m["dSHeuristics"] = MessageElement([], FLAG_MOD_DELETE, "dsHeuristics")
 ldb.modify(m)
 
+# Reset the "minPwdAge" as it was before
+m = Message()
+m.dn = Dn(ldb, base_dn)
+m["minPwdAge"] = MessageElement(minPwdAge, FLAG_MOD_REPLACE, "minPwdAge")
+ldb.modify(m)
+
 sys.exit(rc)