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;
}
const isObjectAlreadyRestored = objMD.archive?.restoreCompletedAt
&& new Date(objMD.archive?.restoreWillExpireAt) >= new Date(Date.now());
// make sure object archive restoration is in progress
// NOTE: we do not use putObjectVersion to update the restoration period.
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',
{ method: 'validatePutVersionId', versionId });
return errors.InvalidObjectState;

View File

@ -71,7 +71,7 @@
},
"scripts": {
"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_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",

View File

@ -7,6 +7,7 @@ const metadata = require('../../../../../lib/metadata/wrapper');
const { DummyRequestLogger } = require('../../../../unit/helpers');
const checkError = require('../../lib/utility/checkError');
const { getMetadata, fakeMetadataRestore } = require('../utils/init');
const { addDays } = require('../../../../utilities/helpers');
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 => {
const params = { Bucket: bucketName, Key: objectName };
const now = Date.now();
const archiveCompleted = {
archiveInfo: {},
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(10),
restoreWillExpireAt: new Date(10 + (5 * 24 * 60 * 60 * 1000)),
restoreCompletedAt: now,
restoreWillExpireAt: addDays(now, 5),
};
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 => {
const params = { Bucket: bucketName, Key: objectName };
let objMDBefore;

View File

@ -7,6 +7,7 @@ const metadata = require('../../../../../lib/metadata/wrapper');
const { DummyRequestLogger } = require('../../../../unit/helpers');
const checkError = require('../../lib/utility/checkError');
const { getMetadata, fakeMetadataRestore } = require('../utils/init');
const { addDays } = require('../../../../utilities/helpers');
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 => {
const params = { Bucket: bucketName, Key: objectName };
const now = Date.now();
const archiveCompleted = {
archiveInfo: {},
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(10),
restoreWillExpireAt: new Date(10 + (5 * 24 * 60 * 60 * 1000)),
restoreCompletedAt: now,
restoreWillExpireAt: addDays(now, 5),
};
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 => {
const params = { Bucket: bucketName, Key: objectName };
let objMDBefore;

View File

@ -2,6 +2,7 @@ const assert = require('assert');
const { errors } = require('arsenal');
const { validatePutVersionId } = require('../../../../lib/api/apiUtils/object/coldStorage');
const { addDays } = require('../../../utilities/helpers');
const { DummyRequestLogger } = require('../../helpers');
const log = new DummyRequestLogger();
const oneDay = 24 * 60 * 60 * 1000;
@ -46,12 +47,25 @@ describe('cold storage', () => {
archive: {
restoreRequestedAt: new Date(0),
restoreRequestedDays: 5,
restoreCompletedAt: new Date(1000),
restoreWillExpireAt: new Date(1000 + 5 * oneDay),
restoreCompletedAt: Date.now(),
restoreWillExpireAt: addDays(Date.now(), 5),
},
},
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',
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,
};