a24961
From 6b70e3c49acc55b5553101cf850fc40978861979 Mon Sep 17 00:00:00 2001
a24961
From: Anuja More <amore@redhat.com>
a24961
Date: Mon, 17 Jan 2022 16:57:52 +0530
a24961
Subject: [PATCH] ipatests: Tests for Autoprivate group.
a24961
a24961
Added tests using posix AD trust and non posix AD trust.
a24961
For option --auto-private-groups=[hybrid/true/false]
a24961
a24961
Related : https://pagure.io/freeipa/issue/8807
a24961
a24961
Signed-off-by: Anuja More <amore@redhat.com>
a24961
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
a24961
Reviewed-By: Anuja More <amore@redhat.com>
a24961
---
a24961
 .../nightly_ipa-4-9_latest.yaml               |   2 +-
a24961
 .../nightly_ipa-4-9_latest_selinux.yaml       |   2 +-
a24961
 .../nightly_ipa-4-9_previous.yaml             |   2 +-
a24961
 ipatests/test_integration/test_trust.py       | 242 +++++++++++++++++-
a24961
 4 files changed, 240 insertions(+), 8 deletions(-)
a24961
a24961
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
a24961
index 6817421b2..8b1f58c4d 100644
a24961
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
a24961
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
a24961
@@ -1627,7 +1627,7 @@ jobs:
a24961
         build_url: '{fedora-latest-ipa-4-9/build_url}'
a24961
         test_suite: test_integration/test_trust.py
a24961
         template: *ci-ipa-4-9-latest
a24961
-        timeout: 9000
a24961
+        timeout: 10000
a24961
         topology: *adroot_adchild_adtree_master_1client
a24961
 
a24961
   fedora-latest-ipa-4-9/test_backup_and_restore_TestBackupAndRestoreTrust:
a24961
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
a24961
index 817329756..a11376ab8 100644
a24961
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
a24961
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
a24961
@@ -1743,7 +1743,7 @@ jobs:
a24961
         selinux_enforcing: True
a24961
         test_suite: test_integration/test_trust.py
a24961
         template: *ci-ipa-4-9-latest
a24961
-        timeout: 9000
a24961
+        timeout: 10000
a24961
         topology: *adroot_adchild_adtree_master_1client
a24961
 
a24961
   fedora-latest-ipa-4-9/test_backup_and_restore_TestBackupAndRestoreTrust:
a24961
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
a24961
index 4196265c7..3f8ce8b76 100644
a24961
--- a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
a24961
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
a24961
@@ -1627,7 +1627,7 @@ jobs:
a24961
         build_url: '{fedora-previous-ipa-4-9/build_url}'
a24961
         test_suite: test_integration/test_trust.py
a24961
         template: *ci-ipa-4-9-previous
a24961
-        timeout: 9000
a24961
+        timeout: 10000
a24961
         topology: *adroot_adchild_adtree_master_1client
a24961
 
a24961
   fedora-previous-ipa-4-9/test_backup_and_restore_TestBackupAndRestoreTrust:
a24961
diff --git a/ipatests/test_integration/test_trust.py b/ipatests/test_integration/test_trust.py
a24961
index 0634badbb..ff2dd9cc8 100644
a24961
--- a/ipatests/test_integration/test_trust.py
a24961
+++ b/ipatests/test_integration/test_trust.py
a24961
@@ -62,11 +62,12 @@ class BaseTestTrust(IntegrationTest):
a24961
         cls.check_sid_generation()
a24961
         tasks.sync_time(cls.master, cls.ad)
a24961
 
a24961
-        cls.child_ad = cls.ad_subdomains[0]
a24961
-        cls.ad_subdomain = cls.child_ad.domain.name
a24961
-        cls.tree_ad = cls.ad_treedomains[0]
a24961
-        cls.ad_treedomain = cls.tree_ad.domain.name
a24961
-
a24961
+        if cls.num_ad_subdomains > 0:
a24961
+            cls.child_ad = cls.ad_subdomains[0]
a24961
+            cls.ad_subdomain = cls.child_ad.domain.name
a24961
+        if cls.num_ad_treedomains > 0:
a24961
+            cls.tree_ad = cls.ad_treedomains[0]
a24961
+            cls.ad_treedomain = cls.tree_ad.domain.name
a24961
         # values used in workaround for
