Commit 74f6eb98 authored by Jonathan Rivalan's avatar Jonathan Rivalan

Validation for unit tests except listing

parent 95d90c8a
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
var b64_hmac_sha1 = sha1.b64_hmac_sha1; var b64_hmac_sha1 = sha1.b64_hmac_sha1;
jIO.addStorage("s3", function (spec, my) { jIO.addStorage("s3", function (spec, my) {
var evt, that, priv = {}, lastDigest; var evt, that, priv = {}, lastDigest, isDelete;
that = this; that = this;
//nomenclature param //nomenclature param
...@@ -260,9 +260,6 @@ ...@@ -260,9 +260,6 @@
return StringToSign; return StringToSign;
}; };
that.encodePolicy = function (form) { that.encodePolicy = function (form) {
//generates the policy //generates the policy
//enables the choice for the http response code //enables the choice for the http response code
...@@ -273,10 +270,7 @@ ...@@ -273,10 +270,7 @@
{"bucket": priv.server }, {"bucket": priv.server },
["starts-with", "$key", ""], ["starts-with", "$key", ""],
{"acl": priv.acl }, {"acl": priv.acl },
{"success_action_redirect": ""}, ["starts-with", "$Content-Type", ""]
{"success_action_status": http_code },
["starts-with", "$Content-Type", ""],
["content-length-range", 0, 524288000]
] ]
}; };
...@@ -321,9 +315,7 @@ ...@@ -321,9 +315,7 @@
if (jio === true) { if (jio === true) {
if (isAttachment === true) { if (isAttachment === true) {
//méthode that.getAttachment //méthode that.getAttachment
console.log(this);
response = this.response; response = this.response;
console.log(response);
command.success(this.status,{'data':response,'digest':lastDigest}); command.success(this.status,{'data':response,'digest':lastDigest});
} }
//n'est pas un attachment //n'est pas un attachment
...@@ -368,13 +360,25 @@ ...@@ -368,13 +360,25 @@
//error //error
//reason "reason" //reason "reason"
//message "did not work" //message "did not work"
err.statustext = "not_foud"; return command.error(
err.reason = "file does not exist"; 404,
err.error = "not_found"; "Not Found",
command.error(err); "File does not exist"
);
} else { } else {
//not jio
callback('404');
if (isDelete === true){
isDelete = false;
return command.error(
404,
"Not Found",
"File does not exist"
);
}
else {
callback('404');
}
} }
} else { } else {
//status //status
...@@ -382,9 +386,13 @@ ...@@ -382,9 +386,13 @@
//error //error
//reason "reason" //reason "reason"
//message "did not work" //message "did not work"
err.error = "not_found"; return command.error(
command.error(err); 404,
"Not Found",
"File does not exist"
);
} }
//fin 404
} }
if (this.status === 409) { if (this.status === 409) {
//status //status
...@@ -392,8 +400,11 @@ ...@@ -392,8 +400,11 @@
//error //error
//reason "reason" //reason "reason"
//message "did not work" //message "did not work"
err.error = "already_exists"; return command.error(
command.error(err); 409,
"Already Exists",
"File does exist"
);
} }
} }
} }
...@@ -478,7 +489,7 @@ ...@@ -478,7 +489,7 @@
+ ":" + ":"
+ Signature); + Signature);
xhr.setRequestHeader("Content-Type", mime); xhr.setRequestHeader("Content-Type", mime);
if (http == 'GET' && jio == true && is_attachment == true){ if (http == 'GET' && jio == true && is_attachment == true){
xhr.responseType = 'blob'; xhr.responseType = 'blob';
} else { } else {
...@@ -508,13 +519,16 @@ ...@@ -508,13 +519,16 @@
* @param {object} command The JIO command * @param {object} command The JIO command
**/ **/
that.post = function (command) { that.post = function (command,metadata) {
//as S3 encoding key are directly inserted within the FormData(), //as S3 encoding key are directly inserted within the FormData(),
//use of XHRwrapper function ain't pertinent //use of XHRwrapper function ain't pertinent
var doc, doc_id, mime; var doc, doc_id, mime;
doc = command.cloneDoc(); doc = metadata;
doc_id = command.getDocId(); doc_id = doc._id;
console.log(doc);
console.log(doc_id);
function postDocument() { function postDocument() {
var http_response, fd, Signature, xhr; var http_response, fd, Signature, xhr;
...@@ -534,15 +548,15 @@ ...@@ -534,15 +548,15 @@
priv.contenTType = "text/plain"; priv.contenTType = "text/plain";
fd.append('Content-Type', priv.contenTType); fd.append('Content-Type', priv.contenTType);
//allows specification of a success url redirection //allows specification of a success url redirection
fd.append('success_action_redirect', ''); //fd.append('success_action_redirect', '');
//allows to specify the http code response if the request is successful //allows to specify the http code response if the request is successful
fd.append('success_action_status', http_response); //fd.append('success_action_status', http_response);
//login AWS //login AWS
fd.append('AWSAccessKeyId', priv.AWSIdentifier); fd.append('AWSAccessKeyId', priv.AWSIdentifier);
//exchange policy with the amazon s3 service //exchange policy with the amazon s3 service
//can be common to all uploads or specific //can be common to all uploads or specific
//that.encodePolicy(fd);
that.encodePolicy(fd); that.encodePolicy(fd);
//priv.b64_policy = that.encodePolicy(fd);
fd.append('policy', priv.b64_policy); fd.append('policy', priv.b64_policy);
//signature through the base64.hmac.sha1(secret key, policy) method //signature through the base64.hmac.sha1(secret key, policy) method
Signature = b64_hmac_sha1(priv.password, priv.b64_policy); Signature = b64_hmac_sha1(priv.password, priv.b64_policy);
...@@ -610,7 +624,12 @@ ...@@ -610,7 +624,12 @@
mime = 'text/plain; charset=UTF-8'; mime = 'text/plain; charset=UTF-8';
that.XHRwrapper(command, docId, '', 'GET', mime, '', isJIO, false, that.XHRwrapper(command, docId, '', 'GET', mime, '', isJIO, false,
function (response) { function (response) {
lastDigest = JSON.parse(response)["_attachments"][param._attachment]['digest']; var responseObj = JSON.parse(response)["_attachments"];
if (responseObj !== undefined){
if (responseObj[param._attachment] !== undefined){
lastDigest = JSON.parse(response)["_attachments"][param._attachment]['digest'];
}
}
getTheAttachment(); getTheAttachment();
}); });
} }
...@@ -654,10 +673,12 @@ ...@@ -654,10 +673,12 @@
that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false, that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false,
function (response) { function (response) {
//if (response === '404') {} var responseObj = JSON.parse(response);
if (response._attachments !== undefined) {
doc._attachments = response._attachments; if (responseObj._attachments !== undefined) {
doc._attachments = responseObj._attachments;
} }
putDocument(); putDocument();
//TODO : control non existing document to throw a 201 http code //TODO : control non existing document to throw a 201 http code
} }
...@@ -682,7 +703,6 @@ ...@@ -682,7 +703,6 @@
attachment_id = param._attachment; attachment_id = param._attachment;
attachment_data = param._blob; attachment_data = param._blob;
console.log(param._blob);
jIO.util.readBlobAsBinaryString(param._blob).then(function (e) { jIO.util.readBlobAsBinaryString(param._blob).then(function (e) {
var binary_string = e.target.result; var binary_string = e.target.result;
...@@ -708,12 +728,16 @@ ...@@ -708,12 +728,16 @@
function putDocument() { function putDocument() {
var attachment_obj, data, doc; var attachment_obj, data, doc;
attachment_mimetype = param._blob.type;
attachment_length = param._blob.size;
attachment_obj = { attachment_obj = {
//"revpos": 3, // optional //"revpos": 3, // optional
"digest": attachment_digest, "digest": attachment_digest,
"content_type": attachment_mimetype, "content_type": attachment_mimetype,
"length": attachment_length "length": attachment_length
}; };
data = JSON.parse(my_document); data = JSON.parse(my_document);
doc = priv.updateMeta(data, docId, attachId, "add", attachment_obj); doc = priv.updateMeta(data, docId, attachId, "add", attachment_obj);
...@@ -750,12 +774,13 @@ ...@@ -750,12 +774,13 @@
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.remove = function (command) { that.remove = function (command,param,options) {
var docId, mime; var docId, mime;
docId = command.getDocId(); docId = param._id;
mime = 'text/plain; charset=UTF-8'; mime = 'text/plain; charset=UTF-8';
isDelete = true;
function deleteDocument() { function deleteDocument() {
isDelete = false;
that.XHRwrapper(command, docId, '', 'DELETE', mime, '', true, false, that.XHRwrapper(command, docId, '', 'DELETE', mime, '', true, false,
function (reponse) { function (reponse) {
command.success({ command.success({
...@@ -794,7 +819,7 @@ ...@@ -794,7 +819,7 @@
); );
}; };
that.removeAttachment = function (command) { that.removeAttachment = function (command,param,options) {
var my_document, var my_document,
docId, docId,
attachId, attachId,
...@@ -806,16 +831,16 @@ ...@@ -806,16 +831,16 @@
attachment_length; attachment_length;
my_document = null; my_document = null;
docId = command.getDocId(); docId = param._id;
attachId = command.getAttachmentId() || ''; attachId = param._attachment;
mime = 'text/plain; charset=UTF-8'; mime = 'text/plain; charset=UTF-8';
//récupération des variables de l'attachement //récupération des variables de l'attachement
attachment_id = command.getAttachmentId(); //attachment_id = command.getAttachmentId();
attachment_data = command.getAttachmentData(); //attachment_data = command.getAttachmentData();
attachment_md5 = command.md5SumAttachmentData(); //attachment_md5 = command.md5SumAttachmentData();
attachment_mimetype = command.getAttachmentMimeType(); //attachment_mimetype = command.getAttachmentMimeType();
attachment_length = command.getAttachmentLength(); //attachment_length = command.getAttachmentLength();
function removeAttachment() { function removeAttachment() {
that.XHRwrapper(command, docId, attachId, 'DELETE', mime, '', true, that.XHRwrapper(command, docId, attachId, 'DELETE', mime, '', true,
...@@ -837,9 +862,17 @@ ...@@ -837,9 +862,17 @@
function getDocument() { function getDocument() {
that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false, that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false,
function (reponse) { function (response) {
my_document = reponse; my_document = response;
putDocument(); if (JSON.parse(my_document)._attachments[attachId] !== undefined){
putDocument();
} else {
return command.error(
404,
"missing attachment",
"This Attachment does not exist"
);
}
} }
); );
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment