def test_030_test_smtp_settings(self): if runtests.quick_tests_only: raise unittest.SkipTest('Skipping a time consuming test') # Test mail setting in config -> email -> outgoing server if (uvmContext.appManager().isInstantiated(self.appNameSpamCase())): print("smtp case present") else: print("smtp not present") uvmContext.appManager().instantiate(self.appNameSpamCase(), 1) appSP = uvmContext.appManager().app(self.appNameSpamCase()) origAppDataSP = appSP.getSmtpSettings() origMailsettings = uvmContext.mailSender().getSettings() # print(appDataSP) newMailsettings = copy.deepcopy(origMailsettings) newMailsettings['smtpHost'] = global_functions.TEST_SERVER_HOST newMailsettings['smtpPort'] = "6800" newMailsettings['sendMethod'] = 'CUSTOM' uvmContext.mailSender().setSettings(newMailsettings) time.sleep(10) # give it time for exim to restart appDataSP = appSP.getSmtpSettings() appSP.setSmtpSettingsWithoutSafelists(appDataSP) recipient = global_functions.random_email() uvmContext.mailSender().sendTestMessage(recipient) time.sleep(2) # force exim to flush queue subprocess.call(["exim -qff >/dev/null 2>&1"],shell=True,stdout=None,stderr=None) time.sleep(10) uvmContext.mailSender().setSettings(origMailsettings) appSP.setSmtpSettingsWithoutSafelists(origAppDataSP) emailContext = remote_control.run_command("wget -q --timeout=5 -O - http://test.untangle.com/cgi-bin/getEmail.py?toaddress=" + recipient + " 2>&1" ,stdout=True) assert('Test Message' in emailContext)
def test_030_test_smtp_settings(self): if runtests.quick_tests_only: raise unittest.SkipTest('Skipping a time consuming test') # Test mail setting in config -> email -> outgoing server if (uvmContext.appManager().isInstantiated(self.appNameSpamCase())): print("smtp case present") else: print("smtp not present") uvmContext.appManager().instantiate(self.appNameSpamCase(), 1) appSP = uvmContext.appManager().app(self.appNameSpamCase()) origAppDataSP = appSP.getSmtpSettings() origMailsettings = uvmContext.mailSender().getSettings() # print(appDataSP) newMailsettings = copy.deepcopy(origMailsettings) newMailsettings['smtpHost'] = global_functions.TEST_SERVER_HOST newMailsettings['smtpPort'] = "6800" newMailsettings['sendMethod'] = 'CUSTOM' uvmContext.mailSender().setSettings(newMailsettings) time.sleep(10) # give it time for exim to restart appDataSP = appSP.getSmtpSettings() appSP.setSmtpSettingsWithoutSafelists(appDataSP) recipient = global_functions.random_email() uvmContext.mailSender().sendTestMessage(recipient) time.sleep(2) # force exim to flush queue subprocess.call(["exim -qff >/dev/null 2>&1"],shell=True,stdout=None,stderr=None) time.sleep(10) uvmContext.mailSender().setSettings(origMailsettings) appSP.setSmtpSettingsWithoutSafelists(origAppDataSP) emailContext = remote_control.run_command("wget -q --timeout=5 -O - http://test.untangle.com/cgi-bin/getEmail.py?toaddress=" + recipient + " 2>&1" ,stdout=True) assert('Test Message' in emailContext)
def configure_mail_relay(): global orig_mailsettings, test_email_address test_email_address = global_functions.random_email() orig_mailsettings = uvmContext.mailSender().getSettings() new_mailsettings = copy.deepcopy(orig_mailsettings) new_mailsettings['sendMethod'] = 'DIRECT' new_mailsettings['fromAddress'] = test_email_address uvmContext.mailSender().setSettings(new_mailsettings)
def configure_mail_relay(): global orig_mailsettings, test_email_address test_email_address = global_functions.random_email() orig_mailsettings = uvmContext.mailSender().getSettings() new_mailsettings = copy.deepcopy(orig_mailsettings) new_mailsettings['sendMethod'] = 'DIRECT' new_mailsettings['fromAddress'] = test_email_address uvmContext.mailSender().setSettings(new_mailsettings)
def sendSpamMail(host=smtpServerHost, useTLS=False): mailResult = None randomAddress = global_functions.random_email() print("randomAddress: " + randomAddress) if useTLS: mailResult = remote_control.run_command("python mailsender.py [email protected] --to=" + randomAddress + " ./spam-mail/ --host=" + host + " --reconnect --series=30:0,150,100,50,25,0,180 --starttls", stdout=False, nowait=False) else: mailResult = remote_control.run_command("python mailsender.py [email protected] --to=" + randomAddress + " ./spam-mail/ --host=" + host + " --reconnect --series=30:0,150,100,50,25,0,180") return mailResult, randomAddress
def sendSpamMail(host=smtpServerHost, useTLS=False): mailResult = None randomAddress = global_functions.random_email() print("randomAddress: " + randomAddress) if useTLS: mailResult = remote_control.run_command( "python mailsender.py [email protected] --to=" + randomAddress + " ./spam-mail/ --host=" + host + " --reconnect --series=30:0,150,100,50,25,0,180 --starttls", stdout=False, nowait=False) else: mailResult = remote_control.run_command( "python mailsender.py [email protected] --to=" + randomAddress + " ./spam-mail/ --host=" + host + " --reconnect --series=30:0,150,100,50,25,0,180") return mailResult, randomAddress
def test_060_customized_email_alert(self): """Create custom email template and verify alert email is received correctly""" #get settings, backup original settings email_settings = uvmContext.eventManager().getSettings() orig_email_settings = copy.deepcopy(email_settings) admin_settings = uvmContext.adminManager().getSettings() orig_admin_settings = copy.deepcopy(admin_settings) #change admin email to verify sent email new_admin_email = global_functions.random_email() admin_settings["users"]["list"][0]["emailAddress"] = new_admin_email uvmContext.adminManager().setSettings(admin_settings) #set custom email template subject and body new_email_subject = "NEW EMAIL SUBJECT TEST" new_email_body = "NEW EMAIL BODY TEST" email_settings["emailSubject"] = new_email_subject email_settings["emailBody"] = new_email_body #set new alert rule for easy trigger of email new_rule = create_alert_rule("test alert rule", "class", "=", "*SessionEvent*", "localAddr", "=", "*"+remote_control.client_ip+"*", sendEmail=True) email_settings['alertRules']['list'].append(new_rule) #set new settings uvmContext.eventManager().setSettings(email_settings) #send a session remote_control.is_online() time.sleep(4) #check email sent is correct emailFound = False timeout = 5 alertEmail = "" while not emailFound and timeout > 0: timeout -= 1 time.sleep(1) alertEmail = remote_control.run_command("wget -q --timeout=5 -O - http://test.untangle.com/cgi-bin/getEmail.py?toaddress=" + new_admin_email + " 2>&1 | grep TEST" ,stdout=True) if (alertEmail != ""): emailFound = True #set settings back uvmContext.eventManager().setSettings(orig_email_settings) uvmContext.adminManager().setSettings(orig_admin_settings) assert(emailFound)