Skip to content

Commit dacfe8e

Browse files
authored
Merge pull request #8664 from achouhan09/status-fix
Added a fix for handling invalid_schema_error returning with invalid status value for bucket lifecycle configuration rule
2 parents f72907e + 7802f6f commit dacfe8e

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/endpoint/s3/ops/s3_put_bucket_lifecycle.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ async function put_bucket_lifecycle(req) {
108108
}
109109
id_set.add(current_rule.id);
110110

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

src/endpoint/s3/s3_constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ const s3_const = exports;
1010
///////////////
1111

1212
s3_const.MAX_RULE_ID_LENGTH = 255;
13+
s3_const.LIFECYCLE_STATUS = Object.freeze({
14+
STAT_ENABLED: 'Enabled',
15+
STAT_DISABLED: 'Disabled'
16+
});

src/endpoint/s3/s3_errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ S3Error.MalformedPOSTRequest = Object.freeze({
271271
});
272272
S3Error.MalformedXML = Object.freeze({
273273
code: 'MalformedXML',
274-
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."',
274+
// This happens when the user sends malformed xml (xml that doesn't conform to the published xsd) for the configuration.
275+
message: 'The XML you provided was not well-formed or did not validate against our published schema.',
275276
http_code: 400,
276277
});
277278
S3Error.InvalidTag = Object.freeze({

src/test/lifecycle/common.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,17 @@ exports.test_rule_duplicate_id = async function(Bucket, Key, s3) {
569569
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: duplicate ID found in the rules');
570570
}
571571
};
572+
573+
exports.test_rule_status_value = async function(Bucket, Key, s3) {
574+
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);
575+
576+
// set the status value to an invalid value - other than 'Enabled' and 'Disabled'
577+
putLifecycleParams.LifecycleConfiguration.Rules[0].Status = 'enabled';
578+
579+
try {
580+
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
581+
assert.fail('Expected MalformedXML error due to wrong status value, but received a different response');
582+
} catch (error) {
583+
assert(error.code === 'MalformedXML', `Expected MalformedXML error: due to invalid status value`);
584+
}
585+
};

src/test/system_tests/test_lifecycle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async function main() {
5656
await commonTests.test_and_prefix_size(Bucket, Key, s3);
5757
await commonTests.test_rule_id_length(Bucket, Key, s3);
5858
await commonTests.test_rule_duplicate_id(Bucket, Key, s3);
59+
await commonTests.test_rule_status_value(Bucket, Key, s3);
5960

6061
const getObjectParams = {
6162
Bucket,

0 commit comments

Comments
 (0)