Skip to content

Commit 6e05efb

Browse files
committed
Added new file s3_constants.js
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent ffa8634 commit 6e05efb

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/endpoint/s3/ops/s3_put_bucket_lifecycle.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const _ = require('lodash');
5-
const config = require('../../../../config');
5+
const s3_const = require('../s3_constants');
66
const { v4: uuid } = require('uuid');
77
const dbg = require('../../../util/debug_module')(__filename);
88
const S3Error = require('../s3_errors').S3Error;
@@ -89,9 +89,9 @@ async function put_bucket_lifecycle(req) {
8989
};
9090

9191
if (rule.ID?.length === 1) {
92-
if (rule.ID[0].length > config.MAX_RULE_ID_LENGTH) {
93-
dbg.error('Rule should not have ID length exceed allowed limit of ', config.MAX_RULE_ID_LENGTH, ' characters', rule);
94-
throw new S3Error({ ...S3Error.InvalidArgument, message: 'ID length should not exceed allowed limit of 255' });
92+
if (rule.ID[0].length > s3_const.MAX_RULE_ID_LENGTH) {
93+
dbg.error('Rule should not have ID length exceed allowed limit of ', s3_const.MAX_RULE_ID_LENGTH, ' characters', rule);
94+
throw new S3Error({ ...S3Error.InvalidArgument, message: `ID length should not exceed allowed limit of ${s3_const.MAX_RULE_ID_LENGTH}` });
9595
} else {
9696
current_rule.id = rule.ID[0];
9797
}

src/endpoint/s3/s3_constants.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* Copyright (C) 2016 NooBaa */
2+
'use strict';
3+
4+
// `s3_const` serves as an alias for `exports` which expose constants related to s3 operations
5+
// keeping name referencing consistent to s3_const.NAME for easier imports and searches
6+
const s3_const = exports;
7+
8+
///////////////
9+
// LIFECYCLE //
10+
///////////////
11+
12+
s3_const.MAX_RULE_ID_LENGTH = 255;

src/test/lifecycle/common.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const assert = require('assert');
5-
const config = require('../../../config');
5+
const s3_const = require('../../endpoint/s3/s3_constants');
66

77
/*
88
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
@@ -518,15 +518,14 @@ exports.test_rule_id_length = async function(Bucket, Key, s3) {
518518
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);
519519

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

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

0 commit comments

Comments
 (0)