Commit 8f5eb06b authored by lucas.parsy's avatar lucas.parsy

davstorage: return 404 status when putAttachment into an inexistent repository

parent d85fc772
...@@ -196,13 +196,24 @@ ...@@ -196,13 +196,24 @@
DavStorage.prototype.putAttachment = function (id, name, blob) { DavStorage.prototype.putAttachment = function (id, name, blob) {
var that = this;
id = restrictDocumentId(id); id = restrictDocumentId(id);
restrictAttachmentId(name); restrictAttachmentId(name);
return ajax(this, {
return new RSVP.Queue()
.push(function () {
return ajax(that, {
type: "PUT", type: "PUT",
url: this._url + id + name, url: that._url + id + name,
data: blob data: blob
}); });
})
.push(undefined, function (error) {
if (error.target.status === 403) {
throw new jIO.util.jIOError("Cannot access subdocument", 404);
}
throw error;
});
}; };
DavStorage.prototype.getAttachment = function (id, name) { DavStorage.prototype.getAttachment = function (id, name) {
......
...@@ -765,6 +765,29 @@ ...@@ -765,6 +765,29 @@
}); });
}); });
test("putAttachment to inexisting directory: expecting a 404", function () {
var blob = new Blob(["foo"]),
url = domain + "/inexistent_dir/attachment1";
this.server.respondWith("PUT", url, [403, {"": ""}, ""]);
stop();
expect(3);
this.jio.putAttachment(
"/inexistent_dir/",
"attachment1",
blob
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot access subdocument");
equal(error.status_code, 404);
})
.always(function () {
start();
});
});
test("putAttachment document", function () { test("putAttachment document", function () {
var blob = new Blob(["foo"]), var blob = new Blob(["foo"]),
url = domain + "/putAttachment1/attachment1", url = domain + "/putAttachment1/attachment1",
......
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