-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9009ad1
commit 2b9cde8
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"use strict"; | ||
var webdav = require('../../lib/index.js'), | ||
request = require('request'), | ||
xmljs = require('xml-js'); | ||
|
||
module.exports = (test, options, index) => test('lockdiscovery', isValid => | ||
{ | ||
var server = new webdav.WebDAVServer(); | ||
server.start(options.port + index); | ||
isValid = isValid.multiple(1, server); | ||
const _ = (e, cb) => { | ||
if(e) | ||
isValid(false, e); | ||
else | ||
cb(); | ||
} | ||
|
||
server.userManager.addUser('usernameX', 'password'); | ||
const url = 'http://127.0.0.1:' + (options.port + index); | ||
|
||
function propfind(path, callback) | ||
{ | ||
request({ | ||
url: url + path, | ||
method: 'PROPFIND', | ||
}, (e, res, body) => _(e, () => { | ||
try | ||
{ | ||
callback(xmljs.xml2js(body, { compact: true, alwaysArray: true })); | ||
} | ||
catch(e) | ||
{ | ||
isValid(e); | ||
} | ||
})) | ||
} | ||
|
||
server.addResourceTree({ | ||
r: new webdav.VirtualFolder('testFolder'), | ||
c: new webdav.VirtualFile('test5.txt') | ||
}, e => _(e, () => { | ||
propfind('/testFolder', xml => { | ||
const lockdiscovery = xml['D:multistatus'][0]['D:response'][0]['D:propstat'][0]['D:prop'][0]['D:lockdiscovery']; | ||
if(lockdiscovery && Object.keys(lockdiscovery[0]).length !== 0) | ||
{ | ||
isValid(false, 'There must be no D:lockdiscovery element or an empty D:lockdiscovery element in the body of the response of PROPFIND when there is no lock on the resource or on a parent'); | ||
return; | ||
} | ||
|
||
request({ | ||
url: url + '/testFolder', | ||
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, () => { | ||
|
||
function test(path, callback) | ||
{ | ||
propfind(path, xml => { | ||
const activelock = xml['D:multistatus'][0]['D:response'][0]['D:propstat'][0]['D:prop'][0]['D:lockdiscovery'][0]['D:activelock'][0]; | ||
if(activelock['D:locktype'][0]['D:write'][0] | ||
&& activelock['D:lockscope'][0]['D:exclusive'][0] | ||
&& activelock['D:depth'][0]._text.toLowerCase() === 'infinity' | ||
&& activelock['D:owner'][0]['D:href'][0]._text === url | ||
&& activelock['D:locktoken'][0]['D:href'][0] | ||
&& activelock['D:timeout'][0]._text.toLowerCase().indexOf('second-') === 0 | ||
&& activelock['D:lockroot'][0]['D:href'][0]._text === url + '/testFolder') | ||
{ | ||
callback(); | ||
} | ||
else | ||
isValid(false, 'Some values are not valid in D:lockroot or D:timeout or D:owner or D:depth') | ||
}) | ||
} | ||
test('/testFolder', () => { | ||
test('/testFolder/test5.txt', () => isValid(true)) | ||
}) | ||
})) | ||
}) | ||
})) | ||
}) |