Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
4a4b4a5b
Commit
4a4b4a5b
authored
Jun 04, 2012
by
Tristan Cavelier
Committed by
Sebastien Robin
Jun 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding Crypted Storage + Qunit tests.
Load, GetList, and Remove document do not work.
parent
f089c138
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
264 additions
and
8 deletions
+264
-8
OfficeJS/js/sjcl.requirejs_module.js
OfficeJS/js/sjcl.requirejs_module.js
+4
-0
OfficeJS/src/jio.storage.js
OfficeJS/src/jio.storage.js
+181
-5
OfficeJS/test/jiotests.js
OfficeJS/test/jiotests.js
+75
-1
OfficeJS/test/jiotests.loader.js
OfficeJS/test/jiotests.loader.js
+3
-2
OfficeJS/test/jiotests_withoutrequirejs.html
OfficeJS/test/jiotests_withoutrequirejs.html
+1
-0
No files found.
OfficeJS/js/sjcl.requirejs_module.js
0 → 100644
View file @
4a4b4a5b
define
(
'
SJCL
'
,[
'
SJCLAPI
'
],
function
()
{
return
sjcl
;
});
\ No newline at end of file
OfficeJS/src/jio.storage.js
View file @
4a4b4a5b
/**
* Adds
4
storages to JIO.
* Adds
5
storages to JIO.
* - LocalStorage ('local')
* - DAVStorage ('dav')
* - ReplicateStorage ('replicate')
* - IndexedStorage ('indexed')
* - CryptedStorage ('crypted')
*
* @module JIOStorages
*/
(
function
()
{
var
jio_storage_loader
=
function
(
LocalOrCookieStorage
,
Base64
,
Jio
,
$
)
{
var
jio_storage_loader
=
function
(
LocalOrCookieStorage
,
$
,
Base64
,
sjcl
,
Jio
)
{
////////////////////////////////////////////////////////////////////////////
// Tools
...
...
@@ -1016,7 +1018,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
newjob
=
that
.
cloneJob
();
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
loadcallback
;
console
.
log
(
newjob
);
that
.
addJob
(
newjob
);
},
settings
=
that
.
cloneOptionObject
();
...
...
@@ -1077,19 +1078,194 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// end Indexed Storage
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Crypted Storage
/**
* JIO Crypted Storage. Type = 'crypted'.
* It will encrypt the file and its metadata stringified by JSON.
*/
newCryptedStorage
=
function
(
spec
,
my
)
{
// CryptedStorage constructor
var
that
=
Jio
.
newBaseStorage
(
spec
,
my
),
priv
=
{};
priv
.
encrypt
=
function
(
data
,
callback
,
index
)
{
// end with a callback in order to improve encrypt to an
// asynchronous encryption.
var
tmp
=
sjcl
.
encrypt
(
that
.
getStorageUserName
()
+
'
:
'
+
that
.
getStoragePassword
(),
data
);
callback
(
tmp
,
index
);
};
priv
.
decrypt
=
function
(
data
,
callback
,
index
)
{
var
tmp
=
sjcl
.
decrypt
(
that
.
getStorageUserName
()
+
'
:
'
+
that
.
getStoragePassword
(),
data
);
callback
(
tmp
,
index
);
};
/**
* Checks the availability of a user name set in the job.
* @method checkNameAvailability
*/
that
.
checkNameAvailability
=
function
()
{
var
newjob
=
that
.
cloneJob
();
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
that
.
done
(
result
.
return_value
);
}
else
{
that
.
fail
(
result
.
error
);
}
};
that
.
addJob
(
newjob
);
};
// end checkNameAvailability
/**
* Saves a document.
* @method saveDocument
*/
that
.
saveDocument
=
function
()
{
var
newjob
,
newfilename
,
newfilecontent
,
_1
=
function
()
{
priv
.
encrypt
(
that
.
getFileName
(),
function
(
res
)
{
newfilename
=
res
;
_2
();
});
},
_2
=
function
()
{
priv
.
encrypt
(
JSON
.
stringify
({
fileName
:
that
.
getFileName
(),
fileContent
:
that
.
getFileContent
()
}),
function
(
res
)
{
newfilecontent
=
res
;
_3
();
});
},
_3
=
function
()
{
newjob
=
that
.
cloneJob
();
newjob
.
fileName
=
newfilename
;
newjob
.
fileContent
=
newfilecontent
;
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
that
.
done
();
}
else
{
that
.
fail
(
result
.
error
);
}
};
that
.
addJob
(
newjob
);
};
_1
();
};
// end saveDocument
/**
* Loads a document.
* job.options.metadata_only {boolean}
* job.options.content_only {boolean}
* @method loadDocument
*/
that
.
loadDocument
=
function
()
{
var
newjob
,
newfilename
,
_1
=
function
()
{
priv
.
encrypt
(
that
.
getFileName
(),
function
(
res
)
{
newfilename
=
res
;
_2
();
});
},
_2
=
function
()
{
newjob
=
that
.
cloneJob
();
newjob
.
fileName
=
newfilename
;
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
loadcallback
;
console
.
log
(
newjob
);
that
.
addJob
(
newjob
);
},
loadcallback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
priv
.
decrypt
(
result
.
return_value
.
fileContent
,
function
(
res
){
that
.
done
(
JSON
.
parse
(
res
));
});
}
else
{
that
.
fail
(
result
.
error
);
}
};
_1
();
};
// end loadDocument
/**
* Gets a document list.
* @method getDocumentList
*/
that
.
getDocumentList
=
function
()
{
var
newjob
,
i
,
l
,
cpt
=
0
,
array
,
_1
=
function
()
{
newjob
=
that
.
cloneJob
();
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
getListCallback
;
that
.
addJob
(
newjob
);
},
getListCallback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
array
=
result
.
return_value
;
for
(
i
=
0
,
l
=
array
.
length
;
i
<
l
;
i
+=
1
)
{
priv
.
decrypt
(
array
[
i
],
lastCallback
,
i
);
}
}
else
{
that
.
fail
(
result
.
error
);
}
},
lastCallback
=
function
(
res
,
index
)
{
var
tmp
;
cpt
++
;
tmp
=
JSON
.
parse
(
res
);
array
[
index
]
=
res
.
fileName
;
array
[
index
]
=
res
.
fileContent
;
if
(
cpt
===
l
)
{
// this is the last callback
that
.
done
(
array
);
}
};
_1
();
};
// end getDocumentList
/**
* Removes a document.
* @method removeDocument
*/
that
.
removeDocument
=
function
()
{
var
newjob
=
that
.
cloneJob
();
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
that
.
done
();
}
else
{
that
.
fail
(
result
.
error
);
}
};
that
.
addJob
(
newjob
);
};
return
that
;
};
// end Crypted Storage
////////////////////////////////////////////////////////////////////////////
// add key to storageObjectType of global jio
Jio
.
addStorageType
(
'
local
'
,
newLocalStorage
);
Jio
.
addStorageType
(
'
dav
'
,
newDAVStorage
);
Jio
.
addStorageType
(
'
replicate
'
,
newReplicateStorage
);
Jio
.
addStorageType
(
'
indexed
'
,
newIndexedStorage
);
Jio
.
addStorageType
(
'
crypted
'
,
newCryptedStorage
);
};
if
(
window
.
requirejs
)
{
define
(
'
JIOStorages
'
,
[
'
LocalOrCookieStorage
'
,
'
Base64
'
,
'
JIO
'
,
'
jQuery
'
],
[
'
LocalOrCookieStorage
'
,
'
jQuery
'
,
'
Base64
'
,
'
SJCL
'
,
'
JIO
'
],
jio_storage_loader
);
}
else
{
jio_storage_loader
(
LocalOrCookieStorage
,
Base64
,
JIO
,
jQuery
);
jio_storage_loader
(
LocalOrCookieStorage
,
jQuery
,
Base64
,
sjcl
,
JIO
);
}
}());
OfficeJS/test/jiotests.js
View file @
4a4b4a5b
(
function
()
{
var
thisfun
=
function
(
loader
)
{
var
JIO
=
loader
.
JIO
,
LocalOrCookieStorage
=
loader
.
LocalOrCookieStorage
,
sjcl
=
loader
.
sjcl
,
Base64
=
loader
.
Base64
,
$
=
loader
.
jQuery
;
...
...
@@ -391,6 +392,8 @@ test ('Document load', function () {
// re-load file after saving it manually
doc
=
{
'
fileName
'
:
'
file
'
,
'
fileContent
'
:
'
content
'
,
'
lastModified
'
:
1234
,
'
creationDate
'
:
1000
};
LocalOrCookieStorage
.
setItem
(
'
jio/localfilenamearray/MrLoadName/jiotests
'
,
[
'
file
'
]);
LocalOrCookieStorage
.
setItem
(
'
jio/local/MrLoadName/jiotests/file
'
,
doc
);
mytest
(
'
return_value
'
,
doc
);
...
...
@@ -1001,6 +1004,74 @@ test ('Remove document', function () {
o
.
jio
.
stop
();
});
module
(
'
Jio CryptedStorage
'
);
test
(
'
Check name availability
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
crypted
'
,
storage
:{
type
:
'
local
'
,
userName
:
'
cryptcheck
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
true
,
'
name must be available
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
checkNameAvailability
({
userName
:
'
cryptcheck
'
,
maxtries
:
1
,
callback
:
o
.
f
});
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
test
(
'
Document save
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
crypted
'
,
password
:
'
mypwd
'
,
storage
:{
type
:
'
local
'
,
userName
:
'
cryptsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
save ok
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
({
fileName
:
'
testsave
'
,
fileContent
:
'
contentoftest
'
,
maxtries
:
1
,
callback
:
o
.
f
});
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
test
(
'
Document Load
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
crypted
'
,
password
:
'
mypwd
'
,
storage
:{
type
:
'
local
'
,
userName
:
'
cryptload
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
deepEqual
(
result
.
return_value
,{
fileName
:
'
testload
'
,
fileContent
:
'
contentoftest
'
,
lastModified
:
500
,
creationDate
:
500
}
,
'
load ok
'
);
}
else
{
ok
(
false
,
'
cannot load
'
);
}
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
testload
'
,
maxtries
:
1
,
callback
:
o
.
f
});
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
// end require
};
// end thisfun
...
...
@@ -1016,13 +1087,16 @@ if (window.requirejs) {
Base64API
:
'
../lib/base64/base64
'
,
Base64
:
'
../js/base64.requirejs_module
'
,
JIODummyStorages
:
'
../src/jio.dummystorages
'
,
JIOStorages
:
'
../src/jio.storage
'
JIOStorages
:
'
../src/jio.storage
'
,
SJCLAPI
:
'
../lib/sjcl/sjcl
'
,
SJCL
:
'
../js/sjcl.requirejs_module
'
}
});
require
([
'
jiotestsloader
'
],
thisfun
);
}
else
{
thisfun
({
LocalOrCookieStorage
:
LocalOrCookieStorage
,
JIO
:
JIO
,
sjcl
:
sjcl
,
Base64
:
Base64
,
jQuery
:
jQuery
});
}
...
...
OfficeJS/test/jiotests.loader.js
View file @
4a4b4a5b
define
(
'
jiotestsloader
'
,[
'
LocalOrCookieStorage
'
,
'
JIO
'
,
'
Base64
'
,
'
LocalOrCookieStorage
'
,
'
JIO
'
,
'
Base64
'
,
'
SJCL
'
,
'
jQuery
'
,
'
JIODummyStorages
'
,
'
JIOStorages
'
],
function
(
LocalOrCookieStorage
,
JIO
,
Base64
,
jQuery
)
{
function
(
LocalOrCookieStorage
,
JIO
,
Base64
,
sjcl
,
jQuery
)
{
return
{
LocalOrCookieStorage
:
LocalOrCookieStorage
,
JIO
:
JIO
,
sjcl
:
sjcl
,
Base64
:
Base64
,
jQuery
:
jQuery
};
...
...
OfficeJS/test/jiotests_withoutrequirejs.html
View file @
4a4b4a5b
...
...
@@ -15,6 +15,7 @@
</script>
<script
type=
"text/javascript"
src=
"../src/jio.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/base64/base64.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/sjcl/sjcl.js"
></script>
<script
type=
"text/javascript"
src=
"../src/jio.dummystorages.js"
></script>
<script
type=
"text/javascript"
src=
"../src/jio.storage.js"
></script>
<script
type=
"text/javascript"
src=
"jiotests.js"
></script>
...
...
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