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_smtpPasswordFailure3.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 '')
-rw-r--r-- | comm/mailnews/compose/test/unit/test_smtpPasswordFailure3.js | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/comm/mailnews/compose/test/unit/test_smtpPasswordFailure3.js b/comm/mailnews/compose/test/unit/test_smtpPasswordFailure3.js new file mode 100644 index 0000000000..27312b47a4 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_smtpPasswordFailure3.js @@ -0,0 +1,154 @@ +/** + * This test checks to see if the smtp password failure is handled correctly + * when the server drops the connection on an authentication error. + * The steps are: + * - Have an invalid password in the password database. + * - Re-initiate connection, this time select enter new password, check that + * we get a new password prompt and can enter the password. + * + */ + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); + +/* import-globals-from ../../../test/resources/alertTestUtils.js */ +/* import-globals-from ../../../test/resources/passwordStorage.js */ +load("../../../resources/alertTestUtils.js"); +load("../../../resources/passwordStorage.js"); + +var server; +var attempt = 0; + +var kIdentityMail = "identity@foo.invalid"; +var kSender = "from@foo.invalid"; +var kTo = "to@foo.invalid"; +var kUsername = "testsmtp"; +// Password needs to match the login information stored in the signons json +// file. +var kValidPassword = "smtptest1"; + +function confirmExPS( + aDialogTitle, + aText, + aButtonFlags, + aButton0Title, + aButton1Title, + aButton2Title, + aCheckMsg, + aCheckState +) { + switch (++attempt) { + // First attempt, retry. + case 1: + dump("\nAttempting Retry\n"); + return 0; + // Second attempt, enter a new password. + case 2: + dump("\nEnter new password\n"); + return 2; + default: + do_throw("unexpected attempt number " + attempt); + return 1; + } +} + +function promptPasswordPS( + aParent, + aDialogTitle, + aText, + aPassword, + aCheckMsg, + aCheckState +) { + if (attempt == 2) { + aPassword.value = kValidPassword; + aCheckState.value = true; + return true; + } + return false; +} + +add_task(async function () { + function createHandler(d) { + var handler = new SMTP_RFC2821_handler(d); + handler.dropOnAuthFailure = true; + // Username needs to match the login information stored in the signons json + // file. + handler.kUsername = kUsername; + handler.kPassword = kValidPassword; + handler.kAuthRequired = true; + handler.kAuthSchemes = ["PLAIN", "LOGIN"]; // make match expected transaction below + return handler; + } + server = setupServerDaemon(createHandler); + + // Prepare files for passwords (generated by a script in bug 1018624). + await setupForPassword("signons-mailnews1.8.json"); + + registerAlertTestUtils(); + + // Test file + var testFile = do_get_file("data/message1.eml"); + + // Ensure we have at least one mail account + localAccountUtils.loadLocalMailAccount(); + + // 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; + + do_test_pending(); + + MailServices.smtp.sendMailMessage( + testFile, + kTo, + identity, + kSender, + null, + URLListener, + null, + null, + false, + "", + {}, + {} + ); + + server.performTest(); +}); + +var URLListener = { + OnStartRunningUrl(url) {}, + OnStopRunningUrl(url, rc) { + // Check for ok status. + Assert.equal(rc, 0); + // Now check the new password has been saved. + let logins = Services.logins.findLogins( + "smtp://localhost", + null, + "smtp://localhost" + ); + + Assert.equal(logins.length, 1); + Assert.equal(logins[0].username, kUsername); + Assert.equal(logins[0].password, kValidPassword); + + server.stop(); + + var thread = gThreadManager.currentThread; + while (thread.hasPendingEvents()) { + thread.processNextEvent(true); + } + + do_test_finished(); + }, +}; |