a24961
         # https://bugzilla.redhat.com/show_bug.cgi?id=1711958
a24961
         cls.srv_gc_record_name = \
a24961
@@ -106,6 +107,63 @@ class BaseTestTrust(IntegrationTest):
a24961
         expected_text = 'iparangetype: %s\n' % expected_type
a24961
         assert expected_text in result.stdout_text
a24961
 
a24961
+    def mod_idrange_auto_private_group(
a24961
+        self, option='false'
a24961
+    ):
a24961
+        """
a24961
+        Set the auto-private-group option of the default trusted
a24961
+        AD domain range.
a24961
+        """
a24961
+        tasks.kinit_admin(self.master)
a24961
+        rangename = self.ad_domain.upper() + '_id_range'
a24961
+        error_msg = "ipa: ERROR: no modifications to be performed"
a24961
+        cmd = ["ipa", "idrange-mod", rangename,
a24961
+               "--auto-private-groups", option]
a24961
+        result = self.master.run_command(cmd, raiseonerr=False)
a24961
+        if result.returncode != 0:
a24961
+            tasks.assert_error(result, error_msg)
a24961
+        tasks.clear_sssd_cache(self.master)
a24961
+        tasks.clear_sssd_cache(self.clients[0])
a24961
+        test = self.master.run_command(["ipa", "idrange-show", rangename])
a24961
+        assert "Auto private groups: {0}".format(option) in test.stdout_text
a24961
+
a24961
+    def get_user_id(self, host, username):
a24961
+        """
a24961
+        User uid gid is parsed from the output of id user command.
a24961
+        """
a24961
+        tasks.clear_sssd_cache(self.master)
a24961
+        tasks.clear_sssd_cache(self.clients[0])
a24961
+        self.master.run_command(["id", username])
a24961
+        test_id = host.run_command(["id", username])
a24961
+        regex = r"^uid=(?P<uid>\d+).*gid=(?P<gid>\d+).*groups=(?P<groups>\d+)"
a24961
+        match = re.match(regex, test_id.stdout_text)
a24961
+        uid = match.group('uid')
a24961
+        gid = match.group('gid')
a24961
+        return uid, gid
a24961
+
a24961
+    @contextmanager
a24961
+    def set_idoverrideuser(self, user, uid, gid):
a24961
+        """
a24961
+        Fixture to add/remove idoverrideuser for default idview,
a24961
+        also creates idm group with the provided gid because
a24961
+        gid overrides requires an existing group.
a24961
+        """
a24961
+        tasks.clear_sssd_cache(self.master)
a24961
+        tasks.clear_sssd_cache(self.clients[0])
a24961
+        tasks.kinit_admin(self.master)
a24961
+        try:
a24961
+            args = ["ipa", "idoverrideuser-add", "Default Trust View",
a24961
+                    "--gid", gid, "--uid", uid, user]
a24961
+            self.master.run_command(args)
a24961
+            tasks.group_add(self.master, "idgroup",
a24961
+                            extra_args=["--gid", gid])
a24961
+            yield
a24961
+        finally:
a24961
+            self.master.run_command([
a24961
+                "ipa", "idoverrideuser-del", "Default Trust View", user]
a24961
+            )
a24961
+            self.master.run_command(["ipa", "group-del", "idgroup"])
a24961
+
a24961
     def remove_trust(self, ad):
a24961
         tasks.remove_trust_with_ad(self.master,
a24961
                                    ad.domain.name, ad.hostname)
a24961
@@ -993,3 +1051,177 @@ class TestTrust(BaseTestTrust):
a24961
             self.master.run_command(['rm', '-f', ad_zone_file])
a24961
             tasks.configure_dns_for_trust(self.master, self.ad)
a24961
             self.remove_trust(self.ad)
