From 1435d2725101124d9a4bd492d378a074ea6a1084 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Sat, 7 Oct 2023 10:46:37 +0800 Subject: [PATCH 01/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- lib/common/bucket/putBucketLifecycle.js | 4 ++-- test/node/bucket.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/common/bucket/putBucketLifecycle.js b/lib/common/bucket/putBucketLifecycle.js index 8cbe97a2b..8eece21e1 100644 --- a/lib/common/bucket/putBucketLifecycle.js +++ b/lib/common/bucket/putBucketLifecycle.js @@ -95,8 +95,8 @@ function checkRule(rule) { if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled'); if (rule.transition) { - if (!['IA', 'Archive'].includes(rule.transition.storageClass)) - throw new Error('StorageClass must be IA or Archive'); + if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.transition.storageClass)) + throw new Error('StorageClass must be IA、Archive、ColdArchive、DeepColdArchive'); checkDaysAndDate(rule.transition, 'Transition'); } diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 7bbbae3b8..e4a267bd3 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -857,6 +857,22 @@ describe('test/bucket.test.js', () => { } ]); assert.equal(putresult2.res.status, 200); + const putresult3 = await store.putBucketLifecycle(bucket, [ + { + id: 'transition', + prefix: 'logs/', + status: 'Enabled', + transition: { + days: 20, + storageClass: 'DeepColdArchive' + }, + tag: { + key: 'test', + value: '123' + } + } + ]); + assert.equal(putresult3.res.status, 200); }); it('should put the lifecycle with expiration and Tag', async () => { From 609d60fade6dc8bcff95bd6e899482e0bf03b57f Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Sat, 7 Oct 2023 13:59:32 +0800 Subject: [PATCH 02/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index e4a267bd3..76e4b3996 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -864,7 +864,7 @@ describe('test/bucket.test.js', () => { status: 'Enabled', transition: { days: 20, - storageClass: 'DeepColdArchive' + storageClass: 'ColdArchive' }, tag: { key: 'test', @@ -873,6 +873,22 @@ describe('test/bucket.test.js', () => { } ]); assert.equal(putresult3.res.status, 200); + const putresult4 = await store.putBucketLifecycle(bucket, [ + { + id: 'transition', + prefix: 'logs/', + status: 'Enabled', + transition: { + days: 20, + storageClass: 'DeepColdArchive' + }, + tag: { + key: 'test', + value: '123' + } + } + ]); + assert.equal(putresult4.res.status, 200); }); it('should put the lifecycle with expiration and Tag', async () => { @@ -1003,7 +1019,7 @@ describe('test/bucket.test.js', () => { ]); assert(false); } catch (error) { - assert(error.message.includes('IA or Archive')); + assert(error.message.includes('IA、Archive')); } }); From b94cebfd7641dc0e3d85aa820ba2de301d209f15 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Sat, 7 Oct 2023 15:07:35 +0800 Subject: [PATCH 03/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 76e4b3996..d4d57229e 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -859,7 +859,7 @@ describe('test/bucket.test.js', () => { assert.equal(putresult2.res.status, 200); const putresult3 = await store.putBucketLifecycle(bucket, [ { - id: 'transition', + id: 'transition3', prefix: 'logs/', status: 'Enabled', transition: { @@ -867,28 +867,28 @@ describe('test/bucket.test.js', () => { storageClass: 'ColdArchive' }, tag: { - key: 'test', + key: 'test3', value: '123' } } ]); assert.equal(putresult3.res.status, 200); - const putresult4 = await store.putBucketLifecycle(bucket, [ - { - id: 'transition', - prefix: 'logs/', - status: 'Enabled', - transition: { - days: 20, - storageClass: 'DeepColdArchive' - }, - tag: { - key: 'test', - value: '123' - } - } - ]); - assert.equal(putresult4.res.status, 200); + // const putresult4 = await store.putBucketLifecycle(bucket, [ + // { + // id: 'transition4', + // prefix: 'logs/', + // status: 'Enabled', + // transition: { + // days: 20, + // storageClass: 'DeepColdArchive' + // }, + // tag: { + // key: 'test4', + // value: '123' + // } + // } + // ]); + // assert.equal(putresult4.res.status, 200); }); it('should put the lifecycle with expiration and Tag', async () => { From 68566cf81e7963bd6cc648edd2ebade0fcab99bb Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Sat, 7 Oct 2023 15:22:39 +0800 Subject: [PATCH 04/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index d4d57229e..d039594e0 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -857,38 +857,38 @@ describe('test/bucket.test.js', () => { } ]); assert.equal(putresult2.res.status, 200); - const putresult3 = await store.putBucketLifecycle(bucket, [ - { - id: 'transition3', - prefix: 'logs/', - status: 'Enabled', - transition: { - days: 20, - storageClass: 'ColdArchive' - }, - tag: { - key: 'test3', - value: '123' - } - } - ]); - assert.equal(putresult3.res.status, 200); - // const putresult4 = await store.putBucketLifecycle(bucket, [ + // const putresult3 = await store.putBucketLifecycle(bucket, [ // { - // id: 'transition4', + // id: 'transition3', // prefix: 'logs/', // status: 'Enabled', // transition: { // days: 20, - // storageClass: 'DeepColdArchive' + // storageClass: 'ColdArchive' // }, // tag: { - // key: 'test4', + // key: 'test3', // value: '123' // } // } // ]); - // assert.equal(putresult4.res.status, 200); + // assert.equal(putresult3.res.status, 200); + const putresult4 = await store.putBucketLifecycle(bucket, [ + { + id: 'transition4', + prefix: 'logs/', + status: 'Enabled', + transition: { + days: 20, + storageClass: 'DeepColdArchive' + }, + tag: { + key: 'test4', + value: '123' + } + } + ]); + assert.equal(putresult4.res.status, 200); }); it('should put the lifecycle with expiration and Tag', async () => { From 5063347a7c2e31119ba46e8c0d03a2650f6d5427 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Sat, 7 Oct 2023 15:43:17 +0800 Subject: [PATCH 05/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 45 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index d039594e0..ab0d89222 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -857,38 +857,41 @@ describe('test/bucket.test.js', () => { } ]); assert.equal(putresult2.res.status, 200); - // const putresult3 = await store.putBucketLifecycle(bucket, [ - // { - // id: 'transition3', - // prefix: 'logs/', - // status: 'Enabled', - // transition: { - // days: 20, - // storageClass: 'ColdArchive' - // }, - // tag: { - // key: 'test3', - // value: '123' - // } - // } - // ]); - // assert.equal(putresult3.res.status, 200); - const putresult4 = await store.putBucketLifecycle(bucket, [ + const putresult3 = await store.putBucketLifecycle(bucket, [ { - id: 'transition4', + id: 'transition3', prefix: 'logs/', status: 'Enabled', transition: { days: 20, - storageClass: 'DeepColdArchive' + storageClass: 'ColdArchive' }, tag: { - key: 'test4', + key: 'test3', value: '123' } } ]); - assert.equal(putresult4.res.status, 200); + assert.equal(putresult3.res.status, 200); + // oss-us-west-1 not support DeepColdArchive + if (!config.endpoint) { + const putresult4 = await store.putBucketLifecycle(bucket, [ + { + id: 'transition4', + prefix: 'logs/', + status: 'Enabled', + transition: { + days: 20, + storageClass: 'DeepColdArchive' + }, + tag: { + key: 'test4', + value: '123' + } + } + ]); + assert.equal(putresult4.res.status, 200); + } }); it('should put the lifecycle with expiration and Tag', async () => { From fbd69720c22e67217b7ce9fd4b40d4a94df62627 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Mon, 16 Oct 2023 10:21:37 +0800 Subject: [PATCH 06/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- README.md | 4 +-- lib/common/bucket/putBucketLifecycle.js | 15 ++++++++++ test/config.js | 2 +- test/node/bucket.test.js | 34 +++++++++++------------ test/node/multiversion.test.js | 37 +++++++++++++++++++++---- 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c6e09a521..10a2a6aad 100644 --- a/README.md +++ b/README.md @@ -957,12 +957,12 @@ parameters: - [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z` `createdBeforeDate` and `days` must have one. - [transition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle. - - storageClass {String} Specifies the storage class that objects that conform to the rule are converted into. allow values: `IA` or `Archive` + - storageClass {String} Specifies the storage class that objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive` - [days] {Number|String} expire after the `days` - [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z` `createdBeforeDate` and `days` must have one. - [noncurrentVersionTransition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle. - - storageClass {String} Specifies the storage class that history objects that conform to the rule are converted into. allow values: `IA` or `Archive` + - storageClass {String} Specifies the storage class that history objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive` - noncurrentDays {String} expire after the `noncurrentDays` `expiration`、 `abortMultipartUpload`、 `transition`、 `noncurrentVersionTransition` must have one. - [noncurrentVersionExpiration] {Object} specifies the expiration attribute of the lifecycle rules for the history object. diff --git a/lib/common/bucket/putBucketLifecycle.js b/lib/common/bucket/putBucketLifecycle.js index 8eece21e1..2235e432e 100644 --- a/lib/common/bucket/putBucketLifecycle.js +++ b/lib/common/bucket/putBucketLifecycle.js @@ -73,6 +73,15 @@ function checkDaysAndDate(obj, key) { } } +function checkNoncurrentDays(obj, key) { + const { noncurrentDays } = obj; + if (!noncurrentDays) { + throw new Error(`${key} must includes noncurrentDays`); + } else if (noncurrentDays && !/^[1-9][0-9]*$/.test(noncurrentDays)) { + throw new Error('noncurrentDays must be a positive integer'); + } +} + function handleCheckTag(tag) { if (!isArray(tag) && !isObject(tag)) { throw new Error('tag must be Object or Array'); @@ -118,6 +127,12 @@ function checkRule(rule) { ); } + if (rule.noncurrentVersionTransition) { + if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.noncurrentVersionTransition.storageClass)) + throw new Error('noncurrentVersionTransition StorageClass must be IA、Archive、ColdArchive、DeepColdArchive'); + checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition'); + } + if (rule.tag) { if (rule.abortMultipartUpload) { throw new Error('Tag cannot be used with abortMultipartUpload'); diff --git a/test/config.js b/test/config.js index a58ca7611..80101e450 100644 --- a/test/config.js +++ b/test/config.js @@ -1,7 +1,7 @@ const { env } = process; const config = module.exports; -const USWEST = 'oss-us-west-1'; // ONCI=true Using the region of Silicon Valley in the United States would be faster +const USWEST = 'oss-ap-southeast-1'; // ONCI=true Faster using oss-ap-outsoutheast-1 config.oss = { accessKeyId: env.ALI_SDK_OSS_ID, diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index ab0d89222..539269d72 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -873,25 +873,23 @@ describe('test/bucket.test.js', () => { } ]); assert.equal(putresult3.res.status, 200); - // oss-us-west-1 not support DeepColdArchive - if (!config.endpoint) { - const putresult4 = await store.putBucketLifecycle(bucket, [ - { - id: 'transition4', - prefix: 'logs/', - status: 'Enabled', - transition: { - days: 20, - storageClass: 'DeepColdArchive' - }, - tag: { - key: 'test4', - value: '123' - } + // Regions that need to support DeepColdArchive + const putresult4 = await store.putBucketLifecycle(bucket, [ + { + id: 'transition4', + prefix: 'logs/', + status: 'Enabled', + transition: { + days: 20, + storageClass: 'DeepColdArchive' + }, + tag: { + key: 'test4', + value: '123' } - ]); - assert.equal(putresult4.res.status, 200); - } + } + ]); + assert.equal(putresult4.res.status, 200); }); it('should put the lifecycle with expiration and Tag', async () => { diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index c115e3354..008d38eda 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -145,7 +145,7 @@ describe('test/multiversion.test.js', () => { expiration: { expiredObjectDeleteMarker: 'true' }, - NoncurrentVersionExpiration: { + noncurrentVersionExpiration: { noncurrentDays: 1 } } @@ -155,25 +155,50 @@ describe('test/multiversion.test.js', () => { assert.strictEqual(rules[0].expiration.expiredObjectDeleteMarker, 'true'); }); - it('should putBucketLifecycle with noncurrentVersionTransition', async () => { - const putresult1 = await store.putBucketLifecycle(bucket, [ + it.only('should putBucketLifecycle with noncurrentVersionTransition', async () => { + const putresult = await store.putBucketLifecycle(bucket, [ { - id: 'expiration1', - prefix: 'logs/', + prefix: 'log/', status: 'Enabled', noncurrentVersionTransition: { noncurrentDays: '10', storageClass: 'IA' } + }, + { + prefix: 'logs/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'Archive' + } + }, + { + prefix: 'logss/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'ColdArchive' + } + }, + { + prefix: 'logsss/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'DeepColdArchive' + } } ]); - assert.equal(putresult1.res.status, 200); + assert.equal(putresult.res.status, 200); + const { rules } = await store.getBucketLifecycle(bucket); const [ { noncurrentVersionTransition: { noncurrentDays, storageClass } } ] = rules; + assert(noncurrentDays === '10' && storageClass === 'IA'); }); }); From f4a170b0db67e8e1c59789a41a3b20af18cebbdd Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Mon, 16 Oct 2023 10:22:55 +0800 Subject: [PATCH 07/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/multiversion.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index 008d38eda..9f1bc1709 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -155,7 +155,7 @@ describe('test/multiversion.test.js', () => { assert.strictEqual(rules[0].expiration.expiredObjectDeleteMarker, 'true'); }); - it.only('should putBucketLifecycle with noncurrentVersionTransition', async () => { + it('should putBucketLifecycle with noncurrentVersionTransition', async () => { const putresult = await store.putBucketLifecycle(bucket, [ { prefix: 'log/', From 65bd92a622c08baf00f1502836ea8ba6e86d5c76 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Wed, 18 Oct 2023 11:04:32 +0800 Subject: [PATCH 08/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- lib/common/bucket/putBucketLifecycle.js | 25 +++++++++++++++++++------ test/config.js | 3 +-- test/node/bucket.test.js | 4 ++-- test/node/multiversion.test.js | 13 ++++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/common/bucket/putBucketLifecycle.js b/lib/common/bucket/putBucketLifecycle.js index 2235e432e..60c16a17d 100644 --- a/lib/common/bucket/putBucketLifecycle.js +++ b/lib/common/bucket/putBucketLifecycle.js @@ -96,6 +96,11 @@ function handleCheckTag(tag) { checkObjectTag(tagObj); } +function checkStorageClass(name, storageClass) { + if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(storageClass)) + throw new Error(`${name} must be IA or Archive or ColdArchive or DeepColdArchive`); +} + function checkRule(rule) { if (rule.id && getStrBytesCount(rule.id) > 255) throw new Error('ID is composed of 255 bytes at most'); @@ -104,8 +109,7 @@ function checkRule(rule) { if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled'); if (rule.transition) { - if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.transition.storageClass)) - throw new Error('StorageClass must be IA、Archive、ColdArchive、DeepColdArchive'); + checkStorageClass('StorageClass', rule.transition.storageClass); checkDaysAndDate(rule.transition, 'Transition'); } @@ -121,18 +125,27 @@ function checkRule(rule) { checkDaysAndDate(rule.abortMultipartUpload, 'AbortMultipartUpload'); } - if (!rule.expiration && !rule.abortMultipartUpload && !rule.transition && !rule.noncurrentVersionTransition) { + if ( + !rule.expiration && + !rule.noncurrentVersionExpiration && + !rule.abortMultipartUpload && + !rule.transition && + !rule.noncurrentVersionTransition + ) { throw new Error( - 'Rule must includes expiration or abortMultipartUpload or transition or noncurrentVersionTransition' + 'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition' ); } if (rule.noncurrentVersionTransition) { - if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.noncurrentVersionTransition.storageClass)) - throw new Error('noncurrentVersionTransition StorageClass must be IA、Archive、ColdArchive、DeepColdArchive'); + checkStorageClass('noncurrentVersionTransition', rule.noncurrentVersionTransition.storageClass); checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition'); } + if (rule.noncurrentVersionExpiration) { + checkNoncurrentDays(rule.noncurrentVersionExpiration, 'NoncurrentVersionExpiration'); + } + if (rule.tag) { if (rule.abortMultipartUpload) { throw new Error('Tag cannot be used with abortMultipartUpload'); diff --git a/test/config.js b/test/config.js index 80101e450..a018796fc 100644 --- a/test/config.js +++ b/test/config.js @@ -1,14 +1,13 @@ const { env } = process; const config = module.exports; -const USWEST = 'oss-ap-southeast-1'; // ONCI=true Faster using oss-ap-outsoutheast-1 config.oss = { accessKeyId: env.ALI_SDK_OSS_ID, accessKeySecret: env.ALI_SDK_OSS_SECRET, accountId: env.ALI_SDK_STS_ROLE.match(/^acs:ram::(\d+):role/i)[1], // Obtain the main account ID through roleRan region: env.ALI_SDK_OSS_REGION, - endpoint: env.ONCI ? `https://${USWEST}.aliyuncs.com` : undefined, + endpoint: env.ONCI ? `https://${env.ALI_SDK_OSS_REGION}.aliyuncs.com` : undefined, maxSocket: 50 }; diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 539269d72..367cd3b2a 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -828,7 +828,7 @@ describe('test/bucket.test.js', () => { status: 'Enabled', transition: { createdBeforeDate: '2020-02-18T00:00:00.000Z', - storageClass: 'Archive' + storageClass: 'IA' }, expiration: { createdBeforeDate: '2020-02-17T00:00:00.000Z' @@ -1020,7 +1020,7 @@ describe('test/bucket.test.js', () => { ]); assert(false); } catch (error) { - assert(error.message.includes('IA、Archive')); + assert(error.message.includes('IA or Archive or ColdArchive or DeepColdArchive')); } }); diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index 9f1bc1709..61f4d1234 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -111,12 +111,11 @@ describe('test/multiversion.test.js', () => { }); describe('putBucketLifecycle() getBucketLifecycle()', async () => { - it('should putBucketLifecycle with NoncurrentVersionExpiration', async () => { + it('should putBucketLifecycle with noncurrentVersionExpiration', async () => { const putresult1 = await store.putBucketLifecycle( bucket, [ { - id: 'expiration1', prefix: 'logs/', status: 'Enabled', expiration: { @@ -125,6 +124,13 @@ describe('test/multiversion.test.js', () => { noncurrentVersionExpiration: { noncurrentDays: 1 } + }, + { + prefix: 'logss/', + status: 'Enabled', + noncurrentVersionExpiration: { + noncurrentDays: 1 + } } ], { @@ -136,6 +142,7 @@ describe('test/multiversion.test.js', () => { const { rules } = await store.getBucketLifecycle(bucket); assert.strictEqual(rules[0].noncurrentVersionExpiration.noncurrentDays, '1'); }); + it('should putBucketLifecycle with expiredObjectDeleteMarker', async () => { const putresult1 = await store.putBucketLifecycle(bucket, [ { @@ -199,7 +206,7 @@ describe('test/multiversion.test.js', () => { } ] = rules; - assert(noncurrentDays === '10' && storageClass === 'IA'); + assert(noncurrentDays === '10' && storageClass === 'IA' && rules.length === 4); }); }); From de7aefeadc27c4015194721555e668c1a313810c Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Wed, 7 Aug 2024 15:33:18 +0800 Subject: [PATCH 09/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- lib/common/bucket/putBucketLifecycle.js | 8 +-- test/node/bucket.test.js | 21 ++++++- test/node/multiversion.test.js | 73 +++++++++++++------------ 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/lib/common/bucket/putBucketLifecycle.js b/lib/common/bucket/putBucketLifecycle.js index 60c16a17d..838d80b9e 100644 --- a/lib/common/bucket/putBucketLifecycle.js +++ b/lib/common/bucket/putBucketLifecycle.js @@ -96,9 +96,9 @@ function handleCheckTag(tag) { checkObjectTag(tagObj); } -function checkStorageClass(name, storageClass) { +function checkStorageClass(storageClass) { if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(storageClass)) - throw new Error(`${name} must be IA or Archive or ColdArchive or DeepColdArchive`); + throw new Error(`StorageClass must be IA or Archive or ColdArchive or DeepColdArchive`); } function checkRule(rule) { @@ -109,7 +109,7 @@ function checkRule(rule) { if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled'); if (rule.transition) { - checkStorageClass('StorageClass', rule.transition.storageClass); + checkStorageClass(rule.transition.storageClass); checkDaysAndDate(rule.transition, 'Transition'); } @@ -138,7 +138,7 @@ function checkRule(rule) { } if (rule.noncurrentVersionTransition) { - checkStorageClass('noncurrentVersionTransition', rule.noncurrentVersionTransition.storageClass); + checkStorageClass(rule.noncurrentVersionTransition.storageClass); checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition'); } diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index d29602013..f579711dc 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -764,7 +764,25 @@ describe('test/bucket.test.js', () => { }); describe('putBucketLifecycle()', () => { - // todo delete + it('should put the lifecycle throw error', async () => { + try { + await store.putBucketLifecycle(bucket, [ + { + id: 'expiration1', + prefix: 'logs/', + status: 'Enabled', + day: 1 + } + ]); + assert.fail('expected an error to be thrown'); + } catch (e) { + assert.equal( + e.message, + 'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition' + ); + } + }); + it('should put the lifecycle with old api', async () => { const putresult1 = await store.putBucketLifecycle(bucket, [ { @@ -774,6 +792,7 @@ describe('test/bucket.test.js', () => { days: 1 } ]); + assert.equal(putresult1.res.status, 200); const putresult2 = await store.putBucketLifecycle(bucket, [ diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index 830f7ffd8..8af82d618 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -22,7 +22,8 @@ describe('test/multiversion.test.js', () => { ].forEach((moreConfigs, idx) => { describe(`test multiversion in iterate ${idx}`, () => { before(async () => { - store = oss({ ...config, ...moreConfigs }); + // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive + store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' }); bucket = `ali-oss-test-bucket-version-${prefix.replace(/[/.]/g, '-')}${idx}`; const result = await store.putBucket(bucket); @@ -170,40 +171,44 @@ describe('test/multiversion.test.js', () => { }); it('should putBucketLifecycle with noncurrentVersionTransition', async () => { - const putresult = await store.putBucketLifecycle(bucket, [ - { - prefix: 'log/', - status: 'Enabled', - noncurrentVersionTransition: { - noncurrentDays: '10', - storageClass: 'IA' - } - }, - { - prefix: 'logs/', - status: 'Enabled', - noncurrentVersionTransition: { - noncurrentDays: '10', - storageClass: 'Archive' - } - }, - { - prefix: 'logss/', - status: 'Enabled', - noncurrentVersionTransition: { - noncurrentDays: '10', - storageClass: 'ColdArchive' - } - }, - { - prefix: 'logsss/', - status: 'Enabled', - noncurrentVersionTransition: { - noncurrentDays: '10', - storageClass: 'DeepColdArchive' + const putresult = await store.putBucketLifecycle( + bucket, + [ + { + prefix: 'log/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'IA' + } + }, + { + prefix: 'log/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'Archive' + } + }, + { + prefix: 'log/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'ColdArchive' + } + }, + { + prefix: 'log/', + status: 'Enabled', + noncurrentVersionTransition: { + noncurrentDays: '10', + storageClass: 'DeepColdArchive' + } } - } - ]); + ], + { headers: { 'x-oss-allow-same-action-overlap': 'true' } } + ); assert.equal(putresult.res.status, 200); await utils.sleep(1000); From ec4eaeed87e30101e480d7409f74a015eba57557 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Wed, 7 Aug 2024 16:24:20 +0800 Subject: [PATCH 10/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index f579711dc..62d432a36 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -25,7 +25,8 @@ describe('test/bucket.test.js', () => { ].forEach((moreConfigs, idx) => { describe(`test bucket in iterate ${idx}`, () => { before(async () => { - store = oss({ ...config, ...moreConfigs }); + // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive + store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' }); bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}${idx}`; const result = await store.putBucket(bucket, { timeout }); From f5dd20a67d2eb51be8005e0b5d1a6de22fd85d09 Mon Sep 17 00:00:00 2001 From: csg01123119 Date: Wed, 7 Aug 2024 17:17:34 +0800 Subject: [PATCH 11/11] fix: putBucketLifecycle add ColdArchive and DeepColdArchive --- test/node/bucket.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 62d432a36..83d1c428f 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -13,7 +13,7 @@ describe('test/bucket.test.js', () => { const { prefix, includesConf } = utils; let store; let bucket; - const bucketRegion = config.region; + const bucketRegion = 'oss-ap-southeast-1'; // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive const { accountId } = config; [ { @@ -25,8 +25,7 @@ describe('test/bucket.test.js', () => { ].forEach((moreConfigs, idx) => { describe(`test bucket in iterate ${idx}`, () => { before(async () => { - // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive - store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' }); + store = oss({ ...config, ...moreConfigs, region: bucketRegion }); bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}${idx}`; const result = await store.putBucket(bucket, { timeout }); @@ -1259,7 +1258,7 @@ describe('test/bucket.test.js', () => { }); it('should throw error when rule have no expiration or abortMultipartUpload', async () => { - const errorMessage = 'expiration or abortMultipartUpload'; + const errorMessage = 'expiration or noncurrentVersionExpiration or abortMultipartUpload'; try { await store.putBucketLifecycle(bucket, [ {