From 6478a375e376722d198621c6380dcd3fcd9aa8af Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 9 Aug 2018 18:20:02 -0400 Subject: [PATCH] Fix WebDAV tests after 276bb99fc9 --- test/content/support.js | 11 +++++++++-- test/tests/webdavTest.js | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/content/support.js b/test/content/support.js index cba1158c07..3d50e009bd 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -894,7 +894,7 @@ function importHTMLAttachment() { * that defines the response * @param {Object} responses - Predefined responses */ -function setHTTPResponse(server, baseURL, response, responses) { +function setHTTPResponse(server, baseURL, response, responses, username, password) { if (typeof response == 'string') { let [topic, key] = response.split('.'); if (!responses[topic]) { @@ -924,5 +924,12 @@ function setHTTPResponse(server, baseURL, response, responses) { responseArray[1][i] = response.headers[i]; } - server.respondWith(response.method, baseURL + response.url, responseArray); + server.respondWith(function (req) { + if (username && req.username != username) return; + if (password && req.password != password) return; + + if (req.method == response.method && req.url == baseURL + response.url) { + req.respond(...responseArray); + } + }); } diff --git a/test/tests/webdavTest.js b/test/tests/webdavTest.js index 8d3cac27b1..4cb270e560 100644 --- a/test/tests/webdavTest.js +++ b/test/tests/webdavTest.js @@ -12,13 +12,13 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { var davHostPath = `localhost:${davPort}${davBasePath}`; var davUsername = "user"; var davPassword = "password"; - var davURL = `${davScheme}://${davUsername}:${davPassword}@${davHostPath}`; + var davURL = `${davScheme}://${davHostPath}`; var win, controller, server, requestCount; var responses = {}; function setResponse(response) { - setHTTPResponse(server, davURL, response, responses); + setHTTPResponse(server, davURL, response, responses, davUsername, davPassword); } function resetRequestCount() { @@ -366,6 +366,9 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { // https://github.com/cjohansen/Sinon.JS/issues/607 let fixSinonBug = ";charset=utf-8"; server.respond(function (req) { + if (req.username != davUsername) return; + if (req.password != davPassword) return; + if (req.method == "PUT" && req.url == `${davURL}zotero/${item.key}.zip`) { assert.equal(req.requestHeaders["Content-Type"], "application/zip" + fixSinonBug);