Advertisement
Guest User

Untitled

a guest
May 4th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. /**
  2. * Login tests for IMAP
  3. *
  4. * Test code <copied from="test_mailboxes.js">
  5. * and <copied from="test_pop3AuthMethods.js">
  6. *
  7. * BUGS:
  8. * - cleanup after each test doesn't seem to work correctly. Effects:
  9. * - one more "lsub" per test, e.g. "capability", "auth...", "lsub", "lsub", "lsub", "list" in the 3. test.,
  10. * - root folder check succeeds although login failed
  11. * - removeIncomingServer(..., true); (cleanup files) fails.
  12. */
  13.  
  14. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  15. load("../../mailnews/resources/alertTestUtils.js");
  16.  
  17. //const kUsername = "fred";
  18. //const kPassword = "wilma";
  19.  
  20. var acctMgr;
  21. var firstTest = true;
  22. var thisTest;
  23. var test = null;
  24.  
  25. var tests = [
  26. { title: "Cleartext password, with server only supporting old-style login",
  27. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
  28. serverAuthMethods : [],
  29. expectSuccess : true,
  30. transaction: [ "capability", "login", "lsub" ] },
  31. // Just to make sure we clean up properly - in the test and in TB, e.g. don't cache stuff
  32. { title: "Second time Cleartext password, with server only supporting old-style login",
  33. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
  34. serverAuthMethods : [],
  35. expectSuccess : true,
  36. transaction: [ "capability", "login", "lsub" ] },
  37. { title: "Cleartext password, with server supporting AUTH PLAIN, LOGIN and CRAM",
  38. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
  39. serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
  40. expectSuccess : true,
  41. transaction: [ "capability", "authenticate PLAIN", "lsub" ] },
  42. { title: "Cleartext password, with server supporting only AUTH LOGIN",
  43. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordCleartext,
  44. serverAuthMethods : [ "LOGIN" ],
  45. expectSuccess : true,
  46. transaction: [ "capability", "authenticate LOGIN", "lsub" ] },
  47. { title: "Encrypted password, with server supporting PLAIN and CRAM",
  48. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordEncrypted,
  49. serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
  50. expectSuccess : true,
  51. transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ] },
  52. { title: "Encrypted password, with server only supporting AUTH PLAIN and LOGIN (must fail)",
  53. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthPasswordEncrypted,
  54. serverAuthMethods : [ "PLAIN", "LOGIN" ],
  55. expectSuccess : false,
  56. transaction: [ "capability" ] },
  57. { title: "Any secure method, with server supporting AUTH PLAIN and CRAM",
  58. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthSecure,
  59. serverAuthMethods : [ "PLAIN" , "LOGIN", "CRAM-MD5" ],
  60. expectSuccess : true,
  61. transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ] },
  62. { title: "Any secure method, with server only supporting AUTH PLAIN and LOGIN (must fail)",
  63. clientAuthMethod : Ci.nsIMsgIncomingServer.kAuthSecure,
  64. serverAuthMethods : [ "PLAIN" ],
  65. expectSuccess : false,
  66. transaction: [ "capability" ] },
  67. ];
  68.  
  69. function nextTest() {
  70. try {
  71. thisTest = tests.shift();
  72. if (!thisTest)
  73. {
  74. endTest();
  75. return;
  76. }
  77. if (firstTest) {
  78. firstTest = false;
  79. }
  80. else /* doesn't work, hangs on first performTest(...)
  81. {
  82. dump("resetTest()\n");
  83. server.resetTest();
  84. dump("server.performTest()\n");
  85. server.performTest();
  86. } */
  87.  
  88. test = thisTest.title;
  89. dump("NEXT test: " + thisTest.title + "\n");
  90.  
  91. // (re)create fake server
  92. var daemon = new imapDaemon();
  93. var server = makeServer(daemon, "");
  94. server.setDebugLevel(fsDebugAll);
  95. var handler = server._handler;
  96. //handler.kUsername = kUsername;
  97. //handler.kPassword = kPassword;
  98.  
  99. handler.kAuthSchemes = thisTest.serverAuthMethods;
  100.  
  101. // If Mailnews ever caches server capabilities, delete and re-create the incomingServer here
  102. var incomingServer = createLocalIMAPServer();
  103.  
  104. let msgServer = incomingServer;
  105. msgServer.QueryInterface(Ci.nsIMsgIncomingServer);
  106. msgServer.authMethod = thisTest.clientAuthMethod;
  107.  
  108. // connect
  109. dump("performExpand()\n");
  110. incomingServer.performExpand(null);
  111. dump("server.performTest()\n");
  112. server.performTest("LSUB");
  113.  
  114. //dump("checking root folder" + (thisTest.expectSuccess ? "\n" : " (should fail)\n"));
  115. //var rootFolder = incomingServer.rootFolder;
  116. //do_check_eq(thisTest.expectSuccess, rootFolder.containsChildNamed("Inbox")); -- see comment at top
  117. dump("checking protocol transaction log\n");
  118. do_check_transaction(server.playTransaction(), thisTest.transaction, false);
  119.  
  120. do {
  121. dump("closeCachedConnections()\n");
  122. incomingServer.closeCachedConnections();
  123. } while (incomingServer.serverBusy)
  124. incomingServer.shutdown();
  125. incomingServer.clearAllValues();
  126. deleteIMAPServer(incomingServer);
  127. acctMgr.closeCachedConnections();
  128. acctMgr.shutdownServers();
  129. acctMgr.UnloadAccounts();
  130. dump("server.stop()\n");
  131. server.stop();
  132. dump("done with this test\n");
  133.  
  134. } catch (e) {
  135. //server.stop();
  136. //endTest();
  137. do_throw(e);
  138. }
  139.  
  140. //do_timeout(1000, nextTest);
  141. nextTest();
  142. }
  143.  
  144. function deleteIMAPServer(incomingServer) {
  145. if (!incomingServer)
  146. return;
  147. acctMgr.removeIncomingServer(incomingServer, false); // TODO cleanup files = true fails
  148. //incomingServer = null;
  149. acctMgr.removeAccount(acctMgr.defaultAccount);
  150. }
  151.  
  152.  
  153. function run_test() {
  154. do_test_pending();
  155.  
  156. registerAlertTestUtils();
  157. acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
  158. .getService(Ci.nsIMsgAccountManager);
  159.  
  160. nextTest();
  161. }
  162.  
  163. function endTest() {
  164. dump("endTest()\n");
  165.  
  166. var thread = gThreadManager.currentThread;
  167. while (thread.hasPendingEvents())
  168. thread.processNextEvent(true);
  169.  
  170. do_test_finished();
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement