Compare commits

...

2 Commits

Author SHA1 Message Date
Ilke 3306624f0a [squash] refactor tests 2020-06-09 14:14:43 -07:00
Ilke 96eeadbd1f ft: S3C-2946 get and head object support object lock 2020-06-09 13:17:11 -07:00
3 changed files with 194 additions and 0 deletions

View File

@ -75,6 +75,17 @@ function collectResponseHeaders(objectMD, corsHeaders, versioningCfg,
responseMetaHeaders['x-amz-tagging-count'] =
Object.keys(objectMD.tags).length;
}
if (objectMD.retentionInfo && (objectMD.retentionInfo.retainUntilDate
&& objectMD.retentionInfo.mode)) {
responseMetaHeaders['x-amz-object-lock-retain-until-date']
= objectMD.retentionInfo.retainUntilDate;
responseMetaHeaders['x-amz-object-lock-mode']
= objectMD.retentionInfo.mode;
}
if (objectMD.legalHold !== undefined) {
responseMetaHeaders['x-amz-object-lock-legal-hold']
= objectMD.legalHold ? 'ON' : 'OFF';
}
if (objectMD.replicationInfo && objectMD.replicationInfo.status) {
responseMetaHeaders['x-amz-replication-status'] =
objectMD.replicationInfo.status;

View File

@ -75,6 +75,137 @@ describe('objectGet API', () => {
});
});
const testPutBucketRequestObjectLock = {
bucketName,
namespace,
headers: {
host: `${bucketName}.s3.amazonaws.com`,
'x-amz-object-lock-enabled': true,
},
url: `/${bucketName}`,
};
const testPutObjectReqRetention = (date, mode) => new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
'x-amz-object-lock-retain-until-date': date,
'x-amz-object-lock-mode': mode,
'content-length': '12',
},
parsedContentLength: 12,
url: `/${bucketName}/${objectName}`,
}, postBody);
const testDate = new Date(2022, 6, 3);
it('should get the object metadata with valid retention info', done => {
bucketPut(authInfo, testPutBucketRequestObjectLock, log, () => {
const request = testPutObjectReqRetention(testDate, 'GOVERNANCE');
objectPut(authInfo, request, undefined,
log, (err, headers) => {
assert.ifError(err);
assert.strictEqual(headers.ETag, `"${correctMD5}"`);
objectGet(authInfo, testGetRequest, false, log,
(err, res, headers) => {
assert.ifError(err);
assert.strictEqual(
headers['x-amz-object-lock-retain-until-date'],
testDate);
assert.strictEqual(
headers['x-amz-object-lock-mode'],
'GOVERNANCE');
assert.strictEqual(headers.ETag,
`"${correctMD5}"`);
done();
});
});
});
});
const testPutObjectReqLegalHold = legalHold => new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
'x-amz-object-lock-legal-hold': legalHold,
'content-length': '12',
},
parsedContentLength: 12,
url: `/${bucketName}/${objectName}`,
}, postBody);
const testStatuses = ['ON', 'OFF'];
testStatuses.forEach(status => {
it(`should get object metadata with legal hold ${status}`, done => {
bucketPut(authInfo, testPutBucketRequestObjectLock, log, () => {
const request = testPutObjectReqLegalHold(status);
objectPut(authInfo, request, undefined, log,
(err, resHeaders) => {
assert.ifError(err);
assert.strictEqual(resHeaders.ETag, `"${correctMD5}"`);
objectGet(authInfo, testGetRequest, false, log,
(err, res, headers) => {
assert.ifError(err);
assert.strictEqual(
headers['x-amz-object-lock-legal-hold'],
status);
assert.strictEqual(headers.ETag,
`"${correctMD5}"`);
done();
});
});
});
});
})
const testPutObjectReqRetentionAndLegalHold = (date, mode, status) => {
return new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
'x-amz-object-lock-retain-until-date': date,
'x-amz-object-lock-mode': mode,
'x-amz-object-lock-legal-hold': status,
'content-length': '12',
},
parsedContentLength: 12,
url: `/${bucketName}/${objectName}`,
}, postBody);
}
it('should get the object metadata with both retention and legal hold',
done => {
bucketPut(authInfo, testPutBucketRequestObjectLock, log, () => {
const request = testPutObjectReqRetentionAndLegalHold(
testDate, 'COMPLIANCE', 'ON');
objectPut(authInfo, request, undefined, log,
(err, resHeaders) => {
assert.ifError(err);
assert.strictEqual(resHeaders.ETag, `"${correctMD5}"`);
objectGet(authInfo, testGetRequest, false, log,
(err, res, headers) => {
assert.ifError(err);
assert.strictEqual(
headers['x-amz-object-lock-legal-hold'],
'ON');
assert.strictEqual(
/* eslint-disable next line */
headers['x-amz-object-lock-retain-until-date'],
testDate);
assert.strictEqual(
headers['x-amz-object-lock-mode'],
'COMPLIANCE');
assert.strictEqual(headers.ETag,
`"${correctMD5}"`);
done();
});
});
});
});
it('should get the object data retrieval info', done => {
bucketPut(authInfo, testPutBucketRequest, log, () => {
objectPut(authInfo, testPutObjectRequest, undefined, log,

View File

@ -256,4 +256,56 @@ describe('objectHead API', () => {
});
});
});
it('should get the object metadata with object lock', done => {
const testPutBucketRequestLock = {
bucketName,
namespace,
headers: { 'x-amz-bucket-object-lock-enabled': true },
url: `/${bucketName}`,
};
const testPutObjectRequestLock = new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers: {
'x-amz-object-lock-retain-until-date': '2050-10-10',
'x-amz-object-lock-mode': 'GOVERNANCE',
'x-amz-object-lock-legal-hold': 'ON',
},
url: `/${bucketName}/${objectName}`,
calculatedHash: correctMD5,
}, postBody);
const testGetRequest = {
bucketName,
namespace,
objectKey: objectName,
headers: {},
url: `/${bucketName}/${objectName}`,
};
bucketPut(authInfo, testPutBucketRequestLock, log, () => {
objectPut(authInfo, testPutObjectRequestLock, undefined, log,
(err, resHeaders) => {
assert.ifError(err);
assert.strictEqual(resHeaders.ETag, `"${correctMD5}"`);
objectHead(authInfo, testGetRequest, log, (err, res) => {
assert.ifError(err);
const expectedDate = testPutObjectRequestLock
.headers['x-amz-object-lock-retain-until-date'];
const expectedMode = testPutObjectRequestLock
.headers['x-amz-object-lock-mode'];
assert.ifError(err);
assert.strictEqual(
res['x-amz-object-lock-retain-until-date'],
expectedDate);
assert.strictEqual(res['x-amz-object-lock-mode'],
expectedMode);
assert.strictEqual(res['x-amz-object-lock-legal-hold'],
'ON');
done();
});
});
});
});
});