def test_send_email_esmtp_no_auth(self): model.db_connect() smtp_account = SMTPAccount(user=User(jid="*****@*****.**"), name="account11", jid="*****@*****.**") smtp_account.host = "localhost" smtp_account.port = 1025 model.db_disconnect() email = smtp_account.create_email("*****@*****.**", "*****@*****.**", "subject", "body") test_func = self.make_test( [ "220 localhost ESMTP\r\n", "250-localhost Hello 127.0.0.1\r\n" + "250-SIZE 52428800\r\n" + "250-PIPELINING\r\n" + "250 HELP\r\n", "250 OK\r\n", "250 Accepted\r\n", "354 Enter message\r\n", None, None, None, None, None, None, None, None, "250 OK\r\n", ], [ "ehlo .*\r\n", "mail FROM:<" + str(email["From"]) + ">.*", "rcpt TO:<" + str(email["To"]) + ">\r\n", "data\r\n", ] + email.as_string().split("\n") + [".\r\n"], lambda self: smtp_account.send_email(email), ) test_func()
def setup_db(self): JCLRunner.setup_db(self) MailAccount.createTable(ifNotExists=True) IMAPAccount.createTable(ifNotExists=True) POP3Account.createTable(ifNotExists=True) AbstractSMTPAccount.createTable(ifNotExists=True) GlobalSMTPAccount.createTable(ifNotExists=True) SMTPAccount.createTable(ifNotExists=True)
def test_filter(self): user1 = User(jid="*****@*****.**") account11 = SMTPAccount(user=user1, name="account11", jid="*****@*****.**") account11.default_account = True account12 = SMTPAccount(user=user1, name="account12", jid="*****@*****.**") message = Message(from_jid="*****@*****.**", to_jid="*****@*****.**", body="message") accounts = self.handler.filter(message, None) self.assertEquals(accounts.count(), 1)
def test__run(self): self.runner.pid_file = "/tmp/jmc.pid" self.runner.db_url = self.db_url def do_nothing(): return (False, 0) self.runner._run(do_nothing) model.db_connection_str = self.runner.db_url model.db_connect() # dropTable should succeed because tables should exist Account.dropTable() PresenceAccount.dropTable() User.dropTable() LegacyJID.dropTable() MailAccount.dropTable() IMAPAccount.dropTable() POP3Account.dropTable() SMTPAccount.dropTable() model.db_disconnect() self.assertFalse(os.access("/tmp/jmc.pid", os.F_OK))
def test_get_default_status_msg_ssl(self): """ Get default status message for SSL IMAPAccount. """ smtp_account = SMTPAccount(user=User(jid="*****@*****.**"), name="account11", jid="*****@*****.**") smtp_account.host = "localhost" smtp_account.port = 1025 smtp_account.login = "******" smtp_account.password = "******" smtp_account.tls = True status_msg = smtp_account.get_default_status_msg(Lang.en) self.assertEquals(status_msg, "smtps://user@localhost:1025")
def test_send_email_esmtp_auth_method2(self): model.db_connect() smtp_account = SMTPAccount(user=User(jid="*****@*****.**"), name="account11", jid="*****@*****.**") smtp_account.host = "localhost" smtp_account.port = 1025 smtp_account.login = "******" smtp_account.password = "******" model.db_disconnect() email = smtp_account.create_email("*****@*****.**", "*****@*****.**", "subject", "body") test_func = self.make_test( [ "220 localhost ESMTP\r\n", "250-localhost Hello 127.0.0.1\r\n" + "250-SIZE 52428800\r\n" + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n" + "250-PIPELINING\r\n" + "250 HELP\r\n", "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n", "535 Incorrect Authentication data\r\n", "334 asd235r4\r\n", "235 Authentication succeeded\r\n", "250 OK\r\n", "250 Accepted\r\n", "354 Enter message\r\n", None, None, None, None, None, None, None, None, "250 OK\r\n", ], [ "ehlo .*\r\n", "AUTH CRAM-MD5\r\n", ".*\r\n", "AUTH LOGIN .*\r\n", ".*\r\n", "mail FROM:<" + str(email["From"]) + ">.*", "rcpt TO:<" + str(email["To"]) + ">\r\n", "data\r\n", ] + email.as_string().split("\n") + [".\r\n"], lambda self: smtp_account.send_email(email), ) test_func()