Advertisement
Guest User

Untitled

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