Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ivan Tyagov
jio
Commits
98871f94
Commit
98871f94
authored
Jan 17, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webDav Storage ALLDOCS new API and unit tests
parent
4ccd05a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
161 deletions
+98
-161
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+52
-65
test/jiotests.js
test/jiotests.js
+43
-93
test/responsexml/davlist
test/responsexml/davlist
+3
-3
No files found.
src/jio.storage/davstorage.js
View file @
98871f94
...
@@ -61,18 +61,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -61,18 +61,6 @@ jIO.addStorageType('dav', function (spec, my) {
return
o
;
return
o
;
};
};
/**
* If some other parameters is needed, it returns an error message.
* @method validateState
* @return {string} '' -> ok, 'message' -> error
*/
that
.
validateState
=
function
()
{
if
(
priv
.
secured_username
&&
priv
.
url
)
{
return
''
;
}
return
'
Need at least 2 parameters: "username" and "url".
'
;
};
priv
.
newAsyncModule
=
function
()
{
priv
.
newAsyncModule
=
function
()
{
var
async
=
{};
var
async
=
{};
async
.
call
=
function
(
obj
,
function_name
,
arglist
)
{
async
.
call
=
function
(
obj
,
function_name
,
arglist
)
{
...
@@ -765,59 +753,74 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -765,59 +753,74 @@ jIO.addStorageType('dav', function (spec, my) {
};
};
/**
/**
* Gets a document list from a distant dav storage
.
* Gets a document list from a distant dav storage
* @method allDocs
* @method allDocs
* @param {object} command The JIO command
*/
*/
//{
// "total_rows": 4,
// "rows": [
// {
// "id": "otherdoc",
// "key": "otherdoc",
// "value": {
// "rev": "1-3753476B70A49EA4D8C9039E7B04254C"
// }
// },{...}
// ]
//}
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
rows
=
[],
var
rows
=
[],
url
,
am
=
priv
.
newAsyncModule
(),
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
=
{};
o
.
getContent
=
function
(
file
)
{
o
.
getContent
=
function
(
file
)
{
$
.
ajax
({
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
url
:
priv
.
url
+
'
/
'
+
priv
.
secureDocId
(
file
.
id
)
+
'
?_=
'
+
Date
.
now
(),
priv
.
secured_application_name
+
'
/
'
+
priv
.
secureDocId
(
file
.
id
)
+
type
:
'
GET
'
,
'
?_=
'
+
Date
.
now
(),
type
:
"
GET
"
,
async
:
true
,
async
:
true
,
dataType
:
'
text
'
,
// TODO : is it necessary ?
dataType
:
'
text
'
,
headers
:
{
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
password
)
priv
.
username
+
'
:
'
+
priv
.
password
)
},
},
success
:
function
(
content
)
{
success
:
function
(
content
)
{
file
.
value
.
content
=
content
;
file
.
value
.
content
=
content
;
// WARNING : files can be disordered because
// of asynchronous action
rows
.
push
(
file
);
rows
.
push
(
file
);
am
.
call
(
o
,
'
success
'
);
am
.
call
(
o
,
'
success
'
);
},
},
error
:
function
(
type
)
{
error
:
function
(
type
)
{
type
.
error
=
type
.
statusText
;
// TODO : to lower case
that
.
error
({
type
.
reason
=
'
Cannot get a document
'
+
"
status
"
:
404
,
'
content from DAVStorage
'
;
"
statusText
"
:
"
Not Found
"
,
type
.
message
=
type
.
message
+
'
.
'
;
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Cannot find the document
"
,
"
reason
"
:
"
Cannot get a document from DAVStorage
"
});
am
.
call
(
o
,
'
error
'
,
[
type
]);
am
.
call
(
o
,
'
error
'
,
[
type
]);
}
}
});
});
};
};
o
.
getDocumentList
=
function
()
{
o
.
getDocumentList
=
function
()
{
url
=
priv
.
url
+
'
/
'
;
$
.
ajax
({
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
url
:
url
+
'
?_=
'
+
Date
.
now
(),
priv
.
secured_application_name
+
'
/
'
+
'
?_=
'
+
Date
.
now
(),
async
:
true
,
type
:
'
PROPFIND
'
,
type
:
'
PROPFIND
'
,
async
:
true
,
dataType
:
'
xml
'
,
dataType
:
'
xml
'
,
headers
:
{
crossdomain
:
true
,
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
headers
:
{
Authorization
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
),
),
Depth
:
'
1
'
Depth
:
'
1
'
},
},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
xmlData
)
{
success
:
function
(
xmlData
)
{
var
response
=
$
(
xmlData
).
find
(
'
D
\\
:response, response
'
),
var
response
=
$
(
xmlData
).
find
(
'
D
\\
:response, response
'
),
len
=
response
.
length
;
len
=
response
.
length
;
if
(
len
===
1
)
{
if
(
len
===
1
)
{
return
am
.
call
(
o
,
'
success
'
);
return
am
.
call
(
o
,
'
success
'
);
}
}
...
@@ -833,24 +836,10 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -833,24 +836,10 @@ jIO.addStorageType('dav', function (spec, my) {
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
key
=
file
.
id
;
file
.
key
=
file
.
id
;
});
});
if
(
file
.
id
===
'
.htaccess
'
||
file
.
id
===
'
.htpasswd
'
)
{
// this should probably also filter for the "." in case
return
;
// there is a title.revision. Then we could fill value in
}
// allDocs, too!
$
(
data
).
find
(
'
lp1
\\
:getlastmodified, getlastmodified
'
).
each
(
if
(
command
.
getOption
(
'
include_content
'
))
{
function
()
{
file
.
value
.
_last_modified
=
new
Date
(
$
(
this
).
text
()
).
getTime
();
}
);
$
(
data
).
find
(
'
lp1
\\
:creationdate, creationdate
'
).
each
(
function
()
{
file
.
value
.
_creation_date
=
new
Date
(
$
(
this
).
text
()
).
getTime
();
}
);
if
(
!
command
.
getOption
(
'
metadata_only
'
))
{
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
}
else
{
}
else
{
rows
.
push
(
file
);
rows
.
push
(
file
);
...
@@ -860,17 +849,14 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -860,17 +849,14 @@ jIO.addStorageType('dav', function (spec, my) {
});
});
},
},
error
:
function
(
type
)
{
error
:
function
(
type
)
{
if
(
type
.
status
===
404
)
{
that
.
error
({
type
.
error
=
'
not_found
'
;
"
status
"
:
404
,
type
.
reason
=
'
missing
'
;
"
statusText
"
:
"
Not Found
"
,
am
.
call
(
o
,
'
error
'
,
[
type
]);
"
error
"
:
"
not_found
"
,
}
else
{
"
message
"
:
"
Cannot find the document
"
,
type
.
error
=
type
.
statusText
;
// TODO : to lower case
"
reason
"
:
"
Cannot get a document list from DAVStorage
"
type
.
reason
=
});
'
Cannot get a document list from DAVStorage
'
;
am
.
call
(
o
,
'
retry
'
,
[
type
]);
type
.
message
=
type
.
reason
+
'
.
'
;
am
.
call
(
o
,
'
retry
'
,
[
type
]);
}
}
}
});
});
};
};
...
@@ -895,8 +881,9 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -895,8 +881,9 @@ jIO.addStorageType('dav', function (spec, my) {
rows
:
rows
rows
:
rows
});
});
};
};
// first get the XML list
am
.
call
(
o
,
'
getDocumentList
'
);
am
.
call
(
o
,
'
getDocumentList
'
);
};
// end allDocs
};
return
that
;
return
that
;
});
});
\ No newline at end of file
test/jiotests.js
View file @
98871f94
...
@@ -142,16 +142,8 @@ basicTickFunction = function (obj) {
...
@@ -142,16 +142,8 @@ basicTickFunction = function (obj) {
}
}
},
},
getXML
=
function
(
url
)
{
getXML
=
function
(
url
)
{
var
tmp
=
''
;
var
xml
=
$
.
ajax
({
url
:
url
,
async
:
false
});
$
.
ajax
({
return
xml
.
responseText
;
url
:
url
,
async
:
false
,
dataType
:
'
text
'
,
success
:
function
(
xml
)
{
tmp
=
xml
;
}
});
return
tmp
;
},
},
objectifyDocumentArray
=
function
(
array
)
{
objectifyDocumentArray
=
function
(
array
)
{
var
obj
=
{},
k
;
var
obj
=
{},
k
;
...
@@ -165,6 +157,10 @@ getLastJob = function (id) {
...
@@ -165,6 +157,10 @@ getLastJob = function (id) {
},
},
generateTools
=
function
(
sinon
)
{
generateTools
=
function
(
sinon
)
{
var
o
=
{};
var
o
=
{};
// need to make server requests before activating fakeServer
o
.
davlist
=
getXML
(
'
responsexml/davlist
'
);
o
.
t
=
sinon
;
o
.
t
=
sinon
;
o
.
server
=
o
.
t
.
sandbox
.
useFakeServer
();
o
.
server
=
o
.
t
.
sandbox
.
useFakeServer
();
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
...
@@ -239,7 +235,6 @@ generateTools = function (sinon) {
...
@@ -239,7 +235,6 @@ generateTools = function (sinon) {
o
.
addFakeServerResponse
=
function
(
method
,
path
,
status
,
response
)
{
o
.
addFakeServerResponse
=
function
(
method
,
path
,
status
,
response
)
{
var
url
=
new
RegExp
(
'
https:
\\
/
\\
/ca-davstorage:8080
\\
/
'
+
path
+
var
url
=
new
RegExp
(
'
https:
\\
/
\\
/ca-davstorage:8080
\\
/
'
+
path
+
'
(
\\
?.*|$)
'
);
'
(
\\
?.*|$)
'
);
// console.log("adding response for: "+method+" "+url );
o
.
server
.
respondWith
(
method
,
url
,
o
.
server
.
respondWith
(
method
,
url
,
[
status
,
{
"
Content-Type
"
:
'
application/xml
'
},
response
]
[
status
,
{
"
Content-Type
"
:
'
application/xml
'
},
response
]
);
);
...
@@ -258,7 +253,6 @@ isUuid = function (uuid) {
...
@@ -258,7 +253,6 @@ isUuid = function (uuid) {
return
uuid
.
match
(
"
^
"
+
x
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
x
+
x
+
"
$
"
)
===
null
?
return
uuid
.
match
(
"
^
"
+
x
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
x
+
x
+
"
$
"
)
===
null
?
false
:
true
;
false
:
true
;
};
};
//// QUnit Tests ////
//// QUnit Tests ////
module
(
'
Jio Global tests
'
);
module
(
'
Jio Global tests
'
);
...
@@ -2322,91 +2316,47 @@ test ("Remove", function(){
...
@@ -2322,91 +2316,47 @@ test ("Remove", function(){
// check for credentials in sinon
// check for credentials in sinon
});
});
test
(
"
AllDocs
"
,
function
()
{
/*
var
o
=
generateTools
(
this
);
test ('Get Document List', function () {
// Test if DavStorage can get a list a document.
var o = {};
o
.
jio
=
JIO
.
newJio
({
o.davlist = getXML('responsexml/davlist');
"
type
"
:
"
dav
"
,
o.clock = this.sandbox.useFakeTimers();
"
username
"
:
"
davall
"
,
o.clock.tick(base_tick);
"
password
"
:
"
checkpwd
"
,
o.t = this;
"
url
"
:
"
https://ca-davstorage:8080
"
o.mytest = function (message,metadata_only,value,errnoprop) {
});
var server = o.t.sandbox.useFakeServer();
server.respondWith (
"PROPFIND",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/(\?.*|$)/,
[errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
o.davlist]);
server.respondWith (
"GET",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/file(\?.*|$)/,
[200,{},'content']);
server.respondWith (
"GET",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/memo(\?.*|$)/,
[200,{},'content2']);
o.f = function (err,val) {
if (err) {
result = undefined;
} else {
deepEqual (objectifyDocumentArray(val.rows),
objectifyDocumentArray(value),message);
return;
}
deepEqual (result, value, message);
};
o.t.spy(o,'f');
o.jio.allDocs({metadata_only:metadata_only},o.f);
o.clock.tick(1000);
server.respond();
if (!o.f.calledOnce) {
if (o.f.called) {
ok(false, 'too much results');
} else {
ok(false, 'no response');
}
}
};
o.jio = JIO.newJio({type:'dav',username:'davlist',
password:'checkpwd',
url:'https://ca-davstorage:8080',
application_name:'jiotests'});
o.mytest('fail to get list',true,undefined,404);
o.mytest('getting list',true,[{
id:'file',key:'file',
value:{
_creation_date:1335962911000,
_last_modified:1335962907000
}
},{
id:'memo',key:'memo',
value:{
_creation_date:1335894073000,
_last_modified:1335955713000
}
}],207);
o.mytest('getting list',false,[{
id:'file',key:'file',
value:{
content:'content',
_creation_date:1335962911000,
_last_modified:1335962907000
}
},{
id:'memo',key:'memo',
value:{
content:'content2',
_creation_date:1335894073000,
_last_modified:1335955713000
}
}],207);
o.jio.stop();
// get allDocs, no content
o
.
addFakeServerResponse
(
"
PROPFIND
"
,
""
,
200
,
o
.
davlist
);
o
.
thisShouldBeTheAnswer
=
{
"
rows
"
:
[
{
"
id
"
:
"
alldocs1
"
,
"
key
"
:
"
alldocs1
"
,
"
value
"
:
{}},
{
"
id
"
:
"
alldocs2
"
,
"
key
"
:
"
alldocs2
"
,
"
value
"
:
{}}
],
"
total_rows
"
:
2
}
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (no content)
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// allDocs with option include
o
.
all1
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs1
"
,
"
title
"
:
"
a doc title
"
});
o
.
all2
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs2
"
,
"
title
"
:
"
another doc title
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs1
"
,
200
,
o
.
all1
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs2
"
,
200
,
o
.
all2
);
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (include_docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
o
.
jio
.
stop
();
});
});
*/
/*
/*
module ('Jio ReplicateStorage');
module ('Jio ReplicateStorage');
...
...
test/responsexml/davlist
View file @
98871f94
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<D:multistatus
xmlns:D=
"DAV:"
>
<D:multistatus
xmlns:D=
"DAV:"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests
/
</D:href>
<D:href>
/
some/path
/
</D:href>
<D:propstat>
<D:propstat>
<D:prop>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
</D:propstat>
</D:propstat>
</D:response>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests/file
</D:href>
<D:href>
/
some/path/alldocs1
</D:href>
<D:propstat>
<D:propstat>
<D:prop>
<D:prop>
<lp1:resourcetype/>
<lp1:resourcetype/>
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
</D:propstat>
</D:propstat>
</D:response>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests/memo
</D:href>
<D:href>
/
some/path/alldocs2
</D:href>
<D:propstat>
<D:propstat>
<D:prop>
<D:prop>
<lp1:resourcetype/>
<lp1:resourcetype/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment