Blame SOURCES/0013-IPA-EPN-Use-a-helper-to-retrieve-LDAP-attributes-fro_rhbz#1866938.patch

3ed92b
From b95817e35716bbab000633043817202e17d7c53e Mon Sep 17 00:00:00 2001
3ed92b
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
3ed92b
Date: Thu, 6 Aug 2020 17:07:36 +0200
3ed92b
Subject: [PATCH] IPA-EPN: Use a helper to retrieve LDAP attributes from an
3ed92b
 entry
3ed92b
3ed92b
Allow for empty attributes.
3ed92b
3ed92b
Reviewed-By: Francois Cami <fcami@redhat.com>
3ed92b
---
3ed92b
 ipaclient/install/ipa_epn.py | 22 +++++++++++++++-------
3ed92b
 1 file changed, 15 insertions(+), 7 deletions(-)
3ed92b
3ed92b
diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py
3ed92b
index 65f9f3d47..0d1ae2add 100644
3ed92b
--- a/ipaclient/install/ipa_epn.py
3ed92b
+++ b/ipaclient/install/ipa_epn.py
3ed92b
@@ -122,22 +122,30 @@ class EPNUserList:
3ed92b
         """Return len(self)."""
3ed92b
         return len(self._expiring_password_user_dq)
3ed92b
 
3ed92b
+    def get_ldap_attr(self, entry, attr):
3ed92b
+        """Get a single value from a multi-valued attr in a safe way"""
3ed92b
+        return str(entry.get(attr, [""]).pop(0))
3ed92b
+
3ed92b
     def add(self, entry):
3ed92b
         """Parses and appends an LDAP user entry with the uid, cn,
3ed92b
            givenname, sn, krbpasswordexpiration and mail attributes.
3ed92b
         """
3ed92b
         try:
3ed92b
             self._sorted = False
