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

Validation for unit tests except listing

parent 95d90c8a
......@@ -17,7 +17,7 @@
var b64_hmac_sha1 = sha1.b64_hmac_sha1;
jIO.addStorage("s3", function (spec, my) {
var evt, that, priv = {}, lastDigest;
var evt, that, priv = {}, lastDigest, isDelete;
that = this;
//nomenclature param
......@@ -260,9 +260,6 @@
return StringToSign;
};
that.encodePolicy = function (form) {
//generates the policy
//enables the choice for the http response code
......@@ -273,10 +270,7 @@
{"bucket": priv.server },
["starts-with", "$key", ""],
{"acl": priv.acl },
{"success_action_redirect": ""},
{"success_action_status": http_code },
["starts-with", "$Content-Type", ""],
["content-length-range", 0, 524288000]
["starts-with", "$Content-Type", ""]
]
};
......@@ -321,9 +315,7 @@
if (jio === true) {
if (isAttachment === true) {
//méthode that.getAttachment
console.log(this);
response = this.response;
console.log(response);
command.success(this.status,{'data':response,'digest':lastDigest});
}
//n'est pas un attachment
......@@ -368,13 +360,25 @@
//error
//reason "reason"
//message "did not work"
err.statustext = "not_foud";
err.reason = "file does not exist";
err.error = "not_found";
command.error(err);
return command.error(
404,
"Not Found",
"File does not exist"
);
} else {
callback('404');
//not jio
if (isDelete === true){
isDelete = false;
return command.error(
404,
"Not Found",
"File does not exist"
);
}
else {
callback('404');
}
}
} else {
//status
......@@ -382,9 +386,13 @@
//error
//reason "reason"
//message "did not work"
err.error = "not_found";
command.error(err);
return command.error(
404,
"Not Found",
"File does not exist"
);
}
//fin 404
}
if (this.status === 409) {
//status
......@@ -392,8 +400,11 @@
//error
//reason "reason"
//message "did not work"
err.error = "already_exists";
command.error(err);
return command.error(
409,
"Already Exists",
"File does exist"
);
}
}
}
......@@ -478,7 +489,7 @@
+ ":"
+ Signature);
xhr.setRequestHeader("Content-Type", mime);
if (http == 'GET' && jio == true && is_attachment == true){
xhr.responseType = 'blob';
} else {
......@@ -508,13 +519,16 @@
* @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(),
//use of XHRwrapper function ain't pertinent
var doc, doc_id, mime;
doc = command.cloneDoc();
doc_id = command.getDocId();
doc = metadata;
doc_id = doc._id;
console.log(doc);
console.log(doc_id);
function postDocument() {
var http_response, fd, Signature, xhr;
......@@ -534,15 +548,15 @@
priv.contenTType = "text/plain";
fd.append('Content-Type', priv.contenTType);
//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
fd.append('success_action_status', http_response);
//fd.append('success_action_status', http_response);
//login AWS
fd.append('AWSAccessKeyId', priv.AWSIdentifier);
//exchange policy with the amazon s3 service
//can be common to all uploads or specific
//that.encodePolicy(fd);
that.encodePolicy(fd);
//priv.b64_policy = that.encodePolicy(fd);
fd.append('policy', priv.b64_policy);
//signature through the base64.hmac.sha1(secret key, policy) method
Signature = b64_hmac_sha1(priv.password, priv.b64_policy);
......@@ -610,7 +624,12 @@
mime = 'text/plain; charset=UTF-8';
that.XHRwrapper(command, docId, '', 'GET', mime, '', isJIO, false,
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();
});
}
......@@ -654,10 +673,12 @@
that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false,
function (response) {
//if (response === '404') {}
if (response._attachments !== undefined) {
doc._attachments = response._attachments;
var responseObj = JSON.parse(response);
if (responseObj._attachments !== undefined) {
doc._attachments = responseObj._attachments;
}
putDocument();
//TODO : control non existing document to throw a 201 http code
}
......@@ -682,7 +703,6 @@
attachment_id = param._attachment;
attachment_data = param._blob;
console.log(param._blob);
jIO.util.readBlobAsBinaryString(param._blob).then(function (e) {
var binary_string = e.target.result;
......@@ -708,12 +728,16 @@
function putDocument() {
var attachment_obj, data, doc;
attachment_mimetype = param._blob.type;
attachment_length = param._blob.size;
attachment_obj = {
//"revpos": 3, // optional
"digest": attachment_digest,
"content_type": attachment_mimetype,
"length": attachment_length
};
data = JSON.parse(my_document);
doc = priv.updateMeta(data, docId, attachId, "add", attachment_obj);
......@@ -750,12 +774,13 @@
* @param {object} command The JIO command
*/
that.remove = function (command) {
that.remove = function (command,param,options) {
var docId, mime;
docId = command.getDocId();
docId = param._id;
mime = 'text/plain; charset=UTF-8';
isDelete = true;
function deleteDocument() {
isDelete = false;
that.XHRwrapper(command, docId, '', 'DELETE', mime, '', true, false,
function (reponse) {
command.success({
......@@ -794,7 +819,7 @@
);
};
that.removeAttachment = function (command) {
that.removeAttachment = function (command,param,options) {
var my_document,
docId,
attachId,
......@@ -806,16 +831,16 @@
attachment_length;
my_document = null;
docId = command.getDocId();
attachId = command.getAttachmentId() || '';
docId = param._id;
attachId = param._attachment;
mime = 'text/plain; charset=UTF-8';
//récupération des variables de l'attachement
attachment_id = command.getAttachmentId();
attachment_data = command.getAttachmentData();
attachment_md5 = command.md5SumAttachmentData();
attachment_mimetype = command.getAttachmentMimeType();
attachment_length = command.getAttachmentLength();
//attachment_id = command.getAttachmentId();
//attachment_data = command.getAttachmentData();
//attachment_md5 = command.md5SumAttachmentData();
//attachment_mimetype = command.getAttachmentMimeType();
//attachment_length = command.getAttachmentLength();
function removeAttachment() {
that.XHRwrapper(command, docId, attachId, 'DELETE', mime, '', true,
......@@ -837,9 +862,17 @@
function getDocument() {
that.XHRwrapper(command, docId, '', 'GET', mime, '', false, false,
function (reponse) {
my_document = reponse;
putDocument();
function (response) {
my_document = response;
if (JSON.parse(my_document)._attachments[attachId] !== undefined){
putDocument();
} else {
return command.error(
404,
"missing attachment",
"This Attachment does not exist"
);
}
}
);
}
......
......@@ -71,12 +71,13 @@
"id": "<uuid>",
"method": "post",
"result": "success",
"status": 201,
"statusText": "Created"
"status": 204,
"statusText": "No Content"
}, "Post a new document");
ok(test_util.isUuid(uuid), "New document id should look like " +
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx : " + uuid);
ok(/^no_document_id_[0-9]+$/.test(uuid), "New document id should look like " +
"no_document_id_479658600408584 : " + uuid);
shared.created_document_id = uuid;
}
function getCreatedDocument() {
......@@ -114,8 +115,8 @@
"id": "b",
"method": "post",
"result": "success",
"status": 201,
"statusText": "Created"
"status": 204,
"statusText": "No Content"
}, "Post specific document");
}
......@@ -380,9 +381,9 @@
deepEqual(answer, {
"error": "conflict",
"id": "a",
"message": "DavStorage, cannot overwrite document metadata.",
"message": "Cannot create document",
"method": "post",
"reason": "Document exists",
"reason": "Document already exists",
"result": "error",
"status": 409,
"statusText": "Conflict"
......@@ -409,8 +410,8 @@
function createAttachmentTest(answer) {
deepEqual(answer, {
"attachment": "aa",
"digest": "sha256-9834876dcfb05cb167a5c24953eba58c4" +
"ac89b1adf57f28f2f9d09af107ee8f0",
"digest":"sha256-9834876dcfb05cb167a5c24953eba58c4"+
"ac89b1adf57f28f2f9d09af107ee8f0",
"id": "a",
"method": "putAttachment",
"result": "success",
......@@ -428,8 +429,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-9834876dcfb05cb167a5c24953eba58c4" +
"ac89b1adf57f28f2f9d09af107ee8f0",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
}
}
......@@ -447,8 +448,8 @@
function updateAttachmentTest(answer) {
deepEqual(answer, {
"attachment": "aa",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"id": "a",
"method": "putAttachment",
"result": "success",
......@@ -466,8 +467,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
}
}
......@@ -504,8 +505,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -525,8 +526,8 @@
"id": "a",
"method": "put",
"result": "success",
"status": 204,
"statusText": "No Content"
"status": 200,
"statusText": "Ok"
}, "Update document metadata");
}
......@@ -539,8 +540,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -563,8 +564,8 @@
deepEqual(answer, {
"attachment": "aa",
"data": "<blob>",
"digest": "sha256-9834876dcfb05cb167a5c24953eba58c4"+
"ac89b1adf57f28f2f9d09af107ee8f0",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"id": "a",
"method": "getAttachment",
"result": "success",
......@@ -573,7 +574,7 @@
}, "Get first attachment");
return jIO.util.readBlobAsText(blob).then(function (e) {
deepEqual(blob.type, "text/plain", "Check blob type");
deepEqual(e.target.result, "aaa", "Check blob text content");
deepEqual(e.target.result, "aab", "Check blob text content");
}, function (err) {
deepEqual(err, "no error", "Check blob text content");
});
......@@ -588,8 +589,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -637,8 +638,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -660,8 +661,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -689,8 +690,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
},
"ab": {
......@@ -726,8 +727,8 @@
"_attachments": {
"aa": {
"content_type": "text/plain",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5" +
"0728e095ff24218119d51bd22475363",
"digest": "sha256-38760eabb666e8e61ee628a17c4090cc5"+
"0728e095ff24218119d51bd22475363",
"length": 3
}
}
......@@ -740,9 +741,9 @@
"attachment": "ab",
"error": "not_found",
"id": "a",
"message": "DavStorage, unable to get attachment.",
"message": "File does not exist",
"method": "getAttachment",
"reason": "missing attachment",
"reason": "Not Found",
"result": "error",
"status": 404,
"statusText": "Not Found"
......@@ -812,7 +813,7 @@
"attachment": "ab",
"error": "not_found",
"id": "a",
"message": "DavStorage, document attachment not found.",
"message": "This Attachment does not exist",
"method": "removeAttachment",
"reason": "missing attachment",
"result": "error",
......@@ -861,9 +862,9 @@
"attachment": "aa",
"error": "not_found",
"id": "a",
"message": "DavStorage, unable to get attachment.",
"message": "File does not exist",
"method": "getAttachment",
"reason": "missing document",
"reason": "Not Found",
"result": "error",
"status": 404,
"statusText": "Not Found"
......@@ -879,7 +880,7 @@
deepEqual(answer, {
"error": "not_found",
"id": "a",
"message": "DavStorage, unable to get document.",
"message": "File does not exist",
"method": "get",
"reason": "Not Found",
"result": "error",
......@@ -897,7 +898,7 @@
deepEqual(answer, {
"error": "not_found",
"id": "a",
"message": "DavStorage, unable to get metadata.",
"message": "File does not exist",
"method": "remove",
"reason": "Not Found",
"result": "error",
......@@ -919,57 +920,57 @@
// # Post new documents, list them and remove them
// post a 201
//postNewDocument().then(postNewDocumentTest).
postNewDocument().then(postNewDocumentTest).
// get 200
//then(getCreatedDocument).then(getCreatedDocumentTest).
then(getCreatedDocument).then(getCreatedDocumentTest).
// post b 201
//then(postSpecificDocument).then(postSpecificDocumentTest).
then(postSpecificDocument).then(postSpecificDocumentTest).
// allD 200 2 documents
//then(listDocuments).then(list2DocumentsTest).
then(listDocuments).then(list2DocumentsTest).
// remove a 204
//then(removeCreatedDocument).then(removeCreatedDocumentTest).
then(removeCreatedDocument).then(removeCreatedDocumentTest).
// remove b 204
//then(removeSpecificDocument).then(removeSpecificDocumentTest).
then(removeSpecificDocument).then(removeSpecificDocumentTest).
// allD 200 empty storage
//then(listEmptyStorage).then(listEmptyStorageTest).
then(listEmptyStorage).then(listEmptyStorageTest).
// # Create and update documents, and some attachment and remove them
// put 201
putNewDocument().then(putNewDocumentTest).
then(putNewDocument).then(putNewDocumentTest).
// get 200
then(getCreatedDocument2).then(getCreatedDocument2Test).
// post 409
//then(postSameDocument).then(postSameDocumentTest).
then(postSameDocument).then(postSameDocumentTest).
// putA a 204
then(createAttachment).then(createAttachmentTest).
// putA a 204
//then(updateAttachment).then(updateAttachmentTest).
then(updateAttachment).then(updateAttachmentTest).
// putA b 204
//then(createAnotherAttachment).then(createAnotherAttachmentTest).
then(createAnotherAttachment).then(createAnotherAttachmentTest).
// put 204
//then(updateLastDocument).then(updateLastDocumentTest).
then(updateLastDocument).then(updateLastDocumentTest).
// getA a 200
then(getFirstAttachment).then(getFirstAttachmentTest).
// getA b 200
//then(getSecondAttachment).then(getSecondAttachmentTest).
then(getSecondAttachment).then(getSecondAttachmentTest).
// get 200
//then(getLastDocument).then(getLastDocumentTest).
then(getLastDocument).then(getLastDocumentTest).
// removeA b 204
//then(removeSecondAttachment).then(removeSecondAttachmentTest).
then(removeSecondAttachment).then(removeSecondAttachmentTest).
// getA b 404
//then(getInexistentSecondAttachment).
//then(getInexistentSecondAttachmentTest).
then(getInexistentSecondAttachment).
then(getInexistentSecondAttachmentTest).
// get 200
//then(getOneAttachmentDocument).then(getOneAttachmentDocumentTest).
then(getOneAttachmentDocument).then(getOneAttachmentDocumentTest).
// removeA b 404
//then(removeSecondAttachmentAgain).then(removeSecondAttachmentAgainTest).
then(removeSecondAttachmentAgain).then(removeSecondAttachmentAgainTest).
// remove 204
//then(removeDocument).then(removeDocumentTest).
then(removeDocument).then(removeDocumentTest).
// getA a 404
//then(getInexistentFirstAttachment).then(getInexistentFirstAttachmentTest).
then(getInexistentFirstAttachment).then(getInexistentFirstAttachmentTest).
// get 404
//then(getInexistentDocument).then(getInexistentDocumentTest).
then(getInexistentDocument).then(getInexistentDocumentTest).
// remove 404
//then(removeInexistentDocument).then(removeInexistentDocumentTest).
then(removeInexistentDocument).then(removeInexistentDocumentTest).
// check 204
//then(checkDocument).done(checkDocumentTest).
//then(checkStorage).done(checkStorageTest).
......
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