Skip to content

Commit

Permalink
Added test for expiration date in past
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 2, 2025
1 parent 5d8e415 commit 8fa3e27
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports.empty_filter_marker_lifecycle_configuration = empty_filter_marker_lifecy

function date_lifecycle_configuration(Bucket, Key) {
const now = new Date(Date.now());
now.setDate(now.getDate() + 1); // Increases date by 1 day; past/current dates can't be set
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));

return {
Expand All @@ -63,8 +64,31 @@ function date_lifecycle_configuration(Bucket, Key) {
}
exports.date_lifecycle_configuration = date_lifecycle_configuration;

function past_date_lifecycle_configuration(Bucket, Key) {
const now = new Date(Date.now());
now.setDate(now.getDate() - 1); // decreases date by 1 day
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));

return {
Bucket,
LifecycleConfiguration: {
Rules: [{
Expiration: {
Date: midnight,
},
Filter: {
Prefix: Key,
},
Status: 'Enabled',
}, ],
},
};
}
exports.past_date_lifecycle_configuration = past_date_lifecycle_configuration;

function date_lifecycle_configuration_and_tags(Bucket, Prefix, tagging) {
const now = new Date(Date.now());
now.setDate(now.getDate() + 1); // Increases date by 1 day; past/current dates can't be set
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));
const Tags = tagging.map((e, _) => ({Key: e.key, Value: e.value}));

Expand All @@ -90,6 +114,7 @@ exports.date_lifecycle_configuration_and_tags = date_lifecycle_configuration_and

function size_less_lifecycle_configuration(Bucket, ObjectSizeLessThan) {
const now = new Date(Date.now());
now.setDate(now.getDate() + 1); // Increases date by 1 day; past/current dates can't be set
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));

return {
Expand Down Expand Up @@ -150,6 +175,7 @@ exports.tag_days_lifecycle_configuration = tag_days_lifecycle_configuration;

function size_gt_lt_lifecycle_configuration(Bucket, gt, lt) {
const now = new Date(Date.now());
now.setDate(now.getDate() + 1); // Increases date by 1 day; past/current dates can't be set
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));

return {
Expand Down Expand Up @@ -307,6 +333,7 @@ function and_prefix_size_lifecycle_configuration(Bucket, Key) {

function rules_length_lifecycle_configuration(Bucket, Key) {
const now = new Date(Date.now());
now.setDate(now.getDate() + 1); // Increases date by 1 day; past/current dates can't be set
const midnight = new Date(now.setUTCHours(0, 0, 0, 0));

return {
Expand Down Expand Up @@ -512,3 +539,13 @@ exports.test_and_prefix_size = async function(Bucket, Key, s3) {
assert(actualFilter.ObjectSizeGreaterThan === expectedFilter.ObjectSizeGreaterThan, 'and prefix size filter - ObjectSizeGreaterThan');
assert(actualFilter.ObjectSizeLessThan === expectedFilter.ObjectSizeLessThan, 'and prefix size filter - ObjectSizeLessThan');
};

exports.test_expiration_date_in_past = async function(Bucket, Key, s3) {
const putLifecycleParams = past_date_lifecycle_configuration(Bucket, Key);

await s3.putBucketLifecycleConfiguration(putLifecycleParams)
.catch(error => {
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: expiration date in the past');
console.log('Expected error received, expiration date in the past');
});
};
1 change: 1 addition & 0 deletions src/test/system_tests/test_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
await commonTests.test_rule_id(Bucket, Key, s3);
await commonTests.test_filter_size(Bucket, s3);
await commonTests.test_and_prefix_size(Bucket, Key, s3);
await commonTests.test_expiration_date_in_past(Bucket, Key, s3);

const getObjectParams = {
Bucket,
Expand Down

0 comments on commit 8fa3e27

Please sign in to comment.