a24961
+
a24961
+
a24961
+class TestNonPosixAutoPrivateGroup(BaseTestTrust):
a24961
+    """
a24961
+    Tests for auto-private-groups option with non posix AD trust
a24961
+    Related : https://pagure.io/freeipa/issue/8807
a24961
+    """
a24961
+    topology = 'line'
a24961
+    num_ad_domains = 1
a24961
+    num_clients = 1
a24961
+    num_ad_subdomains = 0
a24961
+    num_ad_treedomains = 0
a24961
+    uid_override = "99999999"
a24961
+    gid_override = "78878787"
a24961
+
a24961
+    def test_add_nonposix_trust(self):
a24961
+        tasks.configure_dns_for_trust(self.master, self.ad)
a24961
+        tasks.establish_trust_with_ad(
a24961
+            self.master, self.ad_domain,
a24961
+            extra_args=['--range-type', 'ipa-ad-trust'])
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_auto_private_groups_default_trusted_range(self, type):
a24961
+        """
a24961
+        Modify existing range for default trusted AD domain range
a24961
+        with auto-private-groups set as true/hybrid/false and test
a24961
+        user with no posix attributes.
a24961
+        """
a24961
+        self.mod_idrange_auto_private_group(type)
a24961
+        nonposixuser = "nonposixuser@%s" % self.ad_domain
a24961
+        (uid, gid) = self.get_user_id(self.clients[0], nonposixuser)
a24961
+        if type == "true":
a24961
+            assert uid == gid
a24961
+        else:
a24961
+            test_group = self.clients[0].run_command(["id", nonposixuser])
a24961
+            gid_str = "gid={0}(domain users@{1})".format(gid, self.ad_domain)
a24961
+            grp_str = "groups={0}(domain users@{1})".format(gid,
a24961
+                                                            self.ad_domain)
a24961
+            assert gid_str in test_group.stdout_text
a24961
+            assert grp_str in test_group.stdout_text
a24961
+            assert uid != gid
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_idoverride_with_auto_private_group(self, type):
a24961
+        """
a24961
+        Override ad trusted user in default trust view
a24961
+        and set auto-private-groups=[hybrid,true,false]
a24961
+        and ensure that overridden values takes effect.
a24961
+        """
a24961
+        nonposixuser = "nonposixuser@%s" % self.ad_domain
a24961
+        with self.set_idoverrideuser(nonposixuser,
a24961
+                                     self.uid_override,
a24961
+                                     self.gid_override
a24961
+                                     ):
a24961
+            self.mod_idrange_auto_private_group(type)
a24961
+            (uid, gid) = self.get_user_id(self.clients[0], nonposixuser)
a24961
+            assert (uid == self.uid_override and gid == self.gid_override)
a24961
+            test_group = self.clients[0].run_command(
a24961
+                ["id", nonposixuser]).stdout_text
a24961
+            assert "domain users@{0}".format(self.ad_domain) in test_group
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_nonposixuser_nondefault_primary_group(self, type):
a24961
+        """
a24961
+        Test for non default primary group.
a24961
+        For hybrid/false gid corresponds to the group testgroup1.
a24961
+        """
a24961
+        nonposixuser1 = "nonposixuser1@%s" % self.ad_domain
a24961
+        self.mod_idrange_auto_private_group(type)
a24961
+        (uid, gid) = self.get_user_id(self.clients[0], nonposixuser1)
a24961
+        if type == "true":
a24961
+            assert uid == gid
a24961
+        else:
a24961
+            test_group = self.clients[0].run_command(["id", nonposixuser1])
a24961
+            gid_str = "gid={0}(testgroup1@{1})".format(gid, self.ad_domain)
a24961
+            group = "groups={0}(testgroup1@{1})".format(gid, self.ad_domain)
a24961
+            assert (gid_str in test_group.stdout_text
a24961
+                    and group in test_group.stdout_text)
a24961
+
a24961
+
a24961
+class TestPosixAutoPrivateGroup(BaseTestTrust):
a24961
+    """
a24961
+    Tests for auto-private-groups option with posix AD trust
a24961
+    Related : https://pagure.io/freeipa/issue/8807
a24961
+    """
a24961
+    topology = 'line'
a24961
+    num_ad_domains = 1
a24961
+    num_clients = 1
a24961
+    num_ad_subdomains = 0
a24961
+    num_ad_treedomains = 0
a24961
+    uid_override = "99999999"
a24961
+    gid_override = "78878787"
a24961
+
a24961
+    def test_add_posix_trust(self):
a24961
+        tasks.configure_dns_for_trust(self.master, self.ad)
a24961
+        tasks.establish_trust_with_ad(
a24961
+            self.master, self.ad_domain,
a24961
+            extra_args=['--range-type', 'ipa-ad-trust-posix'])
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_gidnumber_not_corresponding_existing_group(self, type):
a24961
+        """
a24961
+        Test checks that sssd can resolve AD users which
a24961
+        contain posix attributes (uidNumber and gidNumber)
a24961
+        but there is no group with the corresponding gidNumber.
a24961
+        """
a24961
+        posixuser = "testuser2@%s" % self.ad_domain
a24961
+        self.mod_idrange_auto_private_group(type)
a24961
+        if type != "true":
a24961
+            result = self.clients[0].run_command(['id', posixuser],
a24961
+                                                 raiseonerr=False)
a24961
+            tasks.assert_error(result, "no such user")
a24961
+        else:
a24961
+            (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
+            assert uid == gid
a24961
+            assert uid == '10060'
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_only_uid_number_auto_private_group_default(self, type):
a24961
+        """
a24961
+        Test checks that posix user with only uidNumber defined
a24961
+        and gidNumber not set, auto-private-group
a24961
+        is set to false/true/hybrid
a24961
+        """
a24961
+        posixuser = "testuser1@%s" % self.ad_domain
a24961
+        self.mod_idrange_auto_private_group(type)
a24961
+        if type == "true":
a24961
+            (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
+            assert uid == gid
a24961
+        else:
a24961
+            for host in [self.master, self.clients[0]]:
a24961
+                result = host.run_command(['id', posixuser], raiseonerr=False)
a24961
+                tasks.assert_error(result, "no such user")
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_auto_private_group_primary_group(self, type):
a24961
+        """
a24961
+        Test checks that AD users which contain posix attributes
a24961
+        (uidNumber and gidNumber) and there is primary group
a24961
+        with gid number defined.
a24961
+        """
a24961
+        posixuser = "testuser@%s" % self.ad_domain
a24961
+        self.mod_idrange_auto_private_group(type)
a24961
+        (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
+        test_grp = self.clients[0].run_command(["id", posixuser])
a24961
+        assert uid == '10042'
a24961
+        if type == "true":
a24961
+            assert uid == gid
a24961
+            groups = "groups=10042(testuser@{0}),10047(testgroup@{1})".format(
a24961
+                self.ad_domain, self.ad_domain)
a24961
+            assert groups in test_grp.stdout_text
a24961
+        else:
a24961
+            assert gid == '10047'
a24961
+            groups = "10047(testgroup@{0})".format(self.ad_domain)
a24961
+            assert groups in test_grp.stdout_text
a24961
+
a24961
+    @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
+    def test_idoverride_with_auto_private_group(self, type):
a24961
+        """
a24961
+        Override ad trusted user in default trust view
a24961
+        and set auto-private-groups=[hybrid,true,false]
a24961
+        and ensure that overridden values takes effect.
a24961
+        """
a24961
+        posixuser = "testuser@%s" % self.ad_domain
a24961
+        with self.set_idoverrideuser(posixuser,
a24961
+                                     self.uid_override,
a24961
+                                     self.gid_override):
a24961
+            self.mod_idrange_auto_private_group(type)
a24961
+            (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
+            assert(uid == self.uid_override
a24961
+                   and gid == self.gid_override)
a24961
+            result = self.clients[0].run_command(['id', posixuser])
a24961
+            assert "10047(testgroup@{0})".format(
a24961
+                self.ad_domain) in result.stdout_text
a24961
-- 
a24961
2.35.1
a24961
a24961
From 84381001d2e114b1f29fe89e16155c040b56b80f Mon Sep 17 00:00:00 2001
a24961
From: Anuja More <amore@redhat.com>
a24961
Date: Thu, 10 Feb 2022 17:07:45 +0530
a24961
Subject: [PATCH] mark xfail for
a24961
 test_idoverride_with_auto_private_group[hybrid]
a24961
a24961
Related : https://github.com/SSSD/sssd/issues/5989
a24961
a24961
Signed-off-by: Anuja More <amore@redhat.com>
a24961
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
a24961
Reviewed-By: Anuja More <amore@redhat.com>
a24961
---
a24961
 ipatests/test_integration/test_trust.py | 7 ++++++-
a24961
 1 file changed, 6 insertions(+), 1 deletion(-)
a24961
a24961
diff --git a/ipatests/test_integration/test_trust.py b/ipatests/test_integration/test_trust.py
a24961
index ff2dd9cc8..54bd15462 100644
a24961
--- a/ipatests/test_integration/test_trust.py
a24961
+++ b/ipatests/test_integration/test_trust.py
a24961
@@ -15,6 +15,7 @@ from ipaplatform.paths import paths
a24961
 from ipatests.test_integration.base import IntegrationTest
a24961
 from ipatests.pytest_ipa.integration import tasks
a24961
 from ipatests.pytest_ipa.integration import fips
a24961
+from ipatests.util import xfail_context
a24961
 from ipapython.dn import DN
a24961
 from collections import namedtuple
a24961
 from contextlib import contextmanager
a24961
@@ -1110,7 +1111,11 @@ class TestNonPosixAutoPrivateGroup(BaseTestTrust):
a24961
             assert (uid == self.uid_override and gid == self.gid_override)
a24961
             test_group = self.clients[0].run_command(
a24961
                 ["id", nonposixuser]).stdout_text
a24961
-            assert "domain users@{0}".format(self.ad_domain) in test_group
a24961
+            version = tasks.get_sssd_version(self.clients[0])
a24961
+            with xfail_context(version <= tasks.parse_version('2.6.3')
a24961
+                               and type == "hybrid",
a24961
+                               'https://github.com/SSSD/sssd/issues/5989'):
a24961
+                assert "domain users@{0}".format(self.ad_domain) in test_group
a24961
 
a24961
     @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
     def test_nonposixuser_nondefault_primary_group(self, type):
a24961
-- 
a24961
2.35.1
a24961
a24961
From 7ad500e5d3f7d9af81e8a3137158672c6fafb0b4 Mon Sep 17 00:00:00 2001
a24961
From: Anuja More <amore@redhat.com>
a24961
Date: Thu, 10 Feb 2022 17:29:45 +0530
a24961
Subject: [PATCH] Mark xfail
a24961
 test_gidnumber_not_corresponding_existing_group[true,hybrid]
a24961
a24961
Related : https://github.com/SSSD/sssd/issues/5988
a24961
a24961
Signed-off-by: Anuja More <amore@redhat.com>
a24961
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
a24961
Reviewed-By: Anuja More <amore@redhat.com>
a24961
---
a24961
 ipatests/test_integration/test_trust.py | 9 ++++++---
a24961
 1 file changed, 6 insertions(+), 3 deletions(-)
a24961
a24961
diff --git a/ipatests/test_integration/test_trust.py b/ipatests/test_integration/test_trust.py
a24961
index 54bd15462..c12837815 100644
a24961
--- a/ipatests/test_integration/test_trust.py
a24961
+++ b/ipatests/test_integration/test_trust.py
a24961
@@ -1169,9 +1169,12 @@ class TestPosixAutoPrivateGroup(BaseTestTrust):
a24961
                                                  raiseonerr=False)
a24961
             tasks.assert_error(result, "no such user")
a24961
         else:
a24961
-            (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
-            assert uid == gid
a24961
-            assert uid == '10060'
a24961
+            sssd_version = tasks.get_sssd_version(self.clients[0])
a24961
+            with xfail_context(sssd_version <= tasks.parse_version('2.6.3'),
a24961
+                               'https://github.com/SSSD/sssd/issues/5988'):
a24961
+                (uid, gid) = self.get_user_id(self.clients[0], posixuser)
a24961
+                assert uid == gid
a24961
+                assert uid == '10060'
a24961
 
a24961
     @pytest.mark.parametrize('type', ['hybrid', 'true', "false"])
a24961
     def test_only_uid_number_auto_private_group_default(self, type):
a24961
-- 
a24961
2.35.1
a24961