diff options
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/compose/test/unit/test_smtpClient.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/comm/mailnews/compose/test/unit/test_smtpClient.js b/comm/mailnews/compose/test/unit/test_smtpClient.js new file mode 100644 index 0000000000..b06ec48560 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_smtpClient.js @@ -0,0 +1,136 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +let server = setupServerDaemon(); +server.start(); +registerCleanupFunction(() => { + server.stop(); +}); + +/** + * Test sending is aborted when alwaysSTARTTLS is set, but the server doesn't + * support STARTTLS. + */ +add_task(async function testAbort() { + server.resetTest(); + let smtpServer = getBasicSmtpServer(server.port); + let identity = getSmtpIdentity("identity@foo.invalid", smtpServer); + // Set to always use STARTTLS. + smtpServer.socketType = Ci.nsMsgSocketType.alwaysSTARTTLS; + + do_test_pending(); + + let urlListener = { + OnStartRunningUrl(url) {}, + OnStopRunningUrl(url, status) { + // Test sending is aborted with NS_ERROR_STARTTLS_FAILED_EHLO_STARTTLS. + Assert.equal(status, 0x80553126); + do_test_finished(); + }, + }; + + // Send a message. + let testFile = do_get_file("data/message1.eml"); + MailServices.smtp.sendMailMessage( + testFile, + "to@foo.invalid", + identity, + "from@foo.invalid", + null, + urlListener, + null, + null, + false, + "", + {}, + {} + ); + server.performTest(); +}); + +/** + * Test client identity extension works. + */ +add_task(async function testClientIdentityExtension() { + server.resetTest(); + let smtpServer = getBasicSmtpServer(server.port); + let identity = getSmtpIdentity("identity@foo.invalid", smtpServer); + // Enable and set clientid to the smtp server. + smtpServer.clientidEnabled = true; + smtpServer.clientid = "uuid-111"; + + // Send a message. + let asyncUrlListener = new PromiseTestUtils.PromiseUrlListener(); + let testFile = do_get_file("data/message1.eml"); + MailServices.smtp.sendMailMessage( + testFile, + "to@foo.invalid", + identity, + "from@foo.invalid", + null, + asyncUrlListener, + null, + null, + false, + "", + {}, + {} + ); + + await asyncUrlListener.promise; + + // Check CLIENTID command is sent. + let transaction = server.playTransaction(); + do_check_transaction(transaction, [ + "EHLO test", + "CLIENTID UUID uuid-111", + "MAIL FROM:<from@foo.invalid> BODY=8BITMIME SIZE=159", + "RCPT TO:<to@foo.invalid>", + "DATA", + ]); +}); + +/** + * Test that when To and Cc/Bcc contain the same address, should send only + * one RCPT TO per address. + */ +add_task(async function testDeduplicateRecipients() { + server.resetTest(); + let smtpServer = getBasicSmtpServer(server.port); + let identity = getSmtpIdentity("identity@foo.invalid", smtpServer); + + // Send a message, notice to1 appears twice in the recipients argument. + let asyncUrlListener = new PromiseTestUtils.PromiseUrlListener(); + let testFile = do_get_file("data/message1.eml"); + MailServices.smtp.sendMailMessage( + testFile, + "to1@foo.invalid,to2@foo.invalid,to1@foo.invalid", + identity, + "from@foo.invalid", + null, + asyncUrlListener, + null, + null, + false, + "", + {}, + {} + ); + + await asyncUrlListener.promise; + + // Check only one RCPT TO is sent for to1. + let transaction = server.playTransaction(); + do_check_transaction(transaction, [ + "EHLO test", + "MAIL FROM:<from@foo.invalid> BODY=8BITMIME SIZE=159", + "RCPT TO:<to1@foo.invalid>", + "RCPT TO:<to2@foo.invalid>", + "DATA", + ]); +}); |