From a3473896a5aba4067b7808c984a2f2c6354d34b3 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 13 Mar 2017 16:02:12 -0700 Subject: [PATCH] Fix error showing some WebDAV verification errors --- chrome/content/zotero/xpcom/storage/webdav.js | 4 +- test/tests/webdavTest.js | 69 ++++++++++++++++--- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index 3ec1c5209..1633efc1c 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -755,7 +755,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = { if (err instanceof Zotero.HTTP.UnexpectedStatusException) { switch (err.status) { case 0: - errorMsg = Zotero.getString('sync.storage.error.serverCouldNotBeReached', uri.host); + errorMsg = Zotero.getString('sync.storage.error.serverCouldNotBeReached', err.channel.URI.host); break; case 401: @@ -766,7 +766,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = { case 403: errorTitle = Zotero.getString('general.permissionDenied'); - errorMsg = Zotero.getString('sync.storage.error.webdav.permissionDenied', uri.path) + errorMsg = Zotero.getString('sync.storage.error.webdav.permissionDenied', err.channel.URI.path) + "\n\n" + Zotero.getString('sync.storage.error.checkFileSyncSettings'); break; diff --git a/test/tests/webdavTest.js b/test/tests/webdavTest.js index d4c5a8c39..ac369aab8 100644 --- a/test/tests/webdavTest.js +++ b/test/tests/webdavTest.js @@ -6,10 +6,6 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { // Components.utils.import("resource://zotero-unit/httpd.js"); - var apiKey = Zotero.Utilities.randomString(24); - var apiPort = 16213; - var apiURL = `http://localhost:${apiPort}/`; - var davScheme = "http"; var davPort = 16214; var davBasePath = "/webdav/"; @@ -50,10 +46,6 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { return params; } - function assertAPIKey(request) { - assert.equal(request.requestHeaders["Zotero-API-Key"], apiKey); - } - beforeEach(function* () { yield resetDB({ thisArg: this, @@ -136,6 +128,7 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { }) after(function* () { + Zotero.HTTP.mock = null; if (win) { win.close(); } @@ -593,7 +586,65 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { assert.equal(item.attachmentSyncedModificationTime, newModTime); assert.isTrue(item.synced); }) - }) + }); + + describe("Verify Server", function () { + it("should show an error for a connection error", function* () { + Zotero.HTTP.mock = null; + Zotero.Prefs.set("sync.storage.url", "127.0.0.1:9999"); + + // Begin install 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.serverCouldNotBeReached', '127.0.0.1') + ); + }); + button.click(); + yield promise1; + + var promise2 = spy.returnValues[0]; + spy.restore(); + yield promise2; + }); + + it("should show an error for a 403", function* () { + Zotero.HTTP.mock = null; + this.httpd.registerPathHandler( + `${davBasePath}zotero/`, + { + handle: function (request, response) { + response.setStatusLine(null, 403, 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 = 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.webdav.permissionDenied', davBasePath + 'zotero/') + ); + }); + button.click(); + yield promise1; + + var promise2 = spy.returnValues[0]; + spy.restore(); + yield promise2; + }); + }); describe("#purgeDeletedStorageFiles()", function () { beforeEach(function () {