Bug 1783517 - Abort connection if canceled password dialog in NntpClient.jsm. r=mkmelin

Add test_cancelPasswordDialog.js.

Differential Revision: https://phabricator.services.mozilla.com/D154196

--HG--
extra : amend_source : 98a4773ac6e0a46a78749dd69c528f29154a907e
This commit is contained in:
Ping Chen 2022-08-10 20:30:21 +10:00
Родитель 452f5bd534
Коммит 1a477fa4c3
3 изменённых файлов: 67 добавлений и 3 удалений

Просмотреть файл

@ -389,8 +389,8 @@ class NntpClient {
outputStream.write(data, data.length);
streamListener.onDataAvailable(null, inputStream, 0, data.length);
};
this.onDone = () => {
streamListener.onStopRequest(null, Cr.NS_OK);
this.onDone = status => {
streamListener.onStopRequest(null, status);
};
}
@ -725,11 +725,15 @@ class NntpClient {
);
}
if (!this._newsFolder.groupUsername) {
this._newsFolder.getAuthenticationCredentials(
let gotPassword = this._newsFolder.getAuthenticationCredentials(
this._msgWindow,
true,
forcePrompt
);
if (!gotPassword) {
this._actionDone(Cr.NS_ERROR_ABORT);
return;
}
}
this._sendCommand(`AUTHINFO user ${this._newsFolder.groupUsername}`, true);
this._nextAction = this._actionAuthResult;

Просмотреть файл

@ -0,0 +1,59 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
);
/* import-globals-from ../../../test/resources/alertTestUtils.js */
load("../../../resources/alertTestUtils.js");
let daemon = setupNNTPDaemon();
let server = makeServer(NNTP_RFC4643_extension, daemon);
server.start();
registerCleanupFunction(() => {
server.stop();
});
/**
* Test connection should be closed after canceling the password dialog.
*/
add_task(async function cancelPasswordDialog() {
// Mock the password prompt.
registerAlertTestUtils();
// Enforce server auth and trigger a list group request.
let incomingServer = setupLocalServer(server.port);
incomingServer.pushAuth = true;
let listener = new PromiseTestUtils.PromiseStreamListener();
incomingServer.loadNewsUrl(
Services.io.newURI(`news://localhost:${server.port}/*`),
null,
listener
);
// The request should be aborted.
try {
await listener.promise;
} catch (e) {
equal(e, Cr.NS_ERROR_ABORT);
}
// Should send nothing after canceling the password dialog.
let transaction = server.playTransaction();
do_check_transaction(transaction, ["MODE READER"]);
});
function promptUsernameAndPasswordPS(
aParent,
aDialogTitle,
aText,
aUsername,
aPassword,
aCheckMsg,
aCheckState
) {
// Cancel the password dialog.
return false;
}

Просмотреть файл

@ -11,6 +11,7 @@ run-sequentially = Restarts server twice--may work but dangerous
[test_bug403242.js]
[test_bug540288.js]
[test_bug695309.js]
[test_cancelPasswordDialog.js]
[test_filter.js]
[test_getNewsMessage.js]
[test_internalUris.js]