5144c6
From 3cf7fb1014ae40fd5a5278f27577a8196a4af051 Mon Sep 17 00:00:00 2001
5144c6
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5144c6
Date: Fri, 7 Aug 2020 07:51:53 +0200
5144c6
Subject: [PATCH] ipatests: test_epn: add test_EPN_connection_refused
5144c6
MIME-Version: 1.0
5144c6
Content-Type: text/plain; charset=UTF-8
5144c6
Content-Transfer-Encoding: 8bit
5144c6
5144c6
Add a test for EPN behavior when the configured SMTP does not
5144c6
accept connections.
5144c6
5144c6
Fixes: https://pagure.io/freeipa/issue/8445
5144c6
Signed-off-by: François Cami <fcami@redhat.com>
5144c6
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5144c6
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
5144c6
---
5144c6
 ipatests/test_integration/test_epn.py | 27 ++++++++++++++++++++++++---
5144c6
 1 file changed, 24 insertions(+), 3 deletions(-)
5144c6
5144c6
diff --git a/ipatests/test_integration/test_epn.py b/ipatests/test_integration/test_epn.py
5144c6
index c5c73835a..1a25d3710 100644
5144c6
--- a/ipatests/test_integration/test_epn.py
5144c6
+++ b/ipatests/test_integration/test_epn.py
5144c6
@@ -182,14 +182,20 @@ class TestEPN(IntegrationTest):
5144c6
         self,
5144c6
         host,
5144c6
         dry_run=False,
5144c6
+        mailtest=False,
5144c6
         from_nbdays=None,
5144c6
         to_nbdays=None,
5144c6
         raiseonerr=True,
5144c6
         validatejson=True
5144c6
     ):
5144c6
-        result = tasks.ipa_epn(host, raiseonerr=raiseonerr, dry_run=dry_run,
5144c6
-                               from_nbdays=from_nbdays,
5144c6
-                               to_nbdays=to_nbdays)
5144c6
+        result = tasks.ipa_epn(
5144c6
+            host,
5144c6
+            from_nbdays=from_nbdays,
5144c6
+            to_nbdays=to_nbdays,
5144c6
+            mailtest=mailtest,
5144c6
+            dry_run=dry_run,
5144c6
+            raiseonerr=raiseonerr
5144c6
+        )
5144c6
         if validatejson:
5144c6
             json.dumps(json.loads(result.stdout_text), ensure_ascii=False)
5144c6
         return (result.stdout_text, result.stderr_text, result.returncode)
5144c6
@@ -243,6 +249,21 @@ class TestEPN(IntegrationTest):
5144c6
         ck = "192481b52fb591112afd7b55b12a44c6618fdbc7e05a3b1866fd67ec579c51df"
5144c6
         assert cmd2.stdout_text.find(ck) == 0
5144c6
 
5144c6
+    @pytest.mark.xfail(reason='freeipa ticket 8445', strict=True)
5144c6
+    def test_EPN_connection_refused(self):
5144c6
+        """Test EPN behavior when the configured SMTP is down
5144c6
+        """
5144c6
+
5144c6
+        self.master.run_command(["systemctl", "stop", "postfix"])
5144c6
+        (unused, stderr_text, rc) = self._check_epn_output(
5144c6
+            self.master, mailtest=True,
5144c6
+            raiseonerr=False, validatejson=False
5144c6
+        )
5144c6
+        self.master.run_command(["systemctl", "start", "postfix"])
5144c6
+        assert "IPA-EPN: Could not connect to the configured SMTP server" in \
5144c6
+            stderr_text
5144c6
+        assert rc > 0
5144c6
+
5144c6
     def test_EPN_smoketest_1(self):
5144c6
         """No users except admin. Check --dry-run output.
5144c6
            With the default configuration, the result should be an empty list.
5144c6
-- 
5144c6
2.26.2
5144c6
5144c6
From 53f330b053740b169d211aa16b3b36fb61157bbd Mon Sep 17 00:00:00 2001
5144c6
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5144c6
Date: Fri, 7 Aug 2020 06:19:31 +0200
5144c6
Subject: [PATCH] IPA-EPN: Fix SMTP connection error handling
5144c6
MIME-Version: 1.0
5144c6
Content-Type: text/plain; charset=UTF-8
5144c6
Content-Transfer-Encoding: 8bit
5144c6
5144c6
Enhance error message when SMTP is down.
5144c6
5144c6
Fixes: https://pagure.io/freeipa/issue/8445
5144c6
Signed-off-by: François Cami <fcami@redhat.com>
5144c6
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5144c6
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
5144c6
---
5144c6
 ipaclient/install/ipa_epn.py          | 17 ++++++++++-------
5144c6
 ipatests/test_integration/test_epn.py |  1 -
5144c6
 2 files changed, 10 insertions(+), 8 deletions(-)
5144c6
5144c6
diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py
5144c6
index 0d1ae2add..82d7b3f57 100644
5144c6
--- a/ipaclient/install/ipa_epn.py
5144c6
+++ b/ipaclient/install/ipa_epn.py
5144c6
@@ -38,6 +38,7 @@ from email.mime.multipart import MIMEMultipart
5144c6
 from email.mime.text import MIMEText
5144c6
 from email.header import Header
5144c6
 from email.utils import make_msgid
5144c6
+from socket import error as socketerror
5144c6
 
5144c6
 from ipaplatform.paths import paths
5144c6
 from ipalib import api, errors
5144c6
@@ -640,13 +641,15 @@ class MTAClient:
5144c6
                     port=self._smtp_port,
5144c6
                     timeout=self._smtp_timeout,
5144c6
                 )
5144c6
-        except smtplib.SMTPException as e:
5144c6
-            logger.error(
5144c6
-                "IPA-EPN: Unable to connect to %s:%s: %s",
5144c6
-                self._smtp_hostname,
5144c6
-                self._smtp_port,
5144c6
-                e,
5144c6
-            )
5144c6
+        except (socketerror, smtplib.SMTPException) as e:
5144c6
+            msg = \
5144c6
+                "IPA-EPN: Could not connect to the configured SMTP server: " \
5144c6
+                "{host}:{port}: {error}".format(
5144c6
+                    host=self._smtp_hostname,
5144c6
+                    port=self._smtp_port,
5144c6
+                    error=e
5144c6
+                )
5144c6
+            raise admintool.ScriptError(msg)
5144c6
 
5144c6
         try:
5144c6
             self._conn.ehlo()
5144c6
diff --git a/ipatests/test_integration/test_epn.py b/ipatests/test_integration/test_epn.py
5144c6
index 1a25d3710..e03521193 100644
5144c6
--- a/ipatests/test_integration/test_epn.py
5144c6
+++ b/ipatests/test_integration/test_epn.py
5144c6
@@ -249,7 +249,6 @@ class TestEPN(IntegrationTest):
5144c6
         ck = "192481b52fb591112afd7b55b12a44c6618fdbc7e05a3b1866fd67ec579c51df"
5144c6
         assert cmd2.stdout_text.find(ck) == 0
5144c6
 
5144c6
-    @pytest.mark.xfail(reason='freeipa ticket 8445', strict=True)
5144c6
     def test_EPN_connection_refused(self):
5144c6
         """Test EPN behavior when the configured SMTP is down
5144c6
         """
5144c6
-- 
5144c6
2.26.2
5144c6