From d2d507547115618be5eac3ce639efc5ab3101d66 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Mon, 22 May 2017 15:05:00 +0200 Subject: [PATCH] Added a full range of tests for the UNLOCK method --- test/tests/unlock.js | 79 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/test/tests/unlock.js b/test/tests/unlock.js index b28dd193..9076862f 100644 --- a/test/tests/unlock.js +++ b/test/tests/unlock.js @@ -6,7 +6,7 @@ module.exports = (test, options, index) => test('unlock', isValid => { var server = new webdav.WebDAVServer(); server.start(options.port + index); - isValid = isValid.multiple(1, server); + isValid = isValid.multiple(4, server); const _ = (e, cb) => { if(e) isValid(false, e); @@ -42,13 +42,86 @@ module.exports = (test, options, index) => test('unlock', isValid => url: url + '/test.txt', method: 'UNLOCK', headers: { - 'Lock-Token': lock, + 'Lock-Token': lock === 'urn:uuid:24fa520c-520c-14fa-00d6-0000d546f655' ? 'urn:uuid:24fa520c-520c-14fa-00d6-0000d546f656' : 'urn:uuid:24fa520c-520c-14fa-00d6-0000d546f655', Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' } }, (e, res, body) => _(e, () => { - wfsNotOwner.writeFile('/test.txt', 'Content!', (e) => _(e, () => isValid(true))) + if(res.statusCode !== 409) + { + isValid(false, 'A bad Lock-Token must lead to a 409 Conflict'); + return; + } + + request({ + url: url + '/test.txt', + method: 'UNLOCK', + headers: { + 'Lock-Token': lock, + Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' + } + }, (e, res, body) => _(e, () => { + wfsNotOwner.writeFile('/test.txt', 'Content!', (e) => _(e, () => isValid(true))) + })) })) })) })) })) + + server.rootResource.addChild(new webdav.VirtualFile('test2.txt'), e => _(e, () => { + request({ + url: url + '/test2.txt', + method: 'UNLOCK', + headers: { + 'Lock-Token': 'urn:uuid:24fa520c-520c-14fa-00d6-0000d546f655', + Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' + } + }, (e, res, body) => _(e, () => { + isValid(res.statusCode === 409, 'An UNLOCK request to a not locked resource must lead to a 409 Conflict'); + })) + })) + + server.rootResource.addChild(new webdav.VirtualFile('test3.txt'), e => _(e, () => { + request({ + url: url + '/test3.txt', + method: 'LOCK', + headers: { + Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' + }, + body: ''+url+'/user' + }, (e, res, body) => _(e, () => { + const lock = body.substr(body.indexOf('') + ''.length, 'urn:uuid:24fa520c-520c-14fa-00d6-0000d546f655'.length); + + request({ + url: url + '/test3.txt', + method: 'UNLOCK', + headers: { + 'Lock-Token': lock, + Authorization: 'Basic dXNlcm5hbWVYMjpwYXNzd29yZDI=' + } + }, (e, res, body) => _(e, () => { + isValid(res.statusCode === 403, 'An UNLOCK request to a resource not locked by the user must lead to a 403 Forbidden'); + })) + })) + })) + + server.rootResource.addChild(new webdav.VirtualFile('test4.txt'), e => _(e, () => { + request({ + url: url + '/test4.txt', + method: 'LOCK', + headers: { + Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' + }, + body: ''+url+'/user' + }, (e, res, body) => _(e, () => { + request({ + url: url + '/test4.txt', + method: 'UNLOCK', + headers: { + Authorization: 'Basic dXNlcm5hbWVYOnBhc3N3b3Jk' + } + }, (e, res, body) => _(e, () => { + isValid(res.statusCode === 400, 'An UNLOCK request without Lock-Token header must lead to a 400 Bad Request'); + })) + })) + })) }) \ No newline at end of file