Compare commits

...

1 Commits

Author SHA1 Message Date
Dimitrios Vasilas c701bd1abf CLDSRV-411: Add tests for imposing last-modified in testing mode 2023-07-20 09:32:35 +02:00
1 changed files with 75 additions and 0 deletions

View File

@ -17,6 +17,7 @@ const objectPut = require('../../../lib/api/objectPut');
const { objectLockTestUtils } = require('../helpers'); const { objectLockTestUtils } = require('../helpers');
const DummyRequest = require('../DummyRequest'); const DummyRequest = require('../DummyRequest');
const mpuUtils = require('../utils/mpuUtils'); const mpuUtils = require('../utils/mpuUtils');
const { lastModifiedHeader } = require('../../../constants');
const any = sinon.match.any; const any = sinon.match.any;
@ -375,6 +376,80 @@ describe('objectPut API', () => {
}); });
}); });
it('If testingMode=true and the last-modified header is given, should set last-modified accordingly', done => {
const imposedLastModified = '2024-07-19';
const testPutObjectRequest = new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
[lastModifiedHeader]: imposedLastModified,
},
url: `/${bucketName}/${objectName}`,
calculatedHash: 'vnR+tLdVF79rPPfF+7YvOg==',
}, postBody);
bucketPut(authInfo, testPutBucketRequest, log, () => {
const config = require('../../../lib/Config');
config.config.testingMode = true;
objectPut(authInfo, testPutObjectRequest, undefined, log,
(err, resHeaders) => {
assert.strictEqual(resHeaders.ETag, `"${correctMD5}"`);
metadata.getObjectMD(bucketName, objectName, {}, log,
(err, md) => {
assert(md);
const lastModified = md['last-modified'];
const lastModifiedDate = lastModified.split('T')[0];
// last-modified date should be the one set by the last-modified header
assert.strictEqual(lastModifiedDate, imposedLastModified);
// The header should be removed after being treated.
assert(md[lastModifiedHeader] === undefined);
config.config.testingMode = false;
done();
});
});
});
});
it('should not take into acccount the last-modified header when testingMode=false', done => {
const imposedLastModified = '2024-07-19';
const testPutObjectRequest = new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
'x-amz-meta-x-scal-last-modified': imposedLastModified,
},
url: `/${bucketName}/${objectName}`,
calculatedHash: 'vnR+tLdVF79rPPfF+7YvOg==',
}, postBody);
bucketPut(authInfo, testPutBucketRequest, log, () => {
const config = require('../../../lib/Config');
config.config.testingMode = false;
objectPut(authInfo, testPutObjectRequest, undefined, log,
(err, resHeaders) => {
assert.strictEqual(resHeaders.ETag, `"${correctMD5}"`);
metadata.getObjectMD(bucketName, objectName, {}, log,
(err, md) => {
assert(md);
assert.strictEqual(md['x-amz-meta-x-scal-last-modified'],
imposedLastModified);
const lastModified = md['last-modified'];
const lastModifiedDate = lastModified.split('T')[0];
const currentTs = new Date().toJSON();
const currentDate = currentTs.split('T')[0];
assert.strictEqual(lastModifiedDate, currentDate);
done();
});
});
});
});
it('should put an object with user metadata but no data', done => { it('should put an object with user metadata but no data', done => {
const postBody = ''; const postBody = '';
const correctMD5 = 'd41d8cd98f00b204e9800998ecf8427e'; const correctMD5 = 'd41d8cd98f00b204e9800998ecf8427e';