Skip to content

Commit

Permalink
Merge pull request #8664 from achouhan09/status-fix
Browse files Browse the repository at this point in the history
Added a fix for handling invalid_schema_error returning with invalid status value for bucket lifecycle configuration rule
  • Loading branch information
achouhan09 authored Jan 16, 2025
2 parents f72907e + 7802f6f commit dacfe8e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ async function put_bucket_lifecycle(req) {
}
id_set.add(current_rule.id);

if (rule.Status?.length !== 1) {
dbg.error('Rule should have status', rule);
throw new S3Error(S3Error.InvalidArgument);
if (!rule.Status || rule.Status.length !== 1 ||
(rule.Status[0] !== s3_const.LIFECYCLE_STATUS.STAT_ENABLED && rule.Status[0] !== s3_const.LIFECYCLE_STATUS.STAT_DISABLED)) {
dbg.error(`Rule should have a status value of "${s3_const.LIFECYCLE_STATUS.STAT_ENABLED}" or "${s3_const.LIFECYCLE_STATUS.STAT_DISABLED}".`, rule);
throw new S3Error(S3Error.MalformedXML);
}
current_rule.status = rule.Status[0];

Expand Down
4 changes: 4 additions & 0 deletions src/endpoint/s3/s3_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ const s3_const = exports;
///////////////

s3_const.MAX_RULE_ID_LENGTH = 255;
s3_const.LIFECYCLE_STATUS = Object.freeze({
STAT_ENABLED: 'Enabled',
STAT_DISABLED: 'Disabled'
});
3 changes: 2 additions & 1 deletion src/endpoint/s3/s3_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ S3Error.MalformedPOSTRequest = Object.freeze({
});
S3Error.MalformedXML = Object.freeze({
code: 'MalformedXML',
message: 'This happens when the user sends malformed xml (xml that doesn\'t conform to the published xsd) for the configuration. The error message is, "The XML you provided was not well-formed or did not validate against our published schema."',
// This happens when the user sends malformed xml (xml that doesn't conform to the published xsd) for the configuration.
message: 'The XML you provided was not well-formed or did not validate against our published schema.',
http_code: 400,
});
S3Error.InvalidTag = Object.freeze({
Expand Down
14 changes: 14 additions & 0 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,17 @@ exports.test_rule_duplicate_id = async function(Bucket, Key, s3) {
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: duplicate ID found in the rules');
}
};

exports.test_rule_status_value = async function(Bucket, Key, s3) {
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);

// set the status value to an invalid value - other than 'Enabled' and 'Disabled'
putLifecycleParams.LifecycleConfiguration.Rules[0].Status = 'enabled';

try {
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
assert.fail('Expected MalformedXML error due to wrong status value, but received a different response');
} catch (error) {
assert(error.code === 'MalformedXML', `Expected MalformedXML error: due to invalid status value`);
}
};
1 change: 1 addition & 0 deletions src/test/system_tests/test_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function main() {
await commonTests.test_and_prefix_size(Bucket, Key, s3);
await commonTests.test_rule_id_length(Bucket, Key, s3);
await commonTests.test_rule_duplicate_id(Bucket, Key, s3);
await commonTests.test_rule_status_value(Bucket, Key, s3);

const getObjectParams = {
Bucket,
Expand Down

0 comments on commit dacfe8e

Please sign in to comment.