Skip to content

Commit

Permalink
Added a full range of tests for the UNLOCK method
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 22, 2017
1 parent 5668628 commit d2d5075
Showing 1 changed file with 76 additions and 3 deletions.
79 changes: 76 additions & 3 deletions test/tests/unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: '<?xml version="1.0" encoding="utf-8" ?><D:lockinfo xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype><D:owner><D:href>'+url+'/user</D:href></D:owner></D:lockinfo>'
}, (e, res, body) => _(e, () => {
const lock = body.substr(body.indexOf('<D:locktoken><D:href>') + '<D:locktoken><D:href>'.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: '<?xml version="1.0" encoding="utf-8" ?><D:lockinfo xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype><D:owner><D:href>'+url+'/user</D:href></D:owner></D:lockinfo>'
}, (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');
}))
}))
}))
})

0 comments on commit d2d5075

Please sign in to comment.