Skip to content

Commit

Permalink
Fix error showing some WebDAV verification errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Mar 13, 2017
1 parent 640aaa1 commit a347389
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/storage/webdav.js
Expand Up @@ -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:
Expand All @@ -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;

Expand Down
69 changes: 60 additions & 9 deletions test/tests/webdavTest.js
Expand Up @@ -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/";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -136,6 +128,7 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
})

after(function* () {
Zotero.HTTP.mock = null;
if (win) {
win.close();
}
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit a347389

Please sign in to comment.