Commit 6f1464b1 authored by Bryan Kaperick's avatar Bryan Kaperick

Added a check to put() to make sure id is not in same format as a timestamp.

parent 79d7f77b
......@@ -13,7 +13,14 @@
//timestamp = Date.now().toString();
timestamp = time.toString();
return timestamp + "-" + uuid;
};
},
looks_like_timestamp = function (id) {
//1529928772623-02e6
//A timestamp is of the form
//"[13 digit number]-[4 numbers/lowercase letters]"
var re = /^[0-9]{13}-[a-z0-9]{4}$/;
return re.test(id);
};
/**
......@@ -90,8 +97,7 @@
if (error.status_code === 400 &&
error instanceof jIO.util.jIOError) {
throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id_in +
"'",
"HistoryStorage: cannot find object '" + id_in + "'",
404
);
}
......@@ -112,6 +118,12 @@
422
);
}
if (looks_like_timestamp(id)) {
throw new jIO.util.jIOError(
"Document cannot have id of the same form as a timestamp",
422
);
}
var timestamp = unique_timestamp(Date.now()),
metadata = {
// XXX: remove this attribute once query can sort_on id
......
......@@ -60,6 +60,7 @@
});
}
});
test("Testing proper adding/removing attachments",
function () {
stop();
......@@ -172,7 +173,6 @@
.always(function () {start(); });
});
test("Correctness of allAttachments method",
function () {
stop();
......@@ -304,59 +304,6 @@
.always(function () {start(); });
});
test("Correctness of allAttachments method",
function () {
stop();
expect(4);
var jio = this.jio,
timestamps = jio.__storage._timestamps,
blob1 = this.blob1,
blob2 = this.blob2,
other_blob1 = this.other_blob,
other_blob2 = new Blob(['asdf']);
putFullDoc(jio, "doc", {}, "data", blob1)
.push(function () {
return jio.putAttachment("doc", "data", blob2);
})
.push(function () {
return jio.putAttachment("doc", "other_data", other_blob1);
})
.push(function () {
return jio.putAttachment("doc", "other_data", other_blob2);
})
.push(function () {
return jio.getAttachment(timestamps.doc.data[0], "data");
})
.push(function (result) {
deepEqual(result, blob1, "Get old version of first attachment");
return jio.getAttachment(timestamps.doc.data[1], "data");
})
.push(function (result) {
deepEqual(result, blob2, "Get current version of first attachment");
return jio.getAttachment(timestamps.doc.other_data[0], "other_data");
})
.push(function (result) {
deepEqual(
result,
other_blob1,
"Get old version of second attachment"
);
return jio.getAttachment(timestamps.doc.other_data[1], "other_data");
})
.push(function (result) {
deepEqual(
result,
other_blob2,
"Get current version of second attachment"
);
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
/////////////////////////////////////////////////////////////////
// Querying older revisions
......@@ -395,7 +342,7 @@
test("Handling bad input",
function () {
stop();
expect(4);
expect(6);
var jio = this.jio,
BADINPUT_ERRCODE = 422;
......@@ -427,6 +374,18 @@
"Can't save a document with a reserved keyword"
);
})
.push(function () {
return jio.put("1234567891123-ab7d", {});
})
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
BADINPUT_ERRCODE,
"Can't save a document with a timestamp-formatted id"
);
})
.fail(function (error) {
//console.log(error);
ok(false, error);
......
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