Skip to content

Commit

Permalink
Merge pull request #386 from jamhall/fix-372
Browse files Browse the repository at this point in the history
Require at least one Object in deleteObjects requests
  • Loading branch information
kherock authored Feb 7, 2019
2 parents 6fc676f + 36f8455 commit 53eb263
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ module.exports = function(rootDirectory, logger, indexDocument, errorDocument) {

function deleteObjects(req, res) {
xml2js.parseString(req.body, (err, parsedBody) => {
const keys = (parsedBody.Delete.Object || []).map(o => o.Key[0]);
if (!parsedBody.Delete || !parsedBody.Delete.Object) {
const template = templateBuilder.buildError(
"MalformedXML",
"The XML you provided was not well-formed or did not validate against our published schema"
);
return buildXmlResponse(res, 400, template);
}
const keys = parsedBody.Delete.Object.map(o => o.Key[0]);
async.each(
keys,
(key, cb) => {
Expand Down
17 changes: 12 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ describe("S3rver Tests", function() {
expect(res.headers).to.have.property("content-length", "100");
});

it("out of bounds range requests should return 416", function*() {
it("should return 416 error for out of bounds range requests", function*() {
const file = path.join(__dirname, "resources/image0.jpg");
const filesize = fs.statSync(file).size;
yield s3Client
Expand Down Expand Up @@ -1059,10 +1059,17 @@ describe("S3rver Tests", function() {
expect(find(data.Deleted, { Key: "key67" })).to.exist;
});

it("should not throw when using deleteObjects with zero objects", function*() {
yield s3Client
.deleteObjects({ Bucket: buckets[2], Delete: { Objects: [] } })
.promise();
it("should report invalid XML when using deleteObjects with zero objects", function*() {
let error;
try {
yield s3Client
.deleteObjects({ Bucket: buckets[2], Delete: { Objects: [] } })
.promise();
} catch (err) {
error = err;
}
expect(error).to.exist;
expect(error.code).to.equal("MalformedXML");
});

it("should return nonexistent objects as deleted with deleteObjects", function*() {
Expand Down

0 comments on commit 53eb263

Please sign in to comment.