Bug 470973 Add unit tests for POP3 and News when hostname/username have changed from their original account values. r=bienvenu
This commit is contained in:
Родитель
46c1ec8836
Коммит
1b82ba4ffc
|
@ -0,0 +1,203 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/**
|
||||
* Authentication tests for POP3 - checks for servers whose details have
|
||||
* changed (e.g. realusername and realhostname are different from username and
|
||||
* hostname).
|
||||
*/
|
||||
var type = null;
|
||||
var test = null;
|
||||
var server;
|
||||
var daemon;
|
||||
var incomingServer;
|
||||
var pop3Service;
|
||||
var firstTest = true;
|
||||
var thisTest;
|
||||
|
||||
// The fake server doesn't support AUTH and CAPA (not part of RFC 1939),
|
||||
// but mailnews correctly tries anyway.
|
||||
var tests = [
|
||||
{ title: "Get New Mail, One Message",
|
||||
messages: ["message1.eml"],
|
||||
transaction: [ "AUTH", "CAPA", "USER testpop3", "PASS pop3test", "STAT", "LIST",
|
||||
"UIDL", "XTND XLST Message-Id",
|
||||
"RETR 1", "DELE 1" ] }
|
||||
];
|
||||
|
||||
var urlListener =
|
||||
{
|
||||
OnStartRunningUrl: function (url) {
|
||||
},
|
||||
OnStopRunningUrl: function (url, result) {
|
||||
try {
|
||||
var transaction = server.playTransaction();
|
||||
|
||||
do_check_transaction(transaction, thisTest.transaction);
|
||||
|
||||
do_check_eq(gLocalInboxFolder.getTotalMessages(false), thisTest.messages.length);
|
||||
|
||||
do_check_eq(result, 0);
|
||||
}
|
||||
catch (e) {
|
||||
// If we have an error, clean up nicely before we throw it.
|
||||
server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
|
||||
do_throw(e);
|
||||
}
|
||||
|
||||
// Let OnStopRunningUrl return cleanly before doing anything else.
|
||||
do_timeout(0, "checkBusy();");
|
||||
}
|
||||
};
|
||||
|
||||
function checkBusy() {
|
||||
if (tests.length == 0) {
|
||||
incomingServer.closeCachedConnections();
|
||||
|
||||
// No more tests, let everything finish
|
||||
server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
|
||||
do_test_finished();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the server hasn't quite finished, just delay a little longer.
|
||||
if (incomingServer.serverBusy ||
|
||||
(incomingServer instanceof Ci.nsIPop3IncomingServer &&
|
||||
incomingServer.runningProtocol)) {
|
||||
do_timeout(20, "checkBusy();");
|
||||
return;
|
||||
}
|
||||
|
||||
testNext();
|
||||
}
|
||||
|
||||
function testNext() {
|
||||
thisTest = tests.shift();
|
||||
|
||||
// Handle the server in a try/catch/finally loop so that we always will stop
|
||||
// the server if something fails.
|
||||
try {
|
||||
if (firstTest) {
|
||||
firstTest = false;
|
||||
|
||||
// Start the fake POP3 server
|
||||
server.start(POP3_PORT);
|
||||
}
|
||||
else
|
||||
server.resetTest();
|
||||
|
||||
// Set up the test
|
||||
test = thisTest.title;
|
||||
daemon.setMessages(thisTest.messages);
|
||||
|
||||
// Now get the mail
|
||||
pop3Service.GetNewMail(null, urlListener, gLocalInboxFolder,
|
||||
incomingServer);
|
||||
|
||||
server.performTest();
|
||||
} catch (e) {
|
||||
server.stop();
|
||||
|
||||
do_throw(e);
|
||||
} finally {
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
// Disable new mail notifications
|
||||
prefSvc.setBoolPref("mail.biff.play_sound", false);
|
||||
prefSvc.setBoolPref("mail.biff.show_alert", false);
|
||||
prefSvc.setBoolPref("mail.biff.show_tray_icon", false);
|
||||
prefSvc.setBoolPref("mail.biff.animate_dock_icon", false);
|
||||
|
||||
// These preferences set up a local pop server that has had its hostname
|
||||
// and username changed from the original settings. We can't do this by
|
||||
// function calls for this test as they would cause the password to be
|
||||
// forgotten when changing the hostname/username and this breaks the test.
|
||||
prefSvc.setCharPref("mail.account.account1.server", "server1");
|
||||
prefSvc.setCharPref("mail.account.account2.server", "server2");
|
||||
prefSvc.setCharPref("mail.account.account2.identities", "id1");
|
||||
prefSvc.setCharPref("mail.accountmanager.accounts", "account1,account2");
|
||||
prefSvc.setCharPref("mail.accountmanager.localfoldersserver", "server1");
|
||||
prefSvc.setCharPref("mail.accountmanager.defaultaccount", "account2");
|
||||
prefSvc.setCharPref("mail.identity.id1.fullName", "testpop3");
|
||||
prefSvc.setCharPref("mail.identity.id1.useremail", "testpop3@localhost");
|
||||
prefSvc.setBoolPref("mail.identity.id1.valid", true);
|
||||
prefSvc.setCharPref("mail.server.server1.directory-rel", "[ProfD]Mail/Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.hostname", "Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.name", "Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.type", "none");
|
||||
prefSvc.setCharPref("mail.server.server1.userName", "nobody");
|
||||
prefSvc.setCharPref("mail.server.server2.directory-rel", "[ProfD]Mail/invalid");
|
||||
prefSvc.setCharPref("mail.server.server2.hostname", "invalid");
|
||||
prefSvc.setCharPref("mail.server.server2.name", "testpop3 on localhost");
|
||||
prefSvc.setIntPref("mail.server.server2.port", 1134);
|
||||
prefSvc.setCharPref("mail.server.server2.realhostname", "localhost");
|
||||
prefSvc.setCharPref("mail.server.server2.realuserName", "testpop3");
|
||||
prefSvc.setCharPref("mail.server.server2.type", "pop3");
|
||||
prefSvc.setCharPref("mail.server.server2.userName", "othername");
|
||||
|
||||
// Passwords File (generated from Mozilla 1.8 branch).
|
||||
var signons = do_get_file("../mailnews/test/data/signons-mailnews1.8-alt.txt");
|
||||
|
||||
// Copy the file to the profile directory
|
||||
signons.copyTo(gProfileDir, "signons.txt");
|
||||
|
||||
// Set up the Server
|
||||
var serverArray = setupServerDaemon();
|
||||
daemon = serverArray[0];
|
||||
server = serverArray[1];
|
||||
|
||||
// Set the server expected username & password to what we have in signons.txt
|
||||
serverArray[2].expectedUsername = "testpop3";
|
||||
serverArray[2].expectedPassword = "pop3test";
|
||||
|
||||
type = "RFC 1939";
|
||||
|
||||
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Ci.nsIMsgAccountManager);
|
||||
|
||||
acctMgr.LoadAccounts();
|
||||
|
||||
gLocalIncomingServer = acctMgr.localFoldersServer;
|
||||
|
||||
var rootFolder = gLocalIncomingServer.rootMsgFolder;
|
||||
|
||||
// Note: Inbox is not created automatically when there is no deferred server,
|
||||
// so we need to create it.
|
||||
gLocalInboxFolder = rootFolder.addSubfolder("Inbox");
|
||||
// a local inbox should have a Mail flag!
|
||||
gLocalInboxFolder.setFlag(Ci.nsMsgFolderFlags.Mail);
|
||||
|
||||
// Create the incoming server with "original" details.
|
||||
incomingServer = acctMgr.getIncomingServer("server2");
|
||||
|
||||
// Check that we haven't got any messages in the folder, if we have its a test
|
||||
// setup issue.
|
||||
do_check_eq(gLocalInboxFolder.getTotalMessages(false), 0);
|
||||
|
||||
pop3Service = Cc["@mozilla.org/messenger/popservice;1"]
|
||||
.getService(Ci.nsIPop3Service);
|
||||
var prefsFile = do_get_file("../testprefs1.js", true);
|
||||
var realPrefSvc = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService);
|
||||
realPrefSvc.savePrefFile(prefsFile);
|
||||
|
||||
do_test_pending();
|
||||
|
||||
testNext();
|
||||
}
|
|
@ -75,6 +75,17 @@ const NNTP_PORT = 1024+119;
|
|||
|
||||
var _server = null;
|
||||
|
||||
function subscribeServer(incomingServer) {
|
||||
// Subscribe to newsgroups
|
||||
incomingServer.QueryInterface(Ci.nsINntpIncomingServer);
|
||||
groups.forEach(function (element) {
|
||||
if (element[1])
|
||||
incomingServer.subscribeToNewsgroup(element[0]);
|
||||
});
|
||||
// Only allow one connection
|
||||
incomingServer.maximumConnectionsNumber = 1;
|
||||
}
|
||||
|
||||
// Sets up the client-side portion of fakeserver
|
||||
function setupLocalServer(port) {
|
||||
if (_server != null)
|
||||
|
@ -90,14 +101,7 @@ function setupLocalServer(port) {
|
|||
account.incomingServer = server;
|
||||
server.valid = true;
|
||||
|
||||
// Subscribe to certain posts
|
||||
server.QueryInterface(Ci.nsINntpIncomingServer);
|
||||
groups.forEach(function (element) {
|
||||
if (element[1])
|
||||
server.subscribeToNewsgroup(element[0]);
|
||||
});
|
||||
// Only allow one connection
|
||||
server.maximumConnectionsNumber = 1;
|
||||
subscribeServer(server);
|
||||
|
||||
_server = server;
|
||||
|
||||
|
@ -109,21 +113,24 @@ const URLCreator = Cc["@mozilla.org/messenger/messageservice;1?type=news"]
|
|||
.QueryInterface(Ci.nsIProtocolHandler);
|
||||
|
||||
// Sets up a protocol object and prepares to run the test for the news url
|
||||
function setupProtocolTest(port, newsUrl) {
|
||||
function setupProtocolTest(port, newsUrl, incomingServer) {
|
||||
var url;
|
||||
if (newsUrl instanceof Ci.nsIMsgMailNewsUrl) {
|
||||
url = newsUrl;
|
||||
} else {
|
||||
url = URLCreator.newURI(newsUrl, null, null);
|
||||
}
|
||||
server = setupLocalServer(port);
|
||||
|
||||
var newsServer = incomingServer;
|
||||
if (!newsServer)
|
||||
newsServer = setupLocalServer(port);
|
||||
|
||||
var listener = {
|
||||
onStartRequest : function () {},
|
||||
onStopRequest : function () {
|
||||
if (!this.called) {
|
||||
this.called = true;
|
||||
server.closeCachedConnections();
|
||||
newsServer.closeCachedConnections();
|
||||
this.called = false;
|
||||
}
|
||||
},
|
||||
|
@ -137,7 +144,7 @@ function setupProtocolTest(port, newsUrl) {
|
|||
}
|
||||
}
|
||||
listener.called = false;
|
||||
server.loadNewsUrl(url, null, listener);
|
||||
newsServer.loadNewsUrl(url, null, listener);
|
||||
}
|
||||
|
||||
function create_post(baseURL, file) {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/**
|
||||
* Authentication tests for NNTP (based on RFC4643).
|
||||
*
|
||||
* Note: Logins for newsgroup servers for 1.8 were stored with either the
|
||||
* default port or the SSL default port. Nothing else!
|
||||
*/
|
||||
|
||||
// The basic daemon to use for testing nntpd.js implementations
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/**
|
||||
* Authentication tests for NNTP (based on RFC4643) - checks for servers whose
|
||||
* details have changed (e.g. realhostname is different from hostname).
|
||||
*
|
||||
* Note: Logins for newsgroup servers for 1.8 were stored with either the
|
||||
* default port or the SSL default port. Nothing else!
|
||||
*/
|
||||
|
||||
// The basic daemon to use for testing nntpd.js implementations
|
||||
var daemon = setupNNTPDaemon();
|
||||
|
||||
// Define these up here for checking with the transaction
|
||||
var type = null;
|
||||
var test = null;
|
||||
|
||||
function run_test() {
|
||||
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
// These preferences set up a local news server that has had its hostname
|
||||
// and username changed from the original settings. We can't do this by
|
||||
// function calls for this test as they would cause the password to be
|
||||
// forgotten when changing the hostname/username and this breaks the test.
|
||||
prefSvc.setCharPref("mail.account.account1.server", "server1");
|
||||
prefSvc.setCharPref("mail.account.account2.server", "server2");
|
||||
prefSvc.setCharPref("mail.account.account2.identities", "id1");
|
||||
prefSvc.setCharPref("mail.accountmanager.accounts", "account1,account2");
|
||||
prefSvc.setCharPref("mail.accountmanager.localfoldersserver", "server1");
|
||||
prefSvc.setCharPref("mail.accountmanager.defaultaccount", "account2");
|
||||
prefSvc.setCharPref("mail.identity.id1.fullName", "testnntp");
|
||||
prefSvc.setCharPref("mail.identity.id1.useremail", "testnntp@localhost");
|
||||
prefSvc.setBoolPref("mail.identity.id1.valid", true);
|
||||
prefSvc.setCharPref("mail.server.server1.directory-rel", "[ProfD]Mail/Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.hostname", "Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.name", "Local Folders");
|
||||
prefSvc.setCharPref("mail.server.server1.type", "none");
|
||||
prefSvc.setCharPref("mail.server.server1.userName", "nobody");
|
||||
prefSvc.setCharPref("mail.server.server2.directory-rel", "[ProfD]Mail/invalid");
|
||||
prefSvc.setCharPref("mail.server.server2.hostname", "invalid");
|
||||
prefSvc.setCharPref("mail.server.server2.name", "testnntp on localhost");
|
||||
prefSvc.setIntPref("mail.server.server2.port", NNTP_PORT);
|
||||
prefSvc.setCharPref("mail.server.server2.realhostname", "localhost");
|
||||
prefSvc.setCharPref("mail.server.server2.type", "nntp");
|
||||
|
||||
type = "RFC 4643";
|
||||
|
||||
// Passwords File (generated from Mozilla 1.8 branch).
|
||||
var signons = do_get_file("../mailnews/test/data/signons-mailnews1.8-alt.txt");
|
||||
|
||||
// Copy the file to the profile directory
|
||||
signons.copyTo(gProfileDir, "signons.txt");
|
||||
|
||||
var handler = new NNTP_RFC4643_extension(daemon);
|
||||
|
||||
var server = new nsMailServer(handler);
|
||||
server.start(NNTP_PORT);
|
||||
|
||||
try {
|
||||
// Note, the uri is for hostname "invalid" which is the original uri. See
|
||||
// setupProtocolTest parameters.
|
||||
var prefix = "news://invalid:"+NNTP_PORT+"/";
|
||||
|
||||
// Test - group subscribe listing
|
||||
test = "news:*";
|
||||
|
||||
// Get the existing incoming server
|
||||
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Ci.nsIMsgAccountManager);
|
||||
|
||||
acctMgr.LoadAccounts();
|
||||
|
||||
// Create the incoming server with "original" details.
|
||||
var incomingServer = acctMgr.getIncomingServer("server2");
|
||||
|
||||
subscribeServer(incomingServer);
|
||||
|
||||
// Now set up and run the tests
|
||||
setupProtocolTest(NNTP_PORT, prefix+"*", incomingServer);
|
||||
server.performTest();
|
||||
var transaction = server.playTransaction();
|
||||
do_check_transaction(transaction, ["MODE READER", "LIST",
|
||||
"AUTHINFO user testnews",
|
||||
"AUTHINFO pass newstest", "LIST"]);
|
||||
|
||||
} catch (e) {
|
||||
dump("NNTP Protocol test "+test+" failed for type RFC 977:\n");
|
||||
try {
|
||||
var trans = server.playTransaction();
|
||||
if (trans)
|
||||
dump("Commands called: "+trans.them+"\n");
|
||||
} catch (exp) {}
|
||||
do_throw(e);
|
||||
}
|
||||
server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#2c
|
||||
.
|
||||
mailbox://othername@invalid
|
||||
\=username=\
|
||||
~b3RoZXJuYW1l
|
||||
*\=password=\
|
||||
~cG9wM3Rlc3Q=
|
||||
.
|
||||
news://invalid:119/#password
|
||||
\=username=\
|
||||
~
|
||||
*\=password=\
|
||||
~bmV3c3Rlc3Q=
|
||||
.
|
||||
news://invalid:119/#username
|
||||
\=username=\
|
||||
~
|
||||
*\=password=\
|
||||
~dGVzdG5ld3M=
|
||||
.
|
Загрузка…
Ссылка в новой задаче