Skip to content

Commit

Permalink
throwing error for undefined case and updated logic for undefined status
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 15, 2025
1 parent df5db46 commit f67070b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,12 @@ async function put_bucket_lifecycle(req) {
}
id_set.add(current_rule.id);

if (!rule.Status || rule.Status.length !== 1) {
dbg.error('Rule should have status', rule);
throw new S3Error(S3Error.InvalidArgument);
}
const status = rule.Status[0];
if (status !== s3_const.LIFECYCLE_STATUS.STAT_ENABLED && status !== s3_const.LIFECYCLE_STATUS.STAT_DISABLED) {
dbg.error(`Rule should not have status value other than "${s3_const.LIFECYCLE_STATUS.STAT_ENABLED}" and "${s3_const.LIFECYCLE_STATUS.STAT_DISABLED}" `, rule);
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 = status;
current_rule.status = rule.Status[0];

if (rule.Prefix) {
if (rule.Filter?.length === 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/endpoint/s3/s3_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ S3Error.MalformedPOSTRequest = Object.freeze({
});
S3Error.MalformedXML = Object.freeze({
code: 'MalformedXML',
// This happens when the user sends malformed xml (xml that doesn\'t conform to the published xsd) for the configuration.
// 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,
});
Expand Down
4 changes: 4 additions & 0 deletions src/endpoint/s3/s3_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,12 @@ function key_marker_to_cont_tok(key_marker, objects_arr, is_truncated) {
* the function throws a `MalformedPolicy` error. Otherwise, it throws the original error.
*
* @param {Object} error - The error object to handle
* @throws {Error|S3Error} - Throws an appropriate error based on the input
*/
function invalid_schema_to_aws_error(error) {
if (!error) {
throw new Error("Invalid error object: Error is undefined or null.");
}
if (["INVALID_SCHEMA", "INVALID_SCHEMA_PARAMS"].includes(error.rpc_code)) {
throw new S3Error(S3Error.MalformedPolicy);
}
Expand Down

0 comments on commit f67070b

Please sign in to comment.