3ed92b
+            if entry.get("mail") is None:
3ed92b
+                logger.error("IPA-EPN: No mail address defined for: %s",
3ed92b
+                             entry.dn)
3ed92b
+                return
3ed92b
             self._expiring_password_user_dq.append(
3ed92b
                 dict(
3ed92b
-                    uid=str(entry["uid"].pop(0)),
3ed92b
-                    cn=str(entry["cn"].pop(0)),
3ed92b
-                    givenname=str(entry["givenname"].pop(0)),
3ed92b
-                    sn=str(entry["sn"].pop(0)),
3ed92b
-                    krbpasswordexpiration=str(
3ed92b
-                        entry["krbpasswordexpiration"].pop(0)
3ed92b
+                    uid=self.get_ldap_attr(entry, "uid"),
3ed92b
+                    cn=self.get_ldap_attr(entry, "cn"),
3ed92b
+                    givenname=self.get_ldap_attr(entry, "givenname"),
3ed92b
+                    sn=self.get_ldap_attr(entry, "sn"),
3ed92b
+                    krbpasswordexpiration=(
3ed92b
+                        self.get_ldap_attr(entry,"krbpasswordexpiration")
3ed92b
                     ),
3ed92b
-                    mail=str(entry["mail"]),
3ed92b
+                    mail=str(entry.get("mail")),
3ed92b
                 )
3ed92b
             )
3ed92b
         except IndexError as e:
3ed92b
-- 
3ed92b
2.26.2
3ed92b
3ed92b
From 8e810d8cf38ec60d76178bd673e218fb05d56c8e Mon Sep 17 00:00:00 2001
3ed92b
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
3ed92b
Date: Thu, 6 Aug 2020 17:13:19 +0200
3ed92b
Subject: [PATCH] IPA-EPN: fix configuration file typo
3ed92b
MIME-Version: 1.0
3ed92b
Content-Type: text/plain; charset=UTF-8
3ed92b
Content-Transfer-Encoding: 8bit
3ed92b
3ed92b
Signed-off-by: François Cami <fcami@redhat.com>
3ed92b
Reviewed-By: Francois Cami <fcami@redhat.com>
3ed92b
---
3ed92b
 client/share/epn.conf | 2 +-
3ed92b
 1 file changed, 1 insertion(+), 1 deletion(-)
3ed92b
3ed92b
diff --git a/client/share/epn.conf b/client/share/epn.conf
3ed92b
index 0e590dfc3..e3645801c 100644
3ed92b
--- a/client/share/epn.conf
3ed92b
+++ b/client/share/epn.conf
3ed92b
@@ -23,7 +23,7 @@ smtp_port = 25
3ed92b
 # Default None (empty value).
3ed92b
 # smtp_password =
3ed92b
 
3ed92b
-# pecifies the number of seconds to wait for SMTP to respond.
3ed92b
+# Specifies the number of seconds to wait for SMTP to respond.
3ed92b
 smtp_timeout = 60
3ed92b
 
3ed92b
 # Specifies the type of secure connection to make. Options are: none,
3ed92b
-- 
3ed92b
2.26.2
3ed92b
3ed92b
From 1b1dbcbe9d83ba35f3cfdd01399f123816ec6e5b Mon Sep 17 00:00:00 2001
3ed92b
From: Rob Crittenden <rcritten@redhat.com>
3ed92b
Date: Thu, 6 Aug 2020 18:57:10 -0400
3ed92b
Subject: [PATCH] IPA-EPN: Test that users without givenname and/or mail are
3ed92b
 handled
3ed92b
3ed92b
The admin user does not have a givenname by default, allow for that.
3ed92b
3ed92b
Report errors for users without a default e-mail address.
3ed92b
3ed92b
Update the SHA256 hash with the typo fix.
3ed92b
3ed92b
Reviewed-By: Francois Cami <fcami@redhat.com>
3ed92b
---
3ed92b
 ipatests/test_integration/test_epn.py | 22 +++++++++++++++++++++-
3ed92b
 1 file changed, 21 insertions(+), 1 deletion(-)
3ed92b
3ed92b
diff --git a/ipatests/test_integration/test_epn.py b/ipatests/test_integration/test_epn.py
3ed92b
index 18f73c722..c5c73835a 100644
3ed92b
--- a/ipatests/test_integration/test_epn.py
3ed92b
+++ b/ipatests/test_integration/test_epn.py
3ed92b
@@ -240,7 +240,7 @@ class TestEPN(IntegrationTest):
3ed92b
         assert epn_conf in cmd1.stdout_text
3ed92b
         assert epn_template in cmd1.stdout_text
3ed92b
         cmd2 = self.master.run_command(["sha256sum", epn_conf])
3ed92b
-        ck = "4c207b5c9c760c36db0d3b2b93da50ea49edcc4002d6d1e7383601f0ec30b957"
3ed92b
+        ck = "192481b52fb591112afd7b55b12a44c6618fdbc7e05a3b1866fd67ec579c51df"
3ed92b
         assert cmd2.stdout_text.find(ck) == 0
3ed92b
 
3ed92b
     def test_EPN_smoketest_1(self):
3ed92b
@@ -591,3 +591,23 @@ class TestEPN(IntegrationTest):
3ed92b
         self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf)
3ed92b
         result = tasks.ipa_epn(self.master, raiseonerr=False)
3ed92b
         assert "smtp_delay cannot be less than zero" in result.stderr_text
3ed92b
+
3ed92b
+    def test_EPN_admin(self):
3ed92b
+        """The admin user is special and has no givenName by default
3ed92b
+           It also doesn't by default have an e-mail address
3ed92b
+           Check --dry-run output.
3ed92b
+        """
3ed92b
+        epn_conf = textwrap.dedent('''
3ed92b
+            [global]
3ed92b
+        ''')
3ed92b
+        self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf)
3ed92b
+        self.master.run_command(
3ed92b
+            ['ipa', 'user-mod', 'admin', '--password-expiration',
3ed92b
+             datetime_to_generalized_time(
3ed92b
+                 datetime.datetime.utcnow() + datetime.timedelta(days=7)
3ed92b
+             )]
3ed92b
+        )
3ed92b
+        (unused, stderr_text, _unused) = self._check_epn_output(
3ed92b
+            self.master, dry_run=True
3ed92b
+        )
3ed92b
+        assert "uid=admin" in stderr_text
3ed92b
-- 
3ed92b
2.26.2
3ed92b