From cca496b5bc1628d3463e4d17c5669e39e1144da5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Fri, 17 Mar 2017 14:42:14 +0100
Subject: [PATCH] test spf DNS field, refs #20817

---
 tests/test_email.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tests/test_email.py b/tests/test_email.py
index b1f7f0d0..ffaee75e 100755
--- a/tests/test_email.py
+++ b/tests/test_email.py
@@ -46,6 +46,10 @@ def check_listening_port():
         print_green('Postfix is listening port 25 correctly.')
         return True
 
+def check_spf(ip):
+    status, output = subprocess.getstatusoutput('host -t TXT ubicast.eu')
+    if ip in output:
+        return True
 
 def check_relay():
     print('Checking if SMTP relay conforms to conf.')
@@ -57,11 +61,15 @@ def check_relay():
     if not configured_relay:
         # no relay configured, check relayless situations
         domain = '.'.join(conf.get('MS_SERVER_NAME').split('.')[-2:])
+        ip = conf.get('NETWORK_IP')
         with open('/etc/mailname', 'r') as f:
             d = f.read()
             if domain != 'ubicast.tv' and domain not in d:
                 print_red('/etc/mailname does not contain the server domain, emails will probably be treated as spam')
                 return False
+            if not check_spf(ip):
+                print_red('ip %s is not in ubicast.eu SPF and emails sent from support@ubicast.eu will be treated as spam' % ip)
+                return False
     conf_relay = conf.get('EMAIL_SMTP_SERVER')
     if conf_relay != configured_relay:
         print_red('Configured STMP relay (%s) does not match the expected value (%s).' % (configured_relay, conf_relay))
-- 
GitLab