Skip to content

Commit

Permalink
used config.js for declaration of max length and updated the error msg
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 8, 2025
1 parent 90cde4c commit eaf259a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ config.LIFECYCLE_INTERVAL = 8 * 60 * 60 * 1000; // 8h
config.LIFECYCLE_BATCH_SIZE = 1000;
config.LIFECYCLE_SCHEDULE_MIN = 5 * 1000 * 60; // run every 5 minutes
config.LIFECYCLE_ENABLED = true;
config.MAX_RULE_ID_LENGTH = 255;

//////////////////////////
// STATISTICS_COLLECTOR //
Expand Down
6 changes: 3 additions & 3 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
'use strict';

const _ = require('lodash');
const config = require('../../../../config');
const { v4: uuid } = require('uuid');
const dbg = require('../../../util/debug_module')(__filename);
const S3Error = require('../s3_errors').S3Error;

const true_regex = /true/i;
const max_length_rule_id = 255;

// parse lifecycle rule filter
function parse_filter(filter) {
Expand Down Expand Up @@ -89,8 +89,8 @@ async function put_bucket_lifecycle(req) {
};

if (rule.ID?.length === 1) {
if (rule.ID[0].length > max_length_rule_id) {
dbg.error('Rule should not have ID length exceeding', max_length_rule_id, 'characters', rule);
if (rule.ID[0].length > config.MAX_RULE_ID_LENGTH) {
dbg.error('Rule should not have ID length exceed allowed limit of ', config.MAX_RULE_ID_LENGTH, ' characters', rule);
throw new S3Error(S3Error.InvalidArgument);
} else {
current_rule.id = rule.ID[0];
Expand Down
8 changes: 4 additions & 4 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
'use strict';

const assert = require('assert');
const config = require('../../../config');

const max_length_rule_id = 255;
/*
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
*/
Expand Down Expand Up @@ -517,14 +517,14 @@ exports.test_and_prefix_size = async function(Bucket, Key, s3) {
exports.test_rule_id_length = async function(Bucket, Key, s3) {
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);

// set the ID to a value with more than 'max_length_rule_id' characters
const ID = 'A'.repeat(max_length_rule_id);
// set the ID to a value with more than 'MAX_RULE_ID_LENGTH' characters
const ID = 'A'.repeat(config.MAX_RULE_ID_LENGTH + 5);
putLifecycleParams.LifecycleConfiguration.Rules[0].ID = ID;

try {
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
} catch (error) {
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: id length exceeding 255 characters');
console.log('Expected error received, id length exceeding 255 characters');
console.log('Expected error received, id length exceeding', config.MAX_RULE_ID_LENGTH, 'characters');
}
};

0 comments on commit eaf259a

Please sign in to comment.