diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/compose/test/unit/test_bug155172.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/compose/test/unit/test_bug155172.js')
-rw-r--r-- | comm/mailnews/compose/test/unit/test_bug155172.js | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/comm/mailnews/compose/test/unit/test_bug155172.js b/comm/mailnews/compose/test/unit/test_bug155172.js new file mode 100644 index 0000000000..06c14416a7 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_bug155172.js @@ -0,0 +1,140 @@ +/** + * Authentication tests for SMTP. + */ + +/* import-globals-from ../../../test/resources/alertTestUtils.js */ +/* import-globals-from ../../../test/resources/passwordStorage.js */ +load("../../../resources/alertTestUtils.js"); +load("../../../resources/passwordStorage.js"); + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); +const { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +var gNewPassword = null; + +// for alertTestUtils.js +function confirmExPS( + parent, + aDialogTitle, + aText, + aButtonFlags, + aButton0Title, + aButton1Title, + aButton2Title, + aCheckMsg, + aCheckState +) { + // Just return 2 which will is pressing button 2 - enter a new password. + return 2; +} + +function promptPasswordPS( + aParent, + aDialogTitle, + aText, + aPassword, + aCheckMsg, + aCheckState +) { + aPassword.value = gNewPassword; + return true; +} + +var server; + +var kIdentityMail = "identity@foo.invalid"; +var kSender = "from@foo.invalid"; +var kTo = "to@foo.invalid"; +var kUsername = "test.smtp@fakeserver"; +// kPasswordSaved is the one defined in signons-smtp.json, the other one +// is intentionally wrong. +var kPasswordWrong = "wrong"; +var kPasswordSaved = "smtptest"; + +add_task(async function () { + registerAlertTestUtils(); + + function createHandler(d) { + var handler = new SMTP_RFC2821_handler(d); + // Username needs to match the login information stored in the signons json + // file. + handler.kUsername = kUsername; + handler.kPassword = kPasswordWrong; + handler.kAuthRequired = true; + handler.kAuthSchemes = ["PLAIN", "LOGIN"]; // make match expected transaction below + return handler; + } + + server = setupServerDaemon(createHandler); + server.setDebugLevel(fsDebugAll); + + // Prepare files for passwords (generated by a script in bug 1018624). + await setupForPassword("signons-smtp.json"); + + // Test file + var testFile = do_get_file("data/message1.eml"); + + // Ensure we have at least one mail account + localAccountUtils.loadLocalMailAccount(); + + // Handle the server in a try/catch/finally loop so that we always will stop + // the server if something fails. + try { + // Start the fake SMTP server + server.start(); + var smtpServer = getBasicSmtpServer(server.port); + var identity = getSmtpIdentity(kIdentityMail, smtpServer); + + // This time with auth + test = "Auth sendMailMessage"; + + smtpServer.authMethod = Ci.nsMsgAuthMethod.passwordCleartext; + smtpServer.socketType = Ci.nsMsgSocketType.plain; + smtpServer.username = kUsername; + + let urlListener = new PromiseTestUtils.PromiseUrlListener(); + MailServices.smtp.sendMailMessage( + testFile, + kTo, + identity, + kSender, + null, + urlListener, + null, + null, + false, + "", + {}, + {} + ); + + // Set the new password for when we get a prompt + gNewPassword = kPasswordWrong; + + await urlListener.promise; + + var transaction = server.playTransaction(); + do_check_transaction(transaction, [ + "EHLO test", + "AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPasswordSaved), + "AUTH LOGIN", + "AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPasswordWrong), + "MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159", + "RCPT TO:<" + kTo + ">", + "DATA", + ]); + } catch (e) { + do_throw(e); + } finally { + server.stop(); + + var thread = gThreadManager.currentThread; + while (thread.hasPendingEvents()) { + thread.processNextEvent(true); + } + } +}); |