From: Rob van der Linde Date: Thu, 23 Feb 2023 02:53:58 +0000 (+1300) Subject: selftest: source4: fix mutable default arguments X-Git-Tag: talloc-2.4.1~1580 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9535526f08141fc5853f5a198bc76f0184e66fe;p=thirdparty%2Fsamba.git selftest: source4: fix mutable default arguments Signed-off-by: Rob van der Linde Reviewed-by: Andrew Bartlett Reviewed-by: Joseph Sutton --- diff --git a/source4/dsdb/tests/python/ad_dc_medley_performance.py b/source4/dsdb/tests/python/ad_dc_medley_performance.py index 6966c9ab529..7afdb747490 100644 --- a/source4/dsdb/tests/python/ad_dc_medley_performance.py +++ b/source4/dsdb/tests/python/ad_dc_medley_performance.py @@ -246,8 +246,10 @@ class UserTests(samba.tests.TestCase): raise def search_expression_list(self, expressions, rounds, - attrs=['cn'], + attrs=None, scope=SCOPE_SUBTREE): + if attrs is None: + attrs = ['cn'] for expression in expressions: t = time.time() for i in range(rounds): diff --git a/source4/dsdb/tests/python/dsdb_schema_info.py b/source4/dsdb/tests/python/dsdb_schema_info.py index 50b04cdcd7f..e3178d1c85c 100644 --- a/source4/dsdb/tests/python/dsdb_schema_info.py +++ b/source4/dsdb/tests/python/dsdb_schema_info.py @@ -165,7 +165,10 @@ systemOnly: FALSE """ return ldif - def test_AddModifyClass(self, controls=[], class_pre="schemaInfo-Class-"): + def test_AddModifyClass(self, controls=None, class_pre="schemaInfo-Class-"): + if controls is None: + controls = [] + # get initial schemaInfo schi_before = self._getSchemaInfo() diff --git a/source4/dsdb/tests/python/linked_attributes.py b/source4/dsdb/tests/python/linked_attributes.py index 65a248a299a..d7c31a7e875 100644 --- a/source4/dsdb/tests/python/linked_attributes.py +++ b/source4/dsdb/tests/python/linked_attributes.py @@ -74,7 +74,10 @@ class LATests(samba.tests.TestCase): if not opts.no_cleanup: self.samdb.delete(self.ou, ['tree_delete:1']) - def add_object(self, cn, objectclass, more_attrs={}): + def add_object(self, cn, objectclass, more_attrs=None): + if more_attrs is None: + more_attrs = {} + dn = "CN=%s,%s" % (cn, self.ou) attrs = {'cn': cn, 'objectclass': objectclass, @@ -84,7 +87,9 @@ class LATests(samba.tests.TestCase): return dn - def add_objects(self, n, objectclass, prefix=None, more_attrs={}): + def add_objects(self, n, objectclass, prefix=None, more_attrs=None): + if more_attrs is None: + more_attrs = {} if prefix is None: prefix = objectclass dns = [] diff --git a/source4/dsdb/tests/python/sec_descriptor.py b/source4/dsdb/tests/python/sec_descriptor.py index 5410e9f7246..8bdd9459bc5 100755 --- a/source4/dsdb/tests/python/sec_descriptor.py +++ b/source4/dsdb/tests/python/sec_descriptor.py @@ -336,8 +336,11 @@ class OwnerGroupDescriptorTests(DescriptorTests): super(OwnerGroupDescriptorTests, self).tearDown() self.deleteAll() - def check_user_belongs(self, user_dn, groups=[]): + def check_user_belongs(self, user_dn, groups=None): """ Test whether user is member of the expected group(s) """ + if groups is None: + groups = [] + if groups != []: # User is member of at least one additional group res = self.ldb_admin.search(user_dn, attrs=["memberOf"]) diff --git a/source4/dsdb/tests/python/subtree_rename.py b/source4/dsdb/tests/python/subtree_rename.py index d396055af68..ad5a5b88202 100644 --- a/source4/dsdb/tests/python/subtree_rename.py +++ b/source4/dsdb/tests/python/subtree_rename.py @@ -89,7 +89,10 @@ class SubtreeRenameTests(samba.tests.TestCase): if not opts.no_cleanup: self.delete_ous() - def add_object(self, cn, objectclass, ou=None, more_attrs={}): + def add_object(self, cn, objectclass, ou=None, more_attrs=None): + if more_attrs is None: + more_attrs = {} + dn = "CN=%s,%s" % (cn, ou) attrs = {'cn': cn, 'objectclass': objectclass, @@ -99,7 +102,10 @@ class SubtreeRenameTests(samba.tests.TestCase): return dn - def add_objects(self, n, objectclass, prefix=None, ou=None, more_attrs={}): + def add_objects(self, n, objectclass, prefix=None, ou=None, more_attrs=None): + if more_attrs is None: + more_attrs = {} + if prefix is None: prefix = objectclass dns = [] diff --git a/source4/dsdb/tests/python/tombstone_reanimation.py b/source4/dsdb/tests/python/tombstone_reanimation.py index ce3555af3bf..787ed999c4b 100755 --- a/source4/dsdb/tests/python/tombstone_reanimation.py +++ b/source4/dsdb/tests/python/tombstone_reanimation.py @@ -60,7 +60,10 @@ class RestoredObjectAttributesBaseTestCase(samba.tests.TestCase): def GUID_string(self, guid): return get_string(self.samdb.schema_format_value("objectGUID", guid)) - def search_guid(self, guid, attrs=["*"]): + def search_guid(self, guid, attrs=None): + if attrs is None: + attrs = ["*"] + res = self.samdb.search(base="" % self.GUID_string(guid), scope=SCOPE_BASE, attrs=attrs, controls=["show_deleted:1"]) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 08b29a85f69..7eff1bb2469 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -34,7 +34,10 @@ from selftesthelpers import smbtorture4, ntlm_auth3, samba3srcdir print("OPTIONS %s" % " ".join(smbtorture4_options), file=sys.stderr) -def plansmbtorture4testsuite(name, env, options, modname=None, environ={}): +def plansmbtorture4testsuite(name, env, options, modname=None, environ=None): + if environ is None: + environ = {} + return selftesthelpers.plansmbtorture4testsuite(name, env, options, @@ -862,7 +865,13 @@ for env in ["ad_dc:local", "s4member:local", "nt4_dc:local", "ad_member:local", subunitrun = valgrindify(python) + " " + os.path.join(samba4srcdir, "scripting/bin/subunitrun") -def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, extra_args=[]): +def planoldpythontestsuite(env, module, name=None, extra_path=None, environ=None, extra_args=None): + if extra_path is None: + extra_path = [] + if environ is None: + environ = {} + if extra_args is None: + extra_args = [] environ = dict(environ) py_path = list(extra_path) if py_path: diff --git a/source4/torture/drs/python/drs_base.py b/source4/torture/drs/python/drs_base.py index db7a87a33fe..bf98e599784 100644 --- a/source4/torture/drs/python/drs_base.py +++ b/source4/torture/drs/python/drs_base.py @@ -341,7 +341,7 @@ class DrsBaseTestCase(SambaToolCmdTest): return ctr - def _check_replication(self, expected_dns, replica_flags, expected_links=[], + def _check_replication(self, expected_dns, replica_flags, expected_links=None, drs_error=drsuapi.DRSUAPI_EXOP_ERR_NONE, drs=None, drs_handle=None, highwatermark=None, uptodateness_vector=None, more_flags=0, more_data=False, @@ -353,6 +353,8 @@ class DrsBaseTestCase(SambaToolCmdTest): """ Makes sure that replication returns the specific error given. """ + if expected_links is None: + expected_links = [] # send a DsGetNCChanges to the DC ctr6 = self._get_replication(replica_flags, @@ -380,13 +382,19 @@ class DrsBaseTestCase(SambaToolCmdTest): return dn_list - def _check_ctr6(self, ctr6, expected_dns=[], expected_links=[], + def _check_ctr6(self, ctr6, expected_dns=None, expected_links=None, dn_ordered=True, links_ordered=True, more_data=False, nc_object_count=0, nc_linked_attributes_count=0, drs_error=0): """ Check that a ctr6 matches the specified parameters. """ + if expected_dns is None: + expected_dns = [] + + if expected_links is None: + expected_links = [] + ctr6_raw_dns = self._get_ctr6_dn_list(ctr6) # filter out changes to the RID Set objects, as these can happen @@ -506,7 +514,9 @@ class DrsBaseTestCase(SambaToolCmdTest): (drs_handle, supported_extensions) = drs_DsBind(drs) return (drs, drs_handle) - def get_partial_attribute_set(self, attids=[drsuapi.DRSUAPI_ATTID_objectClass]): + def get_partial_attribute_set(self, attids=None): + if attids is None: + attids = [drsuapi.DRSUAPI_ATTID_objectClass] partial_attribute_set = drsuapi.DsPartialAttributeSet() partial_attribute_set.attids = attids partial_attribute_set.num_attids = len(attids) diff --git a/source4/torture/drs/python/repl_rodc.py b/source4/torture/drs/python/repl_rodc.py index 317d4a0c24a..3ace1cc5193 100644 --- a/source4/torture/drs/python/repl_rodc.py +++ b/source4/torture/drs/python/repl_rodc.py @@ -42,8 +42,11 @@ import random import time -def drs_get_rodc_partial_attribute_set(samdb, samdb1, exceptions=[]): +def drs_get_rodc_partial_attribute_set(samdb, samdb1, exceptions=None): '''get a list of attributes for RODC replication''' + if exceptions is None: + exceptions = [] + partial_attribute_set = drsuapi.DsPartialAttributeSet() partial_attribute_set.version = 1