From 4bf20e6948133c3a53b91da6c18bf597220082c5 Mon Sep 17 00:00:00 2001 From: Nadezhda Ivanova Date: Fri, 19 Nov 2010 17:41:46 +0200 Subject: [PATCH] s4-tests: Added DsdbTestCase class, containing some common methods used by the dsdb python tests --- .../scripting/python/samba/tests/__init__.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py index 7a5c2aa694a..6458b3f585c 100644 --- a/source4/scripting/python/samba/tests/__init__.py +++ b/source4/scripting/python/samba/tests/__init__.py @@ -113,7 +113,6 @@ class BlackboxTestCase(TestCase): line = " ".join(parts) subprocess.check_call(line, shell=True) - def connect_samdb(samdb_url, lp=None, session_info=None, credentials=None, flags=0, ldb_options=None, ldap_only=False): """Creates SamDB instance and connects to samdb_url database. @@ -157,3 +156,41 @@ def connect_samdb(samdb_url, lp=None, session_info=None, credentials=credentials, flags=flags, options=ldb_options) + +from ldb import ( + SCOPE_BASE, SCOPE_SUBTREE, LdbError, ERR_NO_SUCH_OBJECT) +from ldb import Message, MessageElement, Dn +from ldb import FLAG_MOD_REPLACE, FLAG_MOD_DELETE +from samba.ndr import ndr_unpack +from samba.dcerpc import security + +class DsdbTestCase(TestCase): + """Base test case for dsdb tests.""" + + def delete_force(self, ldb, dn): + try: + ldb.delete(dn) + except LdbError, (num, _): + self.assertEquals(num, ERR_NO_SUCH_OBJECT) + + def find_domain_sid(self, ldb): + res = ldb.search(base=ldb.domain_dn(), expression="(objectClass=*)", scope=SCOPE_BASE) + return ndr_unpack(security.dom_sid,res[0]["objectSid"][0]) + + def set_dsheuristics(self, ldb, dsheuristics): + configuration_dn = ldb.get_config_basedn().get_linearized() + m = Message() + m.dn = Dn(ldb, "CN=Directory Service, CN=Windows NT, CN=Services, " + + configuration_dn) + if dsheuristics is not None: + m["dSHeuristics"] = MessageElement(dsheuristics, FLAG_MOD_REPLACE, + "dSHeuristics") + else: + m["dSHeuristics"] = MessageElement([], FLAG_MOD_DELETE, "dsHeuristics") + ldb.modify(m) + + def set_minPwdAge(self, ldb, value): + m = Message() + m.dn = Dn(ldb, ldb.domain_dn()) + m["minPwdAge"] = MessageElement(value, FLAG_MOD_REPLACE, "minPwdAge") + ldb.modify(m) -- 2.34.1