Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require at least one Object in deleteObjects requests #386

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kherock Do you think this could break users' code? I can imagine a naive deleteObject user might make empty requests sometimes. Should this be released in a patch, minor, or major release?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of a few patches ago, I'm pretty certain the server would just throw an unhandled error inside that callback function, so bringing this up to spec shouldn't be a big deal. I vote patch release.

});

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