From: Joseph Sutton Date: Thu, 2 Mar 2023 23:32:06 +0000 (+1300) Subject: tests/krb5: Allow group_setup to be None in setup_groups() X-Git-Tag: talloc-2.4.1~1466 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d95b4303ea3c5c16afdad92850512d4a18ff8aee;p=thirdparty%2Fsamba.git tests/krb5: Allow group_setup to be None in setup_groups() 'git show -b' shows that not much actually changes. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/krb5/kdc_base_test.py b/python/samba/tests/krb5/kdc_base_test.py index a07d4a23b73..11a91d8cd9b 100644 --- a/python/samba/tests/krb5/kdc_base_test.py +++ b/python/samba/tests/krb5/kdc_base_test.py @@ -1020,45 +1020,48 @@ class KDCBaseTest(RawKerberosTest): primary_group_types = {} # Create each group and add it to the group mapping. - for group_id, (group_type, _) in group_setup.items(): - self.assertNotIn(group_id, preexisting_groups, - "don't specify placeholders") - self.assertNotIn(group_id, groups, - 'group ID specified more than once') - - if primary_groups is not None and ( - group_id in primary_groups.values()): - # Windows disallows setting a domain-local group as a primary - # group, unless we create it as Universal first and change it - # back to Domain-Local later. - primary_group_types[group_id] = group_type - group_type = GroupType.UNIVERSAL - - groups[group_id] = self.create_group_principal(samdb, group_type) - - # Map a group ID to that group's DN, and generate an - # understandable error message if the mapping fails. - def group_id_to_dn(group_id): - try: - group = groups[group_id] - except KeyError: - self.fail(f"included group member '{group_id}', but it is not " - f"specified in {groups.keys()}") - else: - if group.dn is not None: - return str(group.dn) + if group_setup is not None: + for group_id, (group_type, _) in group_setup.items(): + self.assertNotIn(group_id, preexisting_groups, + "don't specify placeholders") + self.assertNotIn(group_id, groups, + 'group ID specified more than once') + + if primary_groups is not None and ( + group_id in primary_groups.values()): + # Windows disallows setting a domain-local group as a + # primary group, unless we create it as Universal first and + # change it back to Domain-Local later. + primary_group_types[group_id] = group_type + group_type = GroupType.UNIVERSAL + + groups[group_id] = self.create_group_principal(samdb, + group_type) + + if group_setup is not None: + # Map a group ID to that group's DN, and generate an + # understandable error message if the mapping fails. + def group_id_to_dn(group_id): + try: + group = groups[group_id] + except KeyError: + self.fail(f"included group member '{group_id}', but it is " + f"not specified in {groups.keys()}") + else: + if group.dn is not None: + return str(group.dn) - return f'' + return f'' - # Populate each group's members. - for group_id, (_, members) in group_setup.items(): - # Get the group's DN and the mapped DNs of its members. - dn = groups[group_id].dn - principal_members = map(group_id_to_dn, members) + # Populate each group's members. + for group_id, (_, members) in group_setup.items(): + # Get the group's DN and the mapped DNs of its members. + dn = groups[group_id].dn + principal_members = map(group_id_to_dn, members) - # Add the members to the group. - self.add_to_group(principal_members, dn, 'member', - expect_attr=False) + # Add the members to the group. + self.add_to_group(principal_members, dn, 'member', + expect_attr=False) # Set primary groups. if primary_groups is not None: