Fix "err is undefined" on 200 response for nonexistent WebDAV file

Fixes #1741
This commit is contained in:
Dan Stillman 2019-10-20 15:03:18 -04:00
parent 02eef477ff
commit 956813ac1f
2 changed files with 57 additions and 1 deletions

View file

@ -674,7 +674,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
catch (e) {
if (e instanceof Zotero.HTTP.UnexpectedStatusException) {
if (e.status >= 200 && e.status < 300) {
throw this.VerificationError("NONEXISTENT_FILE_NOT_MISSING", uri);
throw new this.VerificationError("NONEXISTENT_FILE_NOT_MISSING", uri);
}
}
throw e;

View file

@ -656,6 +656,62 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
win.close();
});
it("should show an error for a 200 for a nonexistent file", async function () {
Zotero.HTTP.mock = null;
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);
if (request.method == 'PROPFIND') {
response.setStatusLine(null, 207, null);
}
else {
response.setStatusLine(null, 200, null);
}
}
}
);
this.httpd.registerPathHandler(
`${davBasePath}zotero/nonexistent.prop`,
{
handle: function (request, response) {
response.setStatusLine(null, 200, null);
}
}
);
// Use httpd.js instead of sinon so we get a real nsIURL with a channel
Zotero.Prefs.set("sync.storage.url", davHostPath);
// Begin install procedure
var win = await 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.webdav.nonexistentFileNotMissing', davBasePath + 'zotero/')
);
});
button.click();
await promise1;
var promise2 = spy.returnValues[0];
spy.restore();
await promise2;
win.close();
});
});
describe("#purgeDeletedStorageFiles()", function () {