Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Login tests for IMAP
- *
- * Test code <copied from="test_mailboxes.js">
- * and <copied from="test_pop3AuthMethods.js">
- *
- * BUGS:
- * - cleanup after each test doesn't seem to work correctly. Effects:
- * - "lsub" one more time per test
- * - root folder check succeeds although login failed
- */
- Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
- load("../../mailnews/resources/alertTestUtils.js");
- //const kUsername = "fred";
- //const kPassword = "wilma";
- var acctMgr;
- var firstTest = true;
- var thisTest;
- var test = null;
- var tests = [
- { title: "Cleartext password, with server only supporting old-style login",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
- serverAuthMethods : [],
- expectSuccess : true,
- transaction: [ "capability", "login", "lsub", "list" ] },
- // Just to make sure we clean up properly - in the test and in TB, e.g. don't cache stuff
- { title: "Second time Cleartext password, with server only supporting old-style login",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
- serverAuthMethods : [],
- expectSuccess : true,
- transaction: [ "capability", "login", "lsub", "lsub", "list" ] }, // TODO one lsub per test added, see above
- { title: "Cleartext password, with server supporting AUTH PLAIN, LOGIN and CRAM",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
- serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
- expectSuccess : true,
- transaction: [ "capability", "authenticate", "lsub", "lsub", "lsub", "list" ] },
- { title: "Cleartext password, with server supporting only AUTH LOGIN",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
- serverAuthMethods : [ "LOGIN" ],
- expectSuccess : true,
- transaction: [ "capability", "authenticate", "lsub", "lsub", "lsub", "lsub", "list" ] },
- { title: "Encrypted password, with server supporting PLAIN and CRAM",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordEncrypted,
- serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
- expectSuccess : true,
- transaction: [ "capability", "authenticate", "lsub", "lsub", "lsub", "lsub", "lsub", "list" ] },
- { title: "Encrypted password, with server only supporting AUTH PLAIN and LOGIN (must fail)",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordEncrypted,
- serverAuthMethods : [ "PLAIN", "LOGIN" ],
- expectSuccess : false,
- transaction: [ "capability" ] },
- { title: "Any secure method, with server supporting AUTH PLAIN and CRAM",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthSecure,
- serverAuthMethods : [ "PLAIN" , "LOGIN", "CRAM-MD5" ],
- expectSuccess : true,
- transaction: [ "capability", "authenticate", "lsub", "lsub", "lsub", "lsub", "lsub", "lsub", "lsub", "list" ] },
- { title: "Any secure method, with server only supporting AUTH PLAIN and LOGIN (must fail)",
- clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthSecure,
- serverAuthMethods : [ "PLAIN" ],
- expectSuccess : false,
- transaction: [ "capability" ] },
- ];
- function nextTest() {
- try {
- thisTest = tests.shift();
- if (!thisTest)
- {
- endTest();
- return;
- }
- if (firstTest) {
- firstTest = false;
- }
- else /* doesn't work, hangs on first performTest(...)
- {
- dump("resetTest()\n");
- server.resetTest();
- dump("server.performTest()\n");
- server.performTest();
- } */
- test = thisTest.title;
- dump("NEXT test: " + thisTest.title + "\n");
- // (re)create fake server
- var daemon = new imapDaemon();
- var server = makeServer(daemon, "");
- server.setDebugLevel(fsDebugAll);
- var handler = server._handler;
- //handler.kUsername = kUsername;
- //handler.kPassword = kPassword;
- handler.kAuthSchemes = thisTest.serverAuthMethods;
- // If Mailnews ever caches server capabilities, delete and re-create the incomingServer here
- var incomingServer = createLocalIMAPServer();
- let prefBranch = Cc["@mozilla.org/preferences-service;1"]
- .getService(Ci.nsIPrefBranch);
- prefBranch.setBoolPref("mail.server.server1.using_subscription", false);
- prefBranch.setBoolPref("mail.server.server2.using_subscription", false);
- prefBranch.setBoolPref("mail.server.server3.using_subscription", false);
- let msgServer = incomingServer;
- msgServer.QueryInterface(Ci.nsIMsgIncomingServer);
- msgServer.authMethod = thisTest.clientAuthMethod;
- // connect
- dump("performExpand()\n");
- incomingServer.performExpand(null);
- dump("server.performTest()\n");
- //server.performTest("SUBSCRIBE");
- server.performTest("LIST");
- dump("checking root folder" + (thisTest.expectSuccess ? "\n" : " (should fail)\n"));
- var rootFolder = incomingServer.rootFolder;
- //do_check_eq(thisTest.expectSuccess, rootFolder.containsChildNamed("Inbox"));
- dump("checking protocol transaction log\n");
- do_check_transaction(server.playTransaction(), thisTest.transaction, false); // TODO true
- do {
- dump("closeCachedConnections()\n");
- incomingServer.closeCachedConnections();
- } while (incomingServer.serverBusy)
- incomingServer.shutdown();
- incomingServer.clearAllValues();
- deleteIMAPServer(incomingServer);
- dump("server.stop()\n");
- server.stop();
- dump("done with this test\n");
- } catch (e) {
- //server.stop();
- //endTest();
- do_throw(e);
- }
- //do_timeout(1000, nextTest);
- nextTest();
- }
- function deleteIMAPServer(incomingServer) {
- if (!incomingServer)
- return;
- acctMgr.removeIncomingServer(incomingServer, false); // TODO cleanup files = true fails
- acctMgr.removeAccount(acctMgr.defaultAccount);
- incomingServer = null;
- }
- function run_test() {
- do_test_pending();
- registerAlertTestUtils();
- acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
- .getService(Ci.nsIMsgAccountManager);
- nextTest();
- }
- function endTest() {
- dump("endTest()\n");
- var thread = gThreadManager.currentThread;
- while (thread.hasPendingEvents())
- thread.processNextEvent(true);
- do_test_finished();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement