Compare commits

...

1 Commits

Author SHA1 Message Date
Nicolas Humbert 9e31ae2b57 not needed 2022-06-03 15:02:15 -04:00
6 changed files with 78 additions and 8 deletions

View File

@ -107,10 +107,13 @@ function validatePutVersionId(objMD, versionId, log) {
return errors.InvalidObjectState; return errors.InvalidObjectState;
} }
const isObjectAlreadyRestored = objMD.archive?.restoreCompletedAt
&& new Date(objMD.archive?.restoreWillExpireAt) >= new Date(Date.now());
// make sure object archive restoration is in progress // make sure object archive restoration is in progress
// NOTE: we do not use putObjectVersion to update the restoration period. // NOTE: we do not use putObjectVersion to update the restoration period.
if (!objMD.archive || !objMD.archive.restoreRequestedAt || !objMD.archive.restoreRequestedDays if (!objMD.archive || !objMD.archive.restoreRequestedAt || !objMD.archive.restoreRequestedDays
|| objMD.archive.restoreCompletedAt || objMD.archive.restoreWillExpireAt) { || isObjectAlreadyRestored) {
log.error('object archive restoration is not in progress', log.error('object archive restoration is not in progress',
{ method: 'validatePutVersionId', versionId }); { method: 'validatePutVersionId', versionId });
return errors.InvalidObjectState; return errors.InvalidObjectState;

View File

@ -71,7 +71,7 @@
}, },
"scripts": { "scripts": {
"cloudserver": "S3METADATA=mongodb npm-run-all --parallel start_dataserver start_s3server", "cloudserver": "S3METADATA=mongodb npm-run-all --parallel start_dataserver start_s3server",
"ft_awssdk": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/", "ft_awssdk": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/object/mpuVersion.js",
"ft_awssdk_aws": "cd tests/functional/aws-node-sdk && AWS_ON_AIR=true mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/", "ft_awssdk_aws": "cd tests/functional/aws-node-sdk && AWS_ON_AIR=true mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/",
"ft_awssdk_buckets": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/bucket", "ft_awssdk_buckets": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/bucket",
"ft_awssdk_objects_misc": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/legacy test/object test/service test/support", "ft_awssdk_objects_misc": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/legacy test/object test/service test/support",

View File

@ -7,6 +7,7 @@ const metadata = require('../../../../../lib/metadata/wrapper');
const { DummyRequestLogger } = require('../../../../unit/helpers'); const { DummyRequestLogger } = require('../../../../unit/helpers');
const checkError = require('../../lib/utility/checkError'); const checkError = require('../../lib/utility/checkError');
const { getMetadata, fakeMetadataRestore } = require('../utils/init'); const { getMetadata, fakeMetadataRestore } = require('../utils/init');
const { addDays } = require('../../../../utilities/helpers');
const log = new DummyRequestLogger(); const log = new DummyRequestLogger();
@ -788,12 +789,13 @@ describe('MPU with x-scal-s3-version-id header', () => {
it('should fail if restore is already completed', done => { it('should fail if restore is already completed', done => {
const params = { Bucket: bucketName, Key: objectName }; const params = { Bucket: bucketName, Key: objectName };
const now = Date.now();
const archiveCompleted = { const archiveCompleted = {
archiveInfo: {}, archiveInfo: {},
restoreRequestedAt: new Date(0), restoreRequestedAt: new Date(0),
restoreRequestedDays: 5, restoreRequestedDays: 5,
restoreCompletedAt: new Date(10), restoreCompletedAt: now,
restoreWillExpireAt: new Date(10 + (5 * 24 * 60 * 60 * 1000)), restoreWillExpireAt: addDays(now, 5),
}; };
async.series([ async.series([
@ -809,6 +811,26 @@ describe('MPU with x-scal-s3-version-id header', () => {
}); });
}); });
it('should pass if restore expired but has not been cleaned up yet', done => {
const params = { Bucket: bucketName, Key: objectName };
const archiveCompleted = {
archiveInfo: {},
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(10),
restoreWillExpireAt: addDays(new Date(10), 5),
};
async.series([
next => s3.putObject(params, next),
next => fakeMetadataRestore(bucketName, objectName, undefined, archiveCompleted, next),
next => putMPUVersion(s3, bucketName, objectName, '', next),
], err => {
assert.strictEqual(err, null, `Expected success got error ${JSON.stringify(err)}`);
return done();
});
});
it('should update restore metadata', done => { it('should update restore metadata', done => {
const params = { Bucket: bucketName, Key: objectName }; const params = { Bucket: bucketName, Key: objectName };
let objMDBefore; let objMDBefore;

View File

@ -7,6 +7,7 @@ const metadata = require('../../../../../lib/metadata/wrapper');
const { DummyRequestLogger } = require('../../../../unit/helpers'); const { DummyRequestLogger } = require('../../../../unit/helpers');
const checkError = require('../../lib/utility/checkError'); const checkError = require('../../lib/utility/checkError');
const { getMetadata, fakeMetadataRestore } = require('../utils/init'); const { getMetadata, fakeMetadataRestore } = require('../utils/init');
const { addDays } = require('../../../../utilities/helpers');
const log = new DummyRequestLogger(); const log = new DummyRequestLogger();
@ -695,12 +696,13 @@ describe('PUT object with x-scal-s3-version-id header', () => {
it('should fail if restore is already completed', done => { it('should fail if restore is already completed', done => {
const params = { Bucket: bucketName, Key: objectName }; const params = { Bucket: bucketName, Key: objectName };
const now = Date.now();
const archiveCompleted = { const archiveCompleted = {
archiveInfo: {}, archiveInfo: {},
restoreRequestedAt: new Date(0), restoreRequestedAt: new Date(0),
restoreRequestedDays: 5, restoreRequestedDays: 5,
restoreCompletedAt: new Date(10), restoreCompletedAt: now,
restoreWillExpireAt: new Date(10 + (5 * 24 * 60 * 60 * 1000)), restoreWillExpireAt: addDays(now, 5),
}; };
async.series([ async.series([
@ -716,6 +718,26 @@ describe('PUT object with x-scal-s3-version-id header', () => {
}); });
}); });
it('should pass if restore expired but has not been cleaned up yet', done => {
const params = { Bucket: bucketName, Key: objectName };
const archiveCompleted = {
archiveInfo: {},
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(10),
restoreWillExpireAt: addDays(new Date(10), 5),
};
async.series([
next => s3.putObject(params, next),
next => fakeMetadataRestore(bucketName, objectName, undefined, archiveCompleted, next),
next => putObjectVersion(s3, params, '', next),
], err => {
assert.strictEqual(err, null, `Expected success got error ${JSON.stringify(err)}`);
return done();
});
});
it('should update restore metadata', done => { it('should update restore metadata', done => {
const params = { Bucket: bucketName, Key: objectName }; const params = { Bucket: bucketName, Key: objectName };
let objMDBefore; let objMDBefore;

View File

@ -2,6 +2,7 @@ const assert = require('assert');
const { errors } = require('arsenal'); const { errors } = require('arsenal');
const { validatePutVersionId } = require('../../../../lib/api/apiUtils/object/coldStorage'); const { validatePutVersionId } = require('../../../../lib/api/apiUtils/object/coldStorage');
const { addDays } = require('../../../utilities/helpers');
const { DummyRequestLogger } = require('../../helpers'); const { DummyRequestLogger } = require('../../helpers');
const log = new DummyRequestLogger(); const log = new DummyRequestLogger();
const oneDay = 24 * 60 * 60 * 1000; const oneDay = 24 * 60 * 60 * 1000;
@ -46,12 +47,25 @@ describe('cold storage', () => {
archive: { archive: {
restoreRequestedAt: new Date(0), restoreRequestedAt: new Date(0),
restoreRequestedDays: 5, restoreRequestedDays: 5,
restoreCompletedAt: new Date(1000), restoreCompletedAt: Date.now(),
restoreWillExpireAt: new Date(1000 + 5 * oneDay), restoreWillExpireAt: addDays(Date.now(), 5),
}, },
}, },
expectedRes: errors.InvalidObjectState, expectedRes: errors.InvalidObjectState,
}, },
{
description: 'should pass if restore expired but has not been cleaned up yet',
objMD: {
dataStoreName: 'location-dmf-v1',
archive: {
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(1000),
restoreWillExpireAt: addDays(new Date(1000), 5),
},
},
expectedRes: undefined,
},
{ {
description: 'should pass if object archived', description: 'should pass if object archived',
objMD: { objMD: {

View File

@ -0,0 +1,9 @@
function addDays(date, days) {
const result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
module.exports = {
addDays,
};