Fix WebDAV tests after 276bb99fc9

This commit is contained in:
Dan Stillman 2018-08-09 18:20:02 -04:00
parent 1274d5a4fe
commit 6478a375e3
2 changed files with 14 additions and 4 deletions

View file

@ -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);
}
});
}

View file

@ -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);