Fix display of a couple WebDAV verification errors
"spec is undefined" Fixes #1745
This commit is contained in:
parent
133b2b83d8
commit
61cebbd8f7
2 changed files with 63 additions and 4 deletions
|
@ -753,9 +753,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
var promptService =
|
||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
||||
createInstance(Components.interfaces.nsIPromptService);
|
||||
if (err.url) {
|
||||
var spec = err.url.scheme + '://' + err.url.hostPort + err.url.pathQueryRef;
|
||||
}
|
||||
|
||||
var errorTitle, errorMsg;
|
||||
|
||||
|
@ -791,6 +788,10 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
}
|
||||
}
|
||||
else if (err instanceof this.VerificationError) {
|
||||
let spec;
|
||||
if (err.uri) {
|
||||
spec = err.uri.scheme + '://' + err.uri.hostPort + err.uri.pathQueryRef;
|
||||
}
|
||||
switch (err.error) {
|
||||
case "NO_URL":
|
||||
errorMsg = Zotero.getString('sync.storage.error.webdav.enterURL');
|
||||
|
@ -810,7 +811,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
|
||||
case "PARENT_DIR_NOT_FOUND":
|
||||
errorTitle = Zotero.getString('sync.storage.error.directoryNotFound');
|
||||
var parentSpec = spec.replace(/\/zotero\/$/, "");
|
||||
var parentSpec = spec.replace(/zotero\/$/, "");
|
||||
errorMsg = Zotero.getString('sync.storage.error.doesNotExist', parentSpec);
|
||||
break;
|
||||
|
||||
|
|
|
@ -657,6 +657,64 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
|
|||
win.close();
|
||||
});
|
||||
|
||||
|
||||
it("should show an error for a 404 for the parent directory", function* () {
|
||||
// Use httpd.js instead of sinon so we get a real nsIURL with a channel
|
||||
Zotero.HTTP.mock = null;
|
||||
Zotero.Prefs.set("sync.storage.url", davHostPath);
|
||||
|
||||
this.httpd.registerPathHandler(
|
||||
`${davBasePath}zotero/`,
|
||||
{
|
||||
handle: function (request, response) {
|
||||
// Force Basic Auth
|
||||
if (!request.hasHeader('Authorization')) {
|
||||
response.setStatusLine(null, 401, null);
|
||||
response.setHeader('WWW-Authenticate', 'Basic realm="WebDAV"', false);
|
||||
return;
|
||||
}
|
||||
response.setHeader('DAV', '1', false);
|
||||
response.setStatusLine(null, 404, "Not Found");
|
||||
}
|
||||
}
|
||||
);
|
||||
this.httpd.registerPathHandler(
|
||||
`${davBasePath}`,
|
||||
{
|
||||
handle: function (request, response) {
|
||||
response.setHeader('DAV', '1', false);
|
||||
if (request.method == 'PROPFIND') {
|
||||
response.setStatusLine(null, 404, null);
|
||||
}
|
||||
/*else {
|
||||
response.setStatusLine(null, 207, null);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Begin verify procedure
|
||||
var win = yield loadPrefPane('sync');
|
||||
var button = win.document.getElementById('storage-verify');
|
||||
|
||||
var spy = sinon.spy(win.Zotero_Preferences.Sync, "verifyStorageServer");
|
||||
var promise1 = waitForDialog(function (dialog) {
|
||||
assert.include(
|
||||
dialog.document.documentElement.textContent,
|
||||
Zotero.getString('sync.storage.error.doesNotExist', davURL)
|
||||
);
|
||||
});
|
||||
button.click();
|
||||
yield promise1;
|
||||
|
||||
var promise2 = spy.returnValues[0];
|
||||
spy.restore();
|
||||
yield promise2;
|
||||
|
||||
win.close();
|
||||
});
|
||||
|
||||
|
||||
it("should show an error for a 200 for a nonexistent file", async function () {
|
||||
Zotero.HTTP.mock = null;
|
||||
this.httpd.registerPathHandler(
|
||||
|
|
Loading…
Reference in a new issue