diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index d9b7e9b0a1..5bd20add62 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -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; diff --git a/test/tests/webdavTest.js b/test/tests/webdavTest.js index 951ed0743e..ae0f1b36a5 100644 --- a/test/tests/webdavTest.js +++ b/test/tests/webdavTest.js @@ -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 () {