Skip to content

Commit

Permalink
Added new file s3_constants.js
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 ffa8634 commit 56e50e0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ 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
8 changes: 4 additions & 4 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const _ = require('lodash');
const config = require('../../../../config');
const s3_const = require('../s3_constants');
const { v4: uuid } = require('uuid');
const dbg = require('../../../util/debug_module')(__filename);
const S3Error = require('../s3_errors').S3Error;
Expand Down Expand Up @@ -89,9 +89,9 @@ async function put_bucket_lifecycle(req) {
};

if (rule.ID?.length === 1) {
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, message: 'ID length should not exceed allowed limit of 255' });
if (rule.ID[0].length > s3_const.MAX_RULE_ID_LENGTH) {
dbg.error('Rule should not have ID length exceed allowed limit of ', s3_const.MAX_RULE_ID_LENGTH, ' characters', rule);
throw new S3Error({ ...S3Error.InvalidArgument, message: `ID length should not exceed allowed limit of ${s3_const.MAX_RULE_ID_LENGTH}` });
} else {
current_rule.id = rule.ID[0];
}
Expand Down
12 changes: 12 additions & 0 deletions src/endpoint/s3/s3_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

// `s3_const` serves as an alias for `exports` which expose constants related to s3 operations
// keeping name referencing consistent to s3_const.NAME for easier imports and searches
const s3_const = exports;

///////////////
// LIFECYCLE //
///////////////

s3_const.MAX_RULE_ID_LENGTH = 255;
9 changes: 4 additions & 5 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const assert = require('assert');
const config = require('../../../config');
const s3_const = require('../../endpoint/s3/s3_constants');

/*
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
Expand Down Expand Up @@ -518,15 +518,14 @@ 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_RULE_ID_LENGTH' characters
const ID = 'A'.repeat(config.MAX_RULE_ID_LENGTH + 5);
const ID = 'A'.repeat(s3_const.MAX_RULE_ID_LENGTH + 5);
putLifecycleParams.LifecycleConfiguration.Rules[0].ID = ID;

try {
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
// if no error occurs, explicitly fail the test
assert.fail('Expected error for ID length exceeding maximum allowed characters, but request was successful');
assert.fail(`Expected error for ID length exceeding maximum allowed characters ${s3_const.MAX_RULE_ID_LENGTH}, but request was successful`);
} catch (error) {
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: id length exceeding 255 characters');
console.log('Expected error received, id length exceeding', config.MAX_RULE_ID_LENGTH, 'characters');
assert(error.code === 'InvalidArgument', `Expected InvalidArgument: id length exceeding ${s3_const.MAX_RULE_ID_LENGTH} characters`);
}
};

0 comments on commit 56e50e0

Please sign in to